diff --git a/bun.lock b/bun.lock index d0bc659c..f1b0c41f 100644 --- a/bun.lock +++ b/bun.lock @@ -18,11 +18,12 @@ "@codemirror/view": "^6.39.14", "@heroicons/react": "^2.2.0", "@raystack/apsara": "^0.56.0", + "@types/unist": "^3.0.3", "chalk": "^5.6.2", "class-variance-authority": "^0.7.1", "codemirror": "^6.0.2", "commander": "^14.0.2", - "fumadocs-core": "^16.4.9", + "fumadocs-core": "16.6.15", "fumadocs-mdx": "^14.2.6", "lodash": "^4.17.23", "mermaid": "^11.13.0", @@ -33,6 +34,7 @@ "remark-attr": "^0.11.1", "remark-directive": "^4.0.0", "slugify": "^1.6.6", + "unified": "^11.0.5", "unist-util-visit": "^5.1.0", "yaml": "^2.8.2", "zod": "^4.3.6", @@ -395,21 +397,23 @@ "@raystack/tools-config": ["@raystack/tools-config@0.56.0", "", { "peerDependencies": { "@biomejs/biome": ">=2.0.0" }, "optionalPeers": ["@biomejs/biome"] }, "sha512-Vh4Ei++2g0hycTFmCF5vjp8VIUasl9TUiQRNv517otYJDY49/C6gqjDt137NDrBRPyguJ+CL+SPY4sRt7UxQxQ=="], - "@shikijs/core": ["@shikijs/core@3.22.0", "", { "dependencies": { "@shikijs/types": "3.22.0", "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4", "hast-util-to-html": "^9.0.5" } }, "sha512-iAlTtSDDbJiRpvgL5ugKEATDtHdUVkqgHDm/gbD2ZS9c88mx7G1zSYjjOxp5Qa0eaW0MAQosFRmJSk354PRoQA=="], + "@shikijs/core": ["@shikijs/core@4.0.2", "", { "dependencies": { "@shikijs/primitive": "4.0.2", "@shikijs/types": "4.0.2", "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4", "hast-util-to-html": "^9.0.5" } }, "sha512-hxT0YF4ExEqB8G/qFdtJvpmHXBYJ2lWW7qTHDarVkIudPFE6iCIrqdgWxGn5s+ppkGXI0aEGlibI0PAyzP3zlw=="], - "@shikijs/engine-javascript": ["@shikijs/engine-javascript@3.22.0", "", { "dependencies": { "@shikijs/types": "3.22.0", "@shikijs/vscode-textmate": "^10.0.2", "oniguruma-to-es": "^4.3.4" } }, "sha512-jdKhfgW9CRtj3Tor0L7+yPwdG3CgP7W+ZEqSsojrMzCjD1e0IxIbwUMDDpYlVBlC08TACg4puwFGkZfLS+56Tw=="], + "@shikijs/engine-javascript": ["@shikijs/engine-javascript@4.0.2", "", { "dependencies": { "@shikijs/types": "4.0.2", "@shikijs/vscode-textmate": "^10.0.2", "oniguruma-to-es": "^4.3.4" } }, "sha512-7PW0Nm49DcoUIQEXlJhNNBHyoGMjalRETTCcjMqEaMoJRLljy1Bi/EGV3/qLBgLKQejdspiiYuHGQW6dX94Nag=="], - "@shikijs/engine-oniguruma": ["@shikijs/engine-oniguruma@3.22.0", "", { "dependencies": { "@shikijs/types": "3.22.0", "@shikijs/vscode-textmate": "^10.0.2" } }, "sha512-DyXsOG0vGtNtl7ygvabHd7Mt5EY8gCNqR9Y7Lpbbd/PbJvgWrqaKzH1JW6H6qFkuUa8aCxoiYVv8/YfFljiQxA=="], + "@shikijs/engine-oniguruma": ["@shikijs/engine-oniguruma@4.0.2", "", { "dependencies": { "@shikijs/types": "4.0.2", "@shikijs/vscode-textmate": "^10.0.2" } }, "sha512-UpCB9Y2sUKlS9z8juFSKz7ZtysmeXCgnRF0dlhXBkmQnek7lAToPte8DkxmEYGNTMii72zU/lyXiCB6StuZeJg=="], - "@shikijs/langs": ["@shikijs/langs@3.22.0", "", { "dependencies": { "@shikijs/types": "3.22.0" } }, "sha512-x/42TfhWmp6H00T6uwVrdTJGKgNdFbrEdhaDwSR5fd5zhQ1Q46bHq9EO61SCEWJR0HY7z2HNDMaBZp8JRmKiIA=="], + "@shikijs/langs": ["@shikijs/langs@4.0.2", "", { "dependencies": { "@shikijs/types": "4.0.2" } }, "sha512-KaXby5dvoeuZzN0rYQiPMjFoUrz4hgwIE+D6Du9owcHcl6/g16/yT5BQxSW5cGt2MZBz6Hl0YuRqf12omRfUUg=="], - "@shikijs/rehype": ["@shikijs/rehype@3.22.0", "", { "dependencies": { "@shikijs/types": "3.22.0", "@types/hast": "^3.0.4", "hast-util-to-string": "^3.0.1", "shiki": "3.22.0", "unified": "^11.0.5", "unist-util-visit": "^5.1.0" } }, "sha512-69b2VPc6XBy/VmAJlpBU5By+bJSBdE2nvgRCZXav7zujbrjXuT0F60DIrjKuutjPqNufuizE+E8tIZr2Yn8Z+g=="], + "@shikijs/primitive": ["@shikijs/primitive@4.0.2", "", { "dependencies": { "@shikijs/types": "4.0.2", "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4" } }, "sha512-M6UMPrSa3fN5ayeJwFVl9qWofl273wtK1VG8ySDZ1mQBfhCpdd8nEx7nPZ/tk7k+TYcpqBZzj/AnwxT9lO+HJw=="], - "@shikijs/themes": ["@shikijs/themes@3.22.0", "", { "dependencies": { "@shikijs/types": "3.22.0" } }, "sha512-o+tlOKqsr6FE4+mYJG08tfCFDS+3CG20HbldXeVoyP+cYSUxDhrFf3GPjE60U55iOkkjbpY2uC3It/eeja35/g=="], + "@shikijs/rehype": ["@shikijs/rehype@4.0.2", "", { "dependencies": { "@shikijs/types": "4.0.2", "@types/hast": "^3.0.4", "hast-util-to-string": "^3.0.1", "shiki": "4.0.2", "unified": "^11.0.5", "unist-util-visit": "^5.1.0" } }, "sha512-cmPlKLD8JeojasNFoY64162ScpEdEdQUMuVodPCrv1nx1z3bjmGwoKWDruQWa/ejSznImlaeB0Ty6Q3zPaVQAA=="], - "@shikijs/transformers": ["@shikijs/transformers@3.22.0", "", { "dependencies": { "@shikijs/core": "3.22.0", "@shikijs/types": "3.22.0" } }, "sha512-E7eRV7mwDBjueLF6852n2oYeJYxBq3NSsDk+uyruYAXONv4U8holGmIrT+mPRJQ1J1SNOH6L8G19KRzmBawrFw=="], + "@shikijs/themes": ["@shikijs/themes@4.0.2", "", { "dependencies": { "@shikijs/types": "4.0.2" } }, "sha512-mjCafwt8lJJaVSsQvNVrJumbnnj1RI8jbUKrPKgE6E3OvQKxnuRoBaYC51H4IGHePsGN/QtALglWBU7DoKDFnA=="], - "@shikijs/types": ["@shikijs/types@3.22.0", "", { "dependencies": { "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4" } }, "sha512-491iAekgKDBFE67z70Ok5a8KBMsQ2IJwOWw3us/7ffQkIBCyOQfm/aNwVMBUriP02QshIfgHCBSIYAl3u2eWjg=="], + "@shikijs/transformers": ["@shikijs/transformers@4.0.2", "", { "dependencies": { "@shikijs/core": "4.0.2", "@shikijs/types": "4.0.2" } }, "sha512-1+L0gf9v+SdDXs08vjaLb3mBFa8U7u37cwcBQIv/HCocLwX69Tt6LpUCjtB+UUTvQxI7BnjZKhN/wMjhHBcJGg=="], + + "@shikijs/types": ["@shikijs/types@4.0.2", "", { "dependencies": { "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4" } }, "sha512-qzbeRooUTPnLE+sHD/Z8DStmaDgnbbc/pMrU203950aRqjX/6AFHeDYT+j00y2lPdz0ywJKx7o/7qnqTivtlXg=="], "@shikijs/vscode-textmate": ["@shikijs/vscode-textmate@10.0.2", "", {}, "sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg=="], @@ -715,7 +719,7 @@ "fdir": ["fdir@6.5.0", "", { "peerDependencies": { "picomatch": "^3 || ^4" }, "optionalPeers": ["picomatch"] }, "sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg=="], - "fumadocs-core": ["fumadocs-core@16.6.3", "", { "dependencies": { "@formatjs/intl-localematcher": "^0.8.1", "@orama/orama": "^3.1.18", "@shikijs/rehype": "^3.22.0", "@shikijs/transformers": "^3.22.0", "estree-util-value-to-estree": "^3.5.0", "github-slugger": "^2.0.0", "hast-util-to-estree": "^3.1.3", "hast-util-to-jsx-runtime": "^2.3.6", "image-size": "^2.0.2", "mdast-util-mdx": "^3.0.0", "mdast-util-to-markdown": "^2.1.2", "negotiator": "^1.0.0", "npm-to-yarn": "^3.0.1", "path-to-regexp": "^8.3.0", "remark": "^15.0.1", "remark-gfm": "^4.0.1", "remark-rehype": "^11.1.2", "scroll-into-view-if-needed": "^3.1.0", "shiki": "^3.22.0", "tinyglobby": "^0.2.15", "unified": "^11.0.5", "unist-util-visit": "^5.1.0", "vfile": "^6.0.3" }, "peerDependencies": { "@mdx-js/mdx": "*", "@mixedbread/sdk": "^0.46.0", "@orama/core": "1.x.x", "@oramacloud/client": "2.x.x", "@tanstack/react-router": "1.x.x", "@types/estree-jsx": "*", "@types/hast": "*", "@types/mdast": "*", "@types/react": "*", "algoliasearch": "5.x.x", "lucide-react": "*", "next": "16.x.x", "react": "^19.2.0", "react-dom": "^19.2.0", "react-router": "7.x.x", "waku": "^0.26.0 || ^0.27.0 || ^1.0.0", "zod": "4.x.x" }, "optionalPeers": ["@mdx-js/mdx", "@mixedbread/sdk", "@orama/core", "@oramacloud/client", "@tanstack/react-router", "@types/estree-jsx", "@types/hast", "@types/mdast", "@types/react", "algoliasearch", "lucide-react", "next", "react", "react-dom", "react-router", "waku", "zod"] }, "sha512-mBeQg1s6lP/0GcjHj5F/x40GaUYp8oYCSEygbfMBl4hykXQuINZdEsMgTcCU7OG5G5VH3MN7XDbqXRVJXtJylg=="], + "fumadocs-core": ["fumadocs-core@16.6.15", "", { "dependencies": { "@formatjs/intl-localematcher": "^0.8.1", "@orama/orama": "^3.1.18", "@shikijs/rehype": "^4.0.2", "@shikijs/transformers": "^4.0.2", "estree-util-value-to-estree": "^3.5.0", "github-slugger": "^2.0.0", "hast-util-to-estree": "^3.1.3", "hast-util-to-jsx-runtime": "^2.3.6", "image-size": "^2.0.2", "mdast-util-mdx": "^3.0.0", "mdast-util-to-markdown": "^2.1.2", "negotiator": "^1.0.0", "npm-to-yarn": "^3.0.1", "path-to-regexp": "^8.3.0", "remark": "^15.0.1", "remark-gfm": "^4.0.1", "remark-rehype": "^11.1.2", "scroll-into-view-if-needed": "^3.1.0", "shiki": "^4.0.2", "tinyglobby": "^0.2.15", "unified": "^11.0.5", "unist-util-visit": "^5.1.0", "vfile": "^6.0.3" }, "peerDependencies": { "@mdx-js/mdx": "*", "@mixedbread/sdk": "^0.46.0", "@orama/core": "1.x.x", "@oramacloud/client": "2.x.x", "@tanstack/react-router": "1.x.x", "@types/estree-jsx": "*", "@types/hast": "*", "@types/mdast": "*", "@types/react": "*", "algoliasearch": "5.x.x", "flexsearch": "*", "lucide-react": "*", "next": "16.x.x", "react": "^19.2.0", "react-dom": "^19.2.0", "react-router": "7.x.x", "waku": "^0.26.0 || ^0.27.0 || ^1.0.0", "zod": "4.x.x" }, "optionalPeers": ["@mdx-js/mdx", "@mixedbread/sdk", "@orama/core", "@oramacloud/client", "@tanstack/react-router", "@types/estree-jsx", "@types/hast", "@types/mdast", "@types/react", "algoliasearch", "flexsearch", "lucide-react", "next", "react", "react-dom", "react-router", "waku", "zod"] }, "sha512-N6gbXicmaylWeaEFu9vpw25dZK29rPPjalrcIqDRgDklCFkxHn0fsagDMZiSjFBn4RfWRErL6mYmu24WSwosew=="], "fumadocs-mdx": ["fumadocs-mdx@14.2.7", "", { "dependencies": { "@mdx-js/mdx": "^3.1.1", "@standard-schema/spec": "^1.1.0", "chokidar": "^5.0.0", "esbuild": "^0.27.3", "estree-util-value-to-estree": "^3.5.0", "js-yaml": "^4.1.1", "mdast-util-to-markdown": "^2.1.2", "picocolors": "^1.1.1", "picomatch": "^4.0.3", "remark-mdx": "^3.1.1", "tinyexec": "^1.0.2", "tinyglobby": "^0.2.15", "unified": "^11.0.5", "unist-util-remove-position": "^5.0.0", "unist-util-visit": "^5.1.0", "vfile": "^6.0.3", "zod": "^4.3.6" }, "peerDependencies": { "@fumadocs/mdx-remote": "^1.4.0", "@types/mdast": "*", "@types/mdx": "*", "@types/react": "*", "fumadocs-core": "^15.0.0 || ^16.0.0", "mdast-util-directive": "*", "mdast-util-mdx-jsx": "*", "next": "^15.3.0 || ^16.0.0", "react": "*", "vite": "6.x.x || 7.x.x" }, "optionalPeers": ["@fumadocs/mdx-remote", "@types/mdast", "@types/mdx", "@types/react", "mdast-util-directive", "mdast-util-mdx-jsx", "next", "react", "vite"], "bin": { "fumadocs-mdx": "dist/bin.js" } }, "sha512-Q2W79F7wpwhq4HoYPw9GnMpf5ZmpdU7YzZND7EWwwOiWddfyzPh6EH/z7MFhhdhsTqRh9/kwwsu9XslWDRRPsg=="], @@ -1005,7 +1009,7 @@ "sharp": ["sharp@0.34.5", "", { "dependencies": { "@img/colour": "^1.0.0", "detect-libc": "^2.1.2", "semver": "^7.7.3" }, "optionalDependencies": { "@img/sharp-darwin-arm64": "0.34.5", "@img/sharp-darwin-x64": "0.34.5", "@img/sharp-libvips-darwin-arm64": "1.2.4", "@img/sharp-libvips-darwin-x64": "1.2.4", "@img/sharp-libvips-linux-arm": "1.2.4", "@img/sharp-libvips-linux-arm64": "1.2.4", "@img/sharp-libvips-linux-ppc64": "1.2.4", "@img/sharp-libvips-linux-riscv64": "1.2.4", "@img/sharp-libvips-linux-s390x": "1.2.4", "@img/sharp-libvips-linux-x64": "1.2.4", "@img/sharp-libvips-linuxmusl-arm64": "1.2.4", "@img/sharp-libvips-linuxmusl-x64": "1.2.4", "@img/sharp-linux-arm": "0.34.5", "@img/sharp-linux-arm64": "0.34.5", "@img/sharp-linux-ppc64": "0.34.5", "@img/sharp-linux-riscv64": "0.34.5", "@img/sharp-linux-s390x": "0.34.5", "@img/sharp-linux-x64": "0.34.5", "@img/sharp-linuxmusl-arm64": "0.34.5", "@img/sharp-linuxmusl-x64": "0.34.5", "@img/sharp-wasm32": "0.34.5", "@img/sharp-win32-arm64": "0.34.5", "@img/sharp-win32-ia32": "0.34.5", "@img/sharp-win32-x64": "0.34.5" } }, "sha512-Ou9I5Ft9WNcCbXrU9cMgPBcCK8LiwLqcbywW3t4oDV37n1pzpuNLsYiAV8eODnjbtQlSDwZ2cUEeQz4E54Hltg=="], - "shiki": ["shiki@3.22.0", "", { "dependencies": { "@shikijs/core": "3.22.0", "@shikijs/engine-javascript": "3.22.0", "@shikijs/engine-oniguruma": "3.22.0", "@shikijs/langs": "3.22.0", "@shikijs/themes": "3.22.0", "@shikijs/types": "3.22.0", "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4" } }, "sha512-LBnhsoYEe0Eou4e1VgJACes+O6S6QC0w71fCSp5Oya79inkwkm15gQ1UF6VtQ8j/taMDh79hAB49WUk8ALQW3g=="], + "shiki": ["shiki@4.0.2", "", { "dependencies": { "@shikijs/core": "4.0.2", "@shikijs/engine-javascript": "4.0.2", "@shikijs/engine-oniguruma": "4.0.2", "@shikijs/langs": "4.0.2", "@shikijs/themes": "4.0.2", "@shikijs/types": "4.0.2", "@shikijs/vscode-textmate": "^10.0.2", "@types/hast": "^3.0.4" } }, "sha512-eAVKTMedR5ckPo4xne/PjYQYrU3qx78gtJZ+sHlXEg5IHhhoQhMfZVzetTYuaJS0L2Ef3AcCRzCHV8T0WI6nIQ=="], "slugify": ["slugify@1.6.6", "", {}, "sha512-h+z7HKHYXj6wJU+AnS/+IH8Uh9fdcX1Lrhg1/VMdf9PwoBQXFcXiAdsy2tSK0P6gKwJLXp02r90ahUCqHk9rrw=="], diff --git a/packages/chronicle/build-cli.ts b/packages/chronicle/build-cli.ts index 3b0fbcc6..2f0a6f73 100644 --- a/packages/chronicle/build-cli.ts +++ b/packages/chronicle/build-cli.ts @@ -5,9 +5,6 @@ const result = await Bun.build({ outdir: 'dist/cli', target: 'node', format: 'esm', - define: { - PACKAGE_ROOT: JSON.stringify(path.resolve(import.meta.dir)), - }, }) if (!result.success) { diff --git a/packages/chronicle/package.json b/packages/chronicle/package.json index 41bab329..970edbd3 100644 --- a/packages/chronicle/package.json +++ b/packages/chronicle/package.json @@ -38,11 +38,12 @@ "@codemirror/view": "^6.39.14", "@heroicons/react": "^2.2.0", "@raystack/apsara": "^0.56.0", + "@types/unist": "^3.0.3", "chalk": "^5.6.2", "class-variance-authority": "^0.7.1", "codemirror": "^6.0.2", "commander": "^14.0.2", - "fumadocs-core": "^16.4.9", + "fumadocs-core": "16.6.15", "fumadocs-mdx": "^14.2.6", "lodash": "^4.17.23", "mermaid": "^11.13.0", @@ -53,6 +54,7 @@ "remark-attr": "^0.11.1", "remark-directive": "^4.0.0", "slugify": "^1.6.6", + "unified": "^11.0.5", "unist-util-visit": "^5.1.0", "yaml": "^2.8.2", "zod": "^4.3.6" diff --git a/packages/chronicle/source.config.ts b/packages/chronicle/source.config.ts index 78d44635..24b8e2ac 100644 --- a/packages/chronicle/source.config.ts +++ b/packages/chronicle/source.config.ts @@ -1,4 +1,5 @@ -import { defineDocs, defineConfig } from 'fumadocs-mdx/config' +import { defineDocs, defineConfig, frontmatterSchema } from 'fumadocs-mdx/config' +import { z } from 'zod' import remarkDirective from 'remark-directive' import { remarkDirectiveAdmonition, remarkMdxMermaid } from 'fumadocs-core/mdx-plugins' import remarkUnusedDirectives from './src/lib/remark-unused-directives' @@ -8,6 +9,12 @@ const contentDir = process.env.CHRONICLE_CONTENT_DIR || './content' export const docs = defineDocs({ dir: contentDir, docs: { + schema: frontmatterSchema.extend({ + order: z.number().optional(), + }), + postprocess: { + includeProcessedMarkdown: true, + }, files: ['**/*.mdx', '**/*.md', '!**/node_modules/**'], }, }) diff --git a/packages/chronicle/src/app/llms-full.txt/route.ts b/packages/chronicle/src/app/llms-full.txt/route.ts new file mode 100644 index 00000000..beb9c70b --- /dev/null +++ b/packages/chronicle/src/app/llms-full.txt/route.ts @@ -0,0 +1,18 @@ +import { source } from '@/lib/source' +import { loadConfig } from '@/lib/config' +import { getLLMText } from '@/lib/get-llm-text' + +export const revalidate = false + +export async function GET() { + const config = loadConfig() + + if (!config.llms?.enabled) { + return new Response('Not Found', { status: 404 }) + } + + const scan = source.getPages().map(getLLMText) + const scanned = await Promise.all(scan) + + return new Response(scanned.join('\n\n')) +} diff --git a/packages/chronicle/src/app/llms.txt/route.ts b/packages/chronicle/src/app/llms.txt/route.ts new file mode 100644 index 00000000..664c6cff --- /dev/null +++ b/packages/chronicle/src/app/llms.txt/route.ts @@ -0,0 +1,15 @@ +import { source } from '@/lib/source' +import { loadConfig } from '@/lib/config' +import { llms } from 'fumadocs-core/source' + +export const revalidate = false + +export function GET() { + const config = loadConfig() + + if (!config.llms?.enabled) { + return new Response('Not Found', { status: 404 }) + } + + return new Response(llms(source).index()) +} diff --git a/packages/chronicle/src/cli/commands/build.ts b/packages/chronicle/src/cli/commands/build.ts index 46c3a4ff..ef11356a 100644 --- a/packages/chronicle/src/cli/commands/build.ts +++ b/packages/chronicle/src/cli/commands/build.ts @@ -1,11 +1,11 @@ import { Command } from 'commander' import { spawn } from 'child_process' import path from 'path' +import { fileURLToPath } from 'url' import chalk from 'chalk' import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '@/cli/utils' -declare const PACKAGE_ROOT: string - +const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..') const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next') export const buildCommand = new Command('build') diff --git a/packages/chronicle/src/cli/commands/dev.ts b/packages/chronicle/src/cli/commands/dev.ts index 2640ac5f..513d2d96 100644 --- a/packages/chronicle/src/cli/commands/dev.ts +++ b/packages/chronicle/src/cli/commands/dev.ts @@ -1,11 +1,11 @@ import { Command } from 'commander' import { spawn } from 'child_process' import path from 'path' +import { fileURLToPath } from 'url' import chalk from 'chalk' import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '@/cli/utils' -declare const PACKAGE_ROOT: string - +const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..') const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next') export const devCommand = new Command('dev') diff --git a/packages/chronicle/src/cli/commands/serve.ts b/packages/chronicle/src/cli/commands/serve.ts index ca3a664b..6d9cb53f 100644 --- a/packages/chronicle/src/cli/commands/serve.ts +++ b/packages/chronicle/src/cli/commands/serve.ts @@ -1,11 +1,11 @@ import { Command } from 'commander' import { spawn } from 'child_process' import path from 'path' +import { fileURLToPath } from 'url' import chalk from 'chalk' import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '@/cli/utils' -declare const PACKAGE_ROOT: string - +const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..') const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next') export const serveCommand = new Command('serve') diff --git a/packages/chronicle/src/cli/commands/start.ts b/packages/chronicle/src/cli/commands/start.ts index 497d39d4..f1081c68 100644 --- a/packages/chronicle/src/cli/commands/start.ts +++ b/packages/chronicle/src/cli/commands/start.ts @@ -1,11 +1,11 @@ import { Command } from 'commander' import { spawn } from 'child_process' import path from 'path' +import { fileURLToPath } from 'url' import chalk from 'chalk' import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '@/cli/utils' -declare const PACKAGE_ROOT: string - +const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..') const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next') export const startCommand = new Command('start') diff --git a/packages/chronicle/src/lib/config.ts b/packages/chronicle/src/lib/config.ts index 8f4f9d1d..e647d2b2 100644 --- a/packages/chronicle/src/lib/config.ts +++ b/packages/chronicle/src/lib/config.ts @@ -32,5 +32,6 @@ export function loadConfig(): ChronicleConfig { search: { ...defaultConfig.search, ...userConfig.search }, footer: userConfig.footer, api: userConfig.api, + llms: { enabled: false, ...userConfig.llms }, } } \ No newline at end of file diff --git a/packages/chronicle/src/lib/get-llm-text.ts b/packages/chronicle/src/lib/get-llm-text.ts new file mode 100644 index 00000000..ca218b17 --- /dev/null +++ b/packages/chronicle/src/lib/get-llm-text.ts @@ -0,0 +1,10 @@ +import { source } from '@/lib/source' +import type { InferPageType } from 'fumadocs-core/source' + +export async function getLLMText(page: InferPageType) { + const processed = await page.data.getText('processed') + + return `# ${page.data.title} (${page.url}) + +${processed}` +} diff --git a/packages/chronicle/src/lib/remark-unused-directives.ts b/packages/chronicle/src/lib/remark-unused-directives.ts index d1d5a889..34076bdb 100644 --- a/packages/chronicle/src/lib/remark-unused-directives.ts +++ b/packages/chronicle/src/lib/remark-unused-directives.ts @@ -2,26 +2,25 @@ import { visit } from 'unist-util-visit' import type { Plugin } from 'unified' import type { Node } from 'unist' -interface DirectiveNode extends Node { - name?: string - attributes?: Record - children?: Node[] - data?: unknown - [key: string]: unknown -} - const remarkUnusedDirectives: Plugin = () => { return (tree) => { - visit(tree, ['textDirective'], (node: DirectiveNode) => { - if (!node.data) { - const hasAttributes = node.attributes && Object.keys(node.attributes).length > 0 - const hasChildren = node.children && node.children.length > 0 + visit(tree, ['textDirective'], (node) => { + const directive = node as Node & { + name?: string + attributes?: Record + children?: Node[] + value?: string + [key: string]: unknown + } + if (!directive.data) { + const hasAttributes = directive.attributes && Object.keys(directive.attributes).length > 0 + const hasChildren = directive.children && directive.children.length > 0 if (!hasAttributes && !hasChildren) { - const name = node.name + const name = directive.name if (!name) return - Object.keys(node).forEach((key) => delete node[key]) - node.type = 'text' - node.value = `:${name}` + Object.keys(directive).forEach((key) => delete directive[key]) + directive.type = 'text' + directive.value = `:${name}` } } }) diff --git a/packages/chronicle/src/lib/source.ts b/packages/chronicle/src/lib/source.ts index 31282c69..3acd4592 100644 --- a/packages/chronicle/src/lib/source.ts +++ b/packages/chronicle/src/lib/source.ts @@ -51,11 +51,12 @@ export function buildPageTree(): PageTree { const folderItems: PageTreeItem[] = [] folders.forEach((items, folder) => { const sorted = sortByOrder(items) - const indexPage = sorted[0] + const indexPage = items.find(item => item.url === `/${folder}`) + const folderOrder = indexPage?.order ?? sorted[0]?.order folderItems.push({ type: 'folder', name: folder.charAt(0).toUpperCase() + folder.slice(1), - order: indexPage?.order, + order: folderOrder, children: sorted, }) }) diff --git a/packages/chronicle/src/types/config.ts b/packages/chronicle/src/types/config.ts index 51332ad8..450fc5b1 100644 --- a/packages/chronicle/src/types/config.ts +++ b/packages/chronicle/src/types/config.ts @@ -7,6 +7,11 @@ export interface ChronicleConfig { search?: SearchConfig footer?: FooterConfig api?: ApiConfig[] + llms?: LlmsConfig +} + +export interface LlmsConfig { + enabled?: boolean } export interface ApiConfig {