Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Breadcrumb script #1060

Merged
merged 20 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/breadcrumbs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Check Breadcrumbs

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
paths:
- 'pages/**/*.mdx'
- 'pages/**/*.md'

jobs:
check-breadcrumbs:
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20.x'

- name: Install pnpm
run: npm install -g pnpm

- name: Install dependencies
run: pnpm install

- name: Run breadcrumb check
run: pnpm check-breadcrumbs
krofax marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion notes/breadcrumbs.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pnpm create-breadcrumbs

2. **After Running**
* Review generated `.mdx` files in each folder
* Check updated descriptions
* Check updated descriptions, please update the description.
* Verify Card components and links

## Common Issues
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"description": "Optimism Docs",
"scripts": {
"lint": "eslint . --ext mdx --max-warnings 0 && pnpm spellcheck:lint",
"fix": "eslint . --ext mdx --fix && pnpm spellcheck:fix",
"fix": "eslint . --ext mdx --fix && pnpm spellcheck:fix && pnpm check-breadcrumbs",
"spellcheck:lint": "cspell lint \"**/*.mdx\"",
"spellcheck:fix": "cspell --words-only --unique \"**/*.mdx\" | sort --ignore-case | uniq > words.txt",
"linkcheck": "lychee --config ./lychee.toml --quiet \"./pages\"",
"create-breadcrumbs":"npx ts-node --skip-project utils/create-breadcrumbs.ts",
"breadcrumbs":"npx ts-node --skip-project utils/create-breadcrumbs.ts",
"check-breadcrumbs":"npx ts-node --skip-project utils/breadcrumbs.ts",
"index:docs": "npx ts-node --skip-project utils/algolia-indexer.ts",
"dev": "next dev",
"build": "next build",
Expand Down
16 changes: 16 additions & 0 deletions pages/stack/beta-features.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---

Check warning on line 1 in pages/stack/beta-features.mdx

View workflow job for this annotation

GitHub Actions / lint

Missing newline character at end of file
title: Beta Features
description: Documentation covering Alt Da Mode, Custom Gas Token in the Beta Features section of the OP Stack ecosystem.
lang: en-US
---

import { Card, Cards } from 'nextra/components'

# Beta Features

Documentation covering Alt Da Mode, Custom Gas Token in the Beta Features section of the OP Stack ecosystem.

<Cards>
<Card title="Alt-DA Mode explainer" href="/stack/beta-features/alt-da-mode" />
<Card title="Custom Gas token explainer" href="/stack/beta-features/custom-gas-token" />
</Cards>
20 changes: 20 additions & 0 deletions pages/stack/fault-proofs.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---

Check warning on line 1 in pages/stack/fault-proofs.mdx

View workflow job for this annotation

GitHub Actions / lint

Missing newline character at end of file
title: Fault Proofs
description: Documentation covering Cannon, Challenger, Explainer, Fp Components, Fp Security, Mips in the Fault Proofs section of the OP Stack ecosystem.
lang: en-US
---

import { Card, Cards } from 'nextra/components'

# Fault Proofs

Documentation covering Cannon, Challenger, Explainer, Fp Components, Fp Security, Mips in the Fault Proofs section of the OP Stack ecosystem.

<Cards>
<Card title="Fault proof VM - Cannon" href="/stack/fault-proofs/cannon" />
<Card title="OP-Challenger explainer" href="/stack/fault-proofs/challenger" />
<Card title="Fault proofs explainer" href="/stack/fault-proofs/explainer" />
<Card title="FP System components" href="/stack/fault-proofs/fp-components" />
<Card title="Fault proofs Mainnet security" href="/stack/fault-proofs/fp-security" />
<Card title="Fault proof VM - MIPS.sol" href="/stack/fault-proofs/mips" />
</Cards>
15 changes: 15 additions & 0 deletions pages/stack/features.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

Check warning on line 1 in pages/stack/features.mdx

View workflow job for this annotation

GitHub Actions / lint

Missing newline character at end of file
title: Features
description: Documentation covering Send Raw Transaction Conditional in the Features section of the OP Stack ecosystem.
lang: en-US
---

import { Card, Cards } from 'nextra/components'

# Features

Documentation covering Send Raw Transaction Conditional in the Features section of the OP Stack ecosystem.

<Cards>
<Card title="SendRawTransactionConditional explainer" href="/stack/features/send-raw-transaction-conditional" />
</Cards>
22 changes: 22 additions & 0 deletions pages/stack/interop.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---

Check warning on line 1 in pages/stack/interop.mdx

View workflow job for this annotation

GitHub Actions / lint

Missing newline character at end of file
title: Interop
description: Documentation covering Cross Chain Message, Explainer, Message Passing, Op Supervisor, Superchain Erc20, Superchain Weth, Supersim, Transfer Superchainerc20 in the Interop section of the OP Stack ecosystem.
lang: en-US
---

import { Card, Cards } from 'nextra/components'

# Interop

Documentation covering Cross Chain Message, Explainer, Message Passing, Op Supervisor, Superchain Erc20, Superchain Weth, Supersim, Transfer Superchainerc20 in the Interop section of the OP Stack ecosystem.

<Cards>
<Card title="Anatomy of a cross-chain message" href="/stack/interop/cross-chain-message" />
<Card title="Interoperability explainer" href="/stack/interop/explainer" />
<Card title="Interop message passing overview" href="/stack/interop/message-passing" />
<Card title="OP Supervisor" href="/stack/interop/op-supervisor" />
<Card title="SuperchainERC20" href="/stack/interop/superchain-erc20" />
<Card title="SuperchainWETH (Interoperable ETH)" href="/stack/interop/superchain-weth" />
<Card title="Supersim multichain development environment" href="/stack/interop/supersim" />
<Card title="How to transfer a SuperchainERC20" href="/stack/interop/transfer-superchainERC20" />
</Cards>
15 changes: 15 additions & 0 deletions pages/stack/research.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

Check warning on line 1 in pages/stack/research.mdx

View workflow job for this annotation

GitHub Actions / lint

Missing newline character at end of file
title: Research
description: Documentation covering Block Time Research in the Research section of the OP Stack ecosystem.
lang: en-US
---

import { Card, Cards } from 'nextra/components'

# Research

Documentation covering Block Time Research in the Research section of the OP Stack ecosystem.

<Cards>
<Card title="Block time research" href="/stack/research/block-time-research" />
</Cards>
17 changes: 17 additions & 0 deletions pages/stack/rollup.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---

Check warning on line 1 in pages/stack/rollup.mdx

View workflow job for this annotation

GitHub Actions / lint

Missing newline character at end of file
title: Rollup
description: The big idea that makes Optimism possible is the Optimistic Rollup. We'll go through a brief explainer of *how* Optimistic Rollups work at a high l...
krofax marked this conversation as resolved.
Show resolved Hide resolved
lang: en-US
---

import { Card, Cards } from 'nextra/components'

# Rollup

The big idea that makes Optimism possible is the Optimistic Rollup. We'll go through a brief explainer of *how* Optimistic Rollups work at a high l...
krofax marked this conversation as resolved.
Show resolved Hide resolved

<Cards>
<Card title="Derivation pipeline" href="/stack/rollup/derivation-pipeline" />
<Card title="Sequencer outages" href="/stack/rollup/outages" />
<Card title="Rollup protocol overview" href="/stack/rollup/overview" />
</Cards>
9 changes: 4 additions & 5 deletions pages/stack/security.mdx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
---

Check warning on line 1 in pages/stack/security.mdx

View workflow job for this annotation

GitHub Actions / lint

Missing newline character at end of file
title: Security
description: This section provides information on op stack security faqs and pausing the bridge.
description: Documentation covering Faq, Pause in the Security section of the OP Stack ecosystem.
krofax marked this conversation as resolved.
Show resolved Hide resolved
lang: en-US
---

import { Card, Cards } from 'nextra/components'

# Security

This section provides information on op stack security faqs and pausing the bridge.
Documentation covering Faq, Pause in the Security section of the OP Stack ecosystem.
krofax marked this conversation as resolved.
Show resolved Hide resolved

<Cards>
<Card title="Op stack security faqs" href="/stack/security/faq" />

<Card title="OP Stack security FAQs" href="/stack/security/faq" />
<Card title="Pausing the bridge" href="/stack/security/pause" />
</Cards>
</Cards>
11 changes: 8 additions & 3 deletions pages/stack/transactions.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

Check warning on line 1 in pages/stack/transactions.mdx

View workflow job for this annotation

GitHub Actions / lint

Missing newline character at end of file
title: Transactions
description: This section provides information on . You'll find reference to help you understand and work with these topics.
lang: en-US
Expand All @@ -8,8 +8,13 @@

# Transactions

This section provides information on . You'll find reference to help you understand and work with these topics.
This section provides information on transactions fees.
krofax marked this conversation as resolved.
Show resolved Hide resolved

<Cards>
<Card title="Transaction fees on op mainnet" href="/stack/transactions/fees" />
</Cards>
<Card title="Transaction fees" href="/stack/transactions/fees" />
<Card title="Transaction flow" href="/stack/transactions/transaction-flow" />
<Card title="Deposit flow" href="/stack/transactions/deposit-flow" />
<Card title="Withdrawal flow" href="/stack/transactions/withdrawal-flow" />
<Card title="Forced transaction" href="/stack/transactions/forced-transaction" />
<Card title="Cross domain transaction" href="/stack/transactions/cross-domain" />
</Cards>
20 changes: 20 additions & 0 deletions pages/stack/transactions/transactions.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---

Check warning on line 1 in pages/stack/transactions/transactions.mdx

View workflow job for this annotation

GitHub Actions / lint

Missing newline character at end of file
title: Transactions
description: Documentation covering Cross Domain, Deposit Flow, Fees, Forced Transaction, Transaction Flow, Withdrawal Flow in the Transactions section of the OP Stack ecosystem.
lang: en-US
---

import { Card, Cards } from 'nextra/components'

# Transactions

Documentation covering Cross Domain, Deposit Flow, Fees, Forced Transaction, Transaction Flow, Withdrawal Flow in the Transactions section of the OP Stack ecosystem.

<Cards>
<Card title="Cross-Domain" href="/stack/transactions/cross-domain" />
<Card title="Deposit flow" href="/stack/transactions/deposit-flow" />
<Card title="Transaction fees on OP Mainnet" href="/stack/transactions/fees" />
<Card title="Forced transaction" href="/stack/transactions/forced-transaction" />
<Card title="Transaction Flow" href="/stack/transactions/transaction-flow" />
<Card title="Withdrawal flow" href="/stack/transactions/withdrawal-flow" />
</Cards>
krofax marked this conversation as resolved.
Show resolved Hide resolved
krofax marked this conversation as resolved.
Show resolved Hide resolved
93 changes: 93 additions & 0 deletions utils/breadcrumbs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import * as fs from 'fs/promises';
import * as path from 'path';
import matter from 'gray-matter';

const rootDir = path.join(process.cwd(), 'pages');
const warnings: string[] = [];

// ANSI color codes
const YELLOW = '\x1b[33m';
const RESET = '\x1b[0m';
const BOLD = '\x1b[1m';

// Pages to exclude from checks
const excludedPages = [
'400.mdx',
'500.mdx',
'index.mdx',
'404.mdx'
];

async function getReferencedPagesFromBreadcrumb(breadcrumbPath: string): Promise<string[]> {
try {
const content = await fs.readFile(breadcrumbPath, 'utf-8');
const cardMatches = content.match(/<Card[^>]*href="([^"]+)"[^>]*>/g) || [];
return cardMatches.map(match => {
const hrefMatch = match.match(/href="([^"]+)"/);
return hrefMatch ? hrefMatch[1] : '';
}).filter(Boolean);
} catch (error) {
return [];
}
}
krofax marked this conversation as resolved.
Show resolved Hide resolved

