diff --git a/.gitignore b/.gitignore index 2708fdb..eb02267 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,9 @@ node_modules .env _pagefind/ .claude/settings.local.json + +# Generated from content/ at build time +/public/llms.txt +/public/llms-full.txt +/public/.ai-docs-manifest.json +/public/**/*.md diff --git a/README.md b/README.md index dd7c466..8e03c55 100644 --- a/README.md +++ b/README.md @@ -40,3 +40,16 @@ If you have feedback, please open an issue or reach out to [@williamhzo](https:/ ## License All content is © Shape Factory. + +## Documentation for AI tools + +The production build generates `/llms.txt`, `/llms-full.txt`, and Markdown versions of all documentation pages from `content/` and the shared cards and callouts. Each HTML page links to its Markdown alternative. `/llms.txt` groups entry points by task, while `/llms-full.txt` contains the technical documentation corpus. + +```bash +bun run generate:ai-docs +bun run test:ai-docs +``` + +Edit the MDX source or shared components, then regenerate the assets. Do not edit generated Markdown directly. The converter handles the current static MDX patterns and stops on unknown components, unclosed code fences, or unmapped documentation links. Add conversion support and a test when introducing a new MDX component. Fenced code blocks are preserved verbatim. + +Generated files under `public/` are ignored by Git. Both development and production scripts generate them from the existing source before starting Next.js. `.ai-docs-manifest.json` records the generated page paths so deleted pages are removed on regeneration. Each HTML page derives its Markdown alternate from its source file path, which the generator mirrors under `public/`. Titles, summaries, examples, and component text come from the original content; only navigation grouping is configured in the generator. diff --git a/app/[[...mdxPath]]/page.tsx b/app/[[...mdxPath]]/page.tsx index 0df8644..ac9f351 100644 --- a/app/[[...mdxPath]]/page.tsx +++ b/app/[[...mdxPath]]/page.tsx @@ -1,3 +1,4 @@ +import { paths } from '@paths'; import { generateStaticParamsFor, importPage } from 'nextra/pages'; import { useMDXComponents as getMDXComponents } from '../../mdx-components'; @@ -6,7 +7,20 @@ export const generateStaticParams = generateStaticParamsFor('mdxPath'); export async function generateMetadata(props) { const params = await props.params; const { metadata } = await importPage(params.mdxPath); - return metadata; + // Nextra exposes the source file (e.g. content/quick-start/index.mdx); the AI docs + // generator writes its Markdown twin to the same relative path under public/. + const markdown = metadata.filePath?.replace(/^content\//, '/').replace(/\.mdx?$/, '.md'); + if (!markdown) return metadata; + return { + ...metadata, + alternates: { + ...metadata.alternates, + types: { + ...metadata.alternates?.types, + 'text/markdown': paths.canonical + markdown, + }, + }, + }; } const Wrapper = getMDXComponents({}).wrapper; diff --git a/app/layout.tsx b/app/layout.tsx index 77903c8..4fd3507 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -57,7 +57,7 @@ export default async function RootLayout({ children }) { light: '#fff', }} > - {/* Your additional tags should be passed as `children` of `
` element */} + diff --git a/next.config.ts b/next.config.ts index aa2f155..c2d57af 100644 --- a/next.config.ts +++ b/next.config.ts @@ -4,6 +4,19 @@ import type { NextConfig } from 'next'; const withNextra = nextra({}); export default withNextra({ + headers: async () => [ + ...['/llms.txt', '/llms-full.txt'].map((source) => ({ + source, + headers: [{ key: 'Content-Type', value: 'text/plain; charset=utf-8' }], + })), + { + source: '/:path*.md', + headers: [ + { key: 'Content-Type', value: 'text/markdown; charset=utf-8' }, + { key: 'Link', value: '; rel="describedby"' }, + ], + }, + ], redirects: () => [ { source: '/building-on-shape/gasback', diff --git a/package.json b/package.json index 5b86e59..2954a92 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,11 @@ { "scripts": { - "dev": "next dev", - "build": "next build", + "dev": "node scripts/generate-ai-docs.mjs && next dev", + "build": "node scripts/generate-ai-docs.mjs && next build", "start": "next start", - "postbuild": "pagefind --site .next/server/app --output-path public/_pagefind" + "postbuild": "pagefind --site .next/server/app --output-path public/_pagefind", + "generate:ai-docs": "node scripts/generate-ai-docs.mjs", + "test:ai-docs": "SHAPE_DOCS_TEST_ROOT=. node --test scripts/generate-ai-docs.test.mjs" }, "dependencies": { "@tailwindcss/postcss": "^4.1.18", diff --git a/public/llms.txt b/public/llms.txt deleted file mode 100644 index e0d3220..0000000 --- a/public/llms.txt +++ /dev/null @@ -1,70 +0,0 @@ -# Shape Network Documentation - -> Shape is a culture-first EVM-compatible L2 built on Ethereum and the Optimism Superchain. It returns 80% of sequencer fees to contract owners via Gasback. Chain ID: 360 (mainnet), 11011 (testnet). Currency: ETH. RPC: https://mainnet.shape.network - -## Getting Started - -- [Introduction](https://docs.shape.network): Overview of Shape, the culture-first L2 for creators and the new NFT economy -- [Wallet Setup](https://docs.shape.network/wallet-setup): Add Shape to your wallet, bridge ETH, mint your Stack -- [Gasback](https://docs.shape.network/gasback): Claim back 80% of L2 sequencer fees users spend interacting with your contracts -- [The Stack](https://docs.shape.network/the-stack): Dynamic NFT reputation system with bronze, silver, gold, and special medals - -## Quick Start - -- [Quick Start](https://docs.shape.network/quick-start): Developer onboarding hub for Shape -- [Connect to Shape](https://docs.shape.network/quick-start/connect-to-shape): Configure viem, wagmi, Foundry, and ethers.js for Shape Mainnet (chain ID 360) and Shape Sepolia (chain ID 11011) -- [Deploy a Contract](https://docs.shape.network/quick-start/deploy-a-contract): Deploy and verify a smart contract on Shape with Foundry - -## Building on Shape - -- [Builder Kit](https://docs.shape.network/building-on-shape/builder-kit): Next.js starter with wallet connect (wagmi), NFT fetching, Shape RPC, and Shadcn UI -- [AI Agents](https://docs.shape.network/building-on-shape/ai): Build AI agents with MCP, Shape MCP server, and Vercel AI SDK -- [Transaction Fees](https://docs.shape.network/building-on-shape/transaction-fees): L1 security fees + L2 execution fees. 80% of L2 fees go back to contract owners via Gasback, 15% to Optimism Collective, 5% to Shape Foundation -- [Differences from Ethereum](https://docs.shape.network/building-on-shape/differences-ethereum-shape): EVM equivalent via OP Stack with minor opcode changes, dual-fee system, faster block times -- [Alchemy API](https://docs.shape.network/building-on-shape/alchemy-api): Full Alchemy tool suite available on Shape -- [Superchain Incentives](https://docs.shape.network/building-on-shape/superchain-incentives): RetroPGF, free contract deployment, gas sponsorship, launch support - -## Technical Reference - -- [Network Information](https://docs.shape.network/technical-details/network-information): Mainnet chain ID 360, RPC https://mainnet.shape.network, explorer https://shapescan.xyz. Testnet chain ID 11011, RPC https://sepolia.shape.network, explorer https://sepolia.shapescan.xyz -- [Contract Addresses](https://docs.shape.network/technical-details/contract-addresses): L1 and L2 contract addresses for mainnet and Sepolia. Gasback contract: 0xf5e602c87d675E978F097503aedE4A766285a08B (mainnet), 0xdF329d59bC797907703F7c198dDA2d770fC45034 (testnet) -- [Run a Node](https://docs.shape.network/technical-details/run-a-node): Run Shape mainnet and Sepolia nodes using op-node with custom rollup.json and genesis.json - -## Onchain Projects - -- [Onchain Compatible](https://docs.shape.network/building-on-shape/onchain-compatible): Collection of interoperable onchain projects on Shape -- [Assembly](https://docs.shape.network/building-on-shape/onchain-compatible/assembly): ERC1155 crafting system built on Otoms. Blueprints, tiers, mutator contracts, fungible and non-fungible items -- [OTOM](https://docs.shape.network/building-on-shape/onchain-compatible/otom): Onchain particle chemistry by Kjetil Golid. Mine otoms, annihilate for energy, react to create molecules - -## Tools - -- [Account Abstraction](https://docs.shape.network/tools/account-abstraction): Alchemy Bundler, Gas Manager, Embedded Accounts, Smart Accounts. Crossmint NFT Checkout and Wallet-as-a-Service -- [Bridges](https://docs.shape.network/tools/bridges): Relay (instant bridging), Superbridge (native bridging), Alchemy bridge. Testnet bridges available for Sepolia -- [Explorers](https://docs.shape.network/tools/explorers): Shapescan (block explorer), Deca (NFT explorer), Zapper (human-readable onchain activity) -- [Data Indexers](https://docs.shape.network/tools/data-indexers): Alchemy NFT/Token/Transfers APIs and Webhooks, Alchemy Subgraphs, Goldsky, Reservoir, SimpleHash -- [Faucets](https://docs.shape.network/tools/faucets): Alchemy and Optimism faucets for Shape Sepolia testnet ETH -- [Node Providers](https://docs.shape.network/tools/node-providers): Alchemy Supernode RPC -- [Oracles - Gelato VRF](https://docs.shape.network/tools/oracles/gelato-vrf): Verifiable randomness using Drand for gaming, DeFi, NFT generation -- [Safes & Asset Security](https://docs.shape.network/tools/safes-asset-security): Safe multisig on Shape, Delegate for hot wallet claim/mint/ownership -- [Sybil Resistance](https://docs.shape.network/tools/sybil-resistance): Gitcoin Passport, Premint allowlists, Crossmint Verifiable Credentials - -## Tutorials - -- [Launch an NFT Collection](https://docs.shape.network/tutorials/mint-nft-collection): Deploy an ERC-721 contract on Shape with Foundry, mint an NFT, verify on Shapescan -- [Register Contract for Gasback (Dashboard)](https://docs.shape.network/tutorials/registering-contract-gasback/dashboard): Step-by-step UI guide to register contracts via the Gasback dashboard -- [Register Contract for Gasback (Programmatic)](https://docs.shape.network/tutorials/registering-contract-gasback/programmatically): Three Solidity approaches to register contracts for Gasback - -## Optional - -- [Shape Website](https://shape.network) -- [Discord](https://discord.com/invite/shape-l2) -- [X / Twitter](https://x.com/shape) -- [GitHub](https://github.com/shape-network) -- [Shape MCP Server](https://github.com/shape-network/mcp-server): MCP server for AI agents to query Gasback, NFT analytics, Stack medals -- [Builder Kit Repo](https://github.com/shape-network/builder-kit): Next.js starter template source code -- [Assembly Repo](https://github.com/shape-network/assembly): Assembly items system source code and contracts -- [OTOM Contracts](https://github.com/shape-network/otom-contracts): OTOM smart contracts source code -- [Gasback Dashboard](https://gasback.shape.network): Register and manage Gasback for your contracts -- [The Stack App](https://stack.shape.network): Mint your Stack and track medals -- [Shapescan](https://shapescan.xyz): Block explorer -- [Deca](https://deca.art): NFT explorer diff --git a/scripts/generate-ai-docs.mjs b/scripts/generate-ai-docs.mjs new file mode 100644 index 0000000..ba32515 --- /dev/null +++ b/scripts/generate-ai-docs.mjs @@ -0,0 +1,298 @@ +import { readFile, readdir, mkdir, writeFile, rm } from 'node:fs/promises'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const ORIGIN = 'https://docs.shape.network'; +const decode = (text) => + text.replace( + /&(apos|quot|amp|lt|gt|nbsp);/g, + (_, key) => ({ apos: "'", quot: '"', amp: '&', lt: '<', gt: '>', nbsp: ' ' })[key] + ); + +// Protect code before processing MDX: imports and JSX inside examples are content. +export function protectCode(text) { + const saved = []; + const save = (value) => { + saved.push(value); + return `\u0000CODE${saved.length - 1}\u0000`; + }; + let fence; + let block = []; + const lines = []; + for (const line of text.split('\n')) { + const marker = line.match(/^ {0,3}(`{3,}|~{3,})/); + if (!fence && marker) { + fence = marker[1]; + block = [line]; + } else if (fence) { + block.push(line); + if ( + marker && + marker[1][0] === fence[0] && + marker[1].length >= fence.length && + /^ {0,3}(`{3,}|~{3,})\s*$/.test(line) + ) { + lines.push(save(block.join('\n'))); + fence = undefined; + } + } else lines.push(line); + } + if (fence) throw new Error('Unclosed code fence'); + const protectedText = lines.join('\n').replace(/(`+)([^\n]*?)\1/g, save); + return { + text: protectedText, + restore: (value) => value.replace(/\u0000CODE(\d+)\u0000/g, (_, index) => saved[Number(index)]), + }; +} + +function attr(attributes, name, paths) { + const literal = attributes.match(new RegExp(`\\b${name}="([^"]*)"`)); + if (literal) return decode(literal[1]); + const ref = attributes.match(new RegExp(`\\b${name}=\\{paths\\.(\\w+)\\}`)); + if (ref && paths[ref[1]]) return paths[ref[1]]; + throw new Error(`Unsupported or missing ${name}: ${attributes}`); +} + +function renderJsx(text, components, paths) { + text = text.replace(/<([A-Z]\w*)\s*\/>/g, (_, name) => { + if (!(name in components)) throw new Error(`Unsupported component: ${name}`); + return renderJsx(components[name], components, paths); + }); + text = text.replace(/