Skip to content

Commit 53241a7

Browse files
committed
Make all pages accessible in the MD format adding .md to path
1 parent 29e4157 commit 53241a7

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

.vitepress/llms.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function readPages(srcDir: string): PageInfo[] {
3838
title: fm.title || extractH1(content) || slug,
3939
llms_description: fm.llms_description,
4040
url: `/docs/${slug}`,
41-
srcPath: `llm/docs/${file}`,
41+
srcPath: `docs/${file}`,
4242
content: content.trim(),
4343
section: llmsValue === 'optional' ? 'optional' : 'docs',
4444
})
@@ -139,23 +139,33 @@ function buildLlmsFullTxt(pages: PageInfo[]): string {
139139
return lines.join('\n')
140140
}
141141

142+
/** Strip frontmatter from a .md file and return clean content */
143+
function stripFrontmatter(filePath: string): string {
144+
const raw = readFileSync(filePath, 'utf-8')
145+
const { content } = matter(raw)
146+
return content.trim() + '\n'
147+
}
148+
142149
// Build-time generation (called from buildEnd)
143150
export async function generateLlms(config: SiteConfig) {
144-
const pages = sortPages(readPages(config.srcDir), getSidebarPaths(config))
151+
const { srcDir, outDir } = config
145152

146-
// Per-page .md files
147-
for (const page of pages) {
148-
const outPath = path.join(config.outDir, page.srcPath)
153+
// Per-page .md files for ALL pages (uses VitePress's own page list)
154+
for (const page of config.pages) {
155+
const outPath = path.join(outDir, page)
149156
mkdirSync(path.dirname(outPath), { recursive: true })
150-
writeFileSync(outPath, page.content + '\n')
157+
writeFileSync(outPath, stripFrontmatter(path.join(srcDir, page)))
151158
}
152159

153-
writeFileSync(path.join(config.outDir, 'llms.txt'), buildLlmsTxt(pages))
154-
writeFileSync(path.join(config.outDir, 'llms-full.txt'), buildLlmsFullTxt(pages))
160+
// llms.txt and llms-full.txt (filtered by llms frontmatter)
161+
const pages = sortPages(readPages(srcDir), getSidebarPaths(config))
162+
163+
writeFileSync(path.join(outDir, 'llms.txt'), buildLlmsTxt(pages))
164+
writeFileSync(path.join(outDir, 'llms-full.txt'), buildLlmsFullTxt(pages))
155165

166+
console.log(`✓ ${config.pages.length} per-page .md files generated`)
156167
console.log(`✓ llms.txt generated (${pages.length} docs)`)
157168
console.log(`✓ llms-full.txt generated`)
158-
console.log(`✓ ${pages.length} per-page .md files generated`)
159169
}
160170

161171
// Vite plugin for dev server
@@ -185,15 +195,12 @@ export function llmsPlugin(): Plugin {
185195
return
186196
}
187197

188-
// Serve per-page .md files
189-
const mdMatch = url.match(/^\/llm\/docs\/(.+\.md)$/)
190-
if (mdMatch) {
191-
const filePath = path.join(docsRoot, 'docs', mdMatch[1])
198+
// Serve per-page .md files (strip frontmatter)
199+
if (url.endsWith('.md')) {
200+
const filePath = path.join(docsRoot, url.slice(1))
192201
if (existsSync(filePath)) {
193-
const raw = readFileSync(filePath, 'utf-8')
194-
const { content } = matter(raw)
195202
res.setHeader('Content-Type', 'text/markdown; charset=utf-8')
196-
res.end(content.trim() + '\n')
203+
res.end(stripFrontmatter(filePath))
197204
return
198205
}
199206
}

public/robots.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ Allow: /
33

44
Disallow: /llms.txt
55
Disallow: /llms-full.txt
6-
Disallow: /llm/
6+
Disallow: /*.md$

0 commit comments

Comments
 (0)