async function checkDirectory(dirPath: string): Promise<void> {
const entries = await fs.readdir(dirPath, { withFileTypes: true });
const currentDir = path.basename(dirPath);

// Skip the root directory check
if (dirPath !== rootDir) {
const breadcrumbPath = path.join(dirPath, `${currentDir}.mdx`);
const referencedPages = await getReferencedPagesFromBreadcrumb(breadcrumbPath);

// Check all .mdx and .md files in the current directory
for (const entry of entries) {
if (entry.isFile() &&
(entry.name.endsWith('.mdx') || entry.name.endsWith('.md')) &&
!excludedPages.includes(entry.name) &&
entry.name !== `${currentDir}.mdx`) {

const pageName = entry.name.replace(/\.(md|mdx)$/, '');
// Dynamically construct the path relative to the pages directory
const relativePath = '/' + path.relative(rootDir, path.join(dirPath, pageName))
.replace(/\\/g, '/');

if (!referencedPages.includes(relativePath)) {
const humanReadableName = pageName.split('-')
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
.join(' ');

warnings.push(
`Page "${humanReadableName}" at path "${relativePath}" is not listed in the breadcrumb navigation of ${currentDir}.mdx`
);
}
}
}
}

// Process subdirectories
for (const entry of entries) {
if (entry.isDirectory() && !entry.name.startsWith('_') && !entry.name.startsWith('.')) {
await checkDirectory(path.join(dirPath, entry.name));
}
}
}

async function main() {
try {
await checkDirectory(rootDir);

if (warnings.length > 0) {
console.log(`${YELLOW}${BOLD}Missing pages in breadcrumb navigation:${RESET}`);
warnings.forEach(warning => console.log(`${YELLOW}- ${warning}${RESET}`));
process.exit(1);
} else {
console.log('All pages are properly listed in their respective breadcrumb navigation files.');
}
} catch (error) {
console.log(`${YELLOW}${BOLD}Error checking breadcrumbs:${RESET}`, error);
process.exit(1);
}
}

main();
krofax marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading