Skip to content

Commit 8265e8e

Browse files
rsbhclaude
andauthored
fix: runtime PACKAGE_ROOT, frontmatter ordering, llms.txt support (#19)
* fix: resolve PACKAGE_ROOT at runtime and add order to frontmatter schema - Replace build-time PACKAGE_ROOT injection with runtime resolution via import.meta.url, fixing broken next binary path in published npm package - Add `order` field to fumadocs frontmatter schema so sidebar ordering works - Use folder's index page order for group sorting, fallback to lowest child order Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: add unified and @types/unist deps, fix directive types for strict TS Adds missing type dependencies that caused Docker production build failures. Fixes DirectiveNode type to be compatible with strict unist types. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * feat: add llms.txt support with config toggle - Add /llms.txt (index) and /llms-full.txt (full content) routes - Controlled via llms.enabled in chronicle.yaml (default: false) - Upgrade fumadocs-core to 16.6.15 for native llms() support - Enable postprocess with includeProcessedMarkdown in source config Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2b6c947 commit 8265e8e

15 files changed

Lines changed: 101 additions & 42 deletions

File tree

bun.lock

Lines changed: 15 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/chronicle/build-cli.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ const result = await Bun.build({
55
outdir: 'dist/cli',
66
target: 'node',
77
format: 'esm',
8-
define: {
9-
PACKAGE_ROOT: JSON.stringify(path.resolve(import.meta.dir)),
10-
},
118
})
129

1310
if (!result.success) {

packages/chronicle/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@
3838
"@codemirror/view": "^6.39.14",
3939
"@heroicons/react": "^2.2.0",
4040
"@raystack/apsara": "^0.56.0",
41+
"@types/unist": "^3.0.3",
4142
"chalk": "^5.6.2",
4243
"class-variance-authority": "^0.7.1",
4344
"codemirror": "^6.0.2",
4445
"commander": "^14.0.2",
45-
"fumadocs-core": "^16.4.9",
46+
"fumadocs-core": "16.6.15",
4647
"fumadocs-mdx": "^14.2.6",
4748
"lodash": "^4.17.23",
4849
"mermaid": "^11.13.0",
@@ -53,6 +54,7 @@
5354
"remark-attr": "^0.11.1",
5455
"remark-directive": "^4.0.0",
5556
"slugify": "^1.6.6",
57+
"unified": "^11.0.5",
5658
"unist-util-visit": "^5.1.0",
5759
"yaml": "^2.8.2",
5860
"zod": "^4.3.6"

packages/chronicle/source.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { defineDocs, defineConfig } from 'fumadocs-mdx/config'
1+
import { defineDocs, defineConfig, frontmatterSchema } from 'fumadocs-mdx/config'
2+
import { z } from 'zod'
23
import remarkDirective from 'remark-directive'
34
import { remarkDirectiveAdmonition, remarkMdxMermaid } from 'fumadocs-core/mdx-plugins'
45
import remarkUnusedDirectives from './src/lib/remark-unused-directives'
@@ -8,6 +9,12 @@ const contentDir = process.env.CHRONICLE_CONTENT_DIR || './content'
89
export const docs = defineDocs({
910
dir: contentDir,
1011
docs: {
12+
schema: frontmatterSchema.extend({
13+
order: z.number().optional(),
14+
}),
15+
postprocess: {
16+
includeProcessedMarkdown: true,
17+
},
1118
files: ['**/*.mdx', '**/*.md', '!**/node_modules/**'],
1219
},
1320
})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { source } from '@/lib/source'
2+
import { loadConfig } from '@/lib/config'
3+
import { getLLMText } from '@/lib/get-llm-text'
4+
5+
export const revalidate = false
6+
7+
export async function GET() {
8+
const config = loadConfig()
9+
10+
if (!config.llms?.enabled) {
11+
return new Response('Not Found', { status: 404 })
12+
}
13+
14+
const scan = source.getPages().map(getLLMText)
15+
const scanned = await Promise.all(scan)
16+
17+
return new Response(scanned.join('\n\n'))
18+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { source } from '@/lib/source'
2+
import { loadConfig } from '@/lib/config'
3+
import { llms } from 'fumadocs-core/source'
4+
5+
export const revalidate = false
6+
7+
export function GET() {
8+
const config = loadConfig()
9+
10+
if (!config.llms?.enabled) {
11+
return new Response('Not Found', { status: 404 })
12+
}
13+
14+
return new Response(llms(source).index())
15+
}

packages/chronicle/src/cli/commands/build.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Command } from 'commander'
22
import { spawn } from 'child_process'
33
import path from 'path'
4+
import { fileURLToPath } from 'url'
45
import chalk from 'chalk'
56
import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '@/cli/utils'
67

7-
declare const PACKAGE_ROOT: string
8-
8+
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..')
99
const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next')
1010

1111
export const buildCommand = new Command('build')

packages/chronicle/src/cli/commands/dev.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Command } from 'commander'
22
import { spawn } from 'child_process'
33
import path from 'path'
4+
import { fileURLToPath } from 'url'
45
import chalk from 'chalk'
56
import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '@/cli/utils'
67

7-
declare const PACKAGE_ROOT: string
8-
8+
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..')
99
const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next')
1010

1111
export const devCommand = new Command('dev')

packages/chronicle/src/cli/commands/serve.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Command } from 'commander'
22
import { spawn } from 'child_process'
33
import path from 'path'
4+
import { fileURLToPath } from 'url'
45
import chalk from 'chalk'
56
import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '@/cli/utils'
67

7-
declare const PACKAGE_ROOT: string
8-
8+
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..')
99
const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next')
1010

1111
export const serveCommand = new Command('serve')

packages/chronicle/src/cli/commands/start.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Command } from 'commander'
22
import { spawn } from 'child_process'
33
import path from 'path'
4+
import { fileURLToPath } from 'url'
45
import chalk from 'chalk'
56
import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '@/cli/utils'
67

7-
declare const PACKAGE_ROOT: string
8-
8+
const PACKAGE_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', '..')
99
const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next')
1010

1111
export const startCommand = new Command('start')

0 commit comments

Comments
 (0)