Skip to content

Commit c757466

Browse files
committed
feat(vitepress): add plugin to move llms.txt files to parent directory
Introduced a new plugin that moves llms.txt and llms-full.txt files generated by vitepress-plugin-llms to the parent directory of the output folder. Updated the VitePress configuration to include this new plugin and adjusted the base path for the documentation output.
1 parent 77190c7 commit c757466

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ docs/.vitepress/dist
99
docs/.vitepress/cache
1010
docs/public/gea-ui-showcase
1111
website/docs
12+
website/llms*.txt
1213
.worktrees

docs/.vitepress/config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { defineConfig } from 'vitepress'
22
import llmstxt, { copyOrDownloadAsMarkdownButtons } from 'vitepress-plugin-llms'
3+
import { moveLlmsTxtToOutDirParent } from './move-llms-txt-to-outdir-parent'
34

45
export default defineConfig({
56
vite: {
6-
plugins: [llmstxt() as any],
7+
plugins: [...(llmstxt() as any[]), moveLlmsTxtToOutDirParent() as any],
78
},
89
markdown: {
910
config(md) {
@@ -12,7 +13,7 @@ export default defineConfig({
1213
},
1314
title: 'Gea',
1415
description: 'A lightweight, reactive JavaScript UI framework with compile-time JSX and proxy-based stores.',
15-
base: '/docs/',
16+
base: '/docs',
1617
outDir: '../website/docs',
1718
head: [
1819
[
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
3+
4+
/**
5+
* vitepress-plugin-llms always emits llms.txt / llms-full.txt into VitePress outDir.
6+
* Move those two files to the parent folder (e.g. website/ next to website/docs/).
7+
* Per-page *.md copies stay in outDir so URLs under `base` stay correct.
8+
*/
9+
export function moveLlmsTxtToOutDirParent() {
10+
let outDir: string | undefined
11+
let isSsrBuild = false
12+
return {
13+
name: 'move-llms-txt-to-outdir-parent',
14+
apply: 'build' as const,
15+
enforce: 'post' as const,
16+
configResolved(resolved: { build: { ssr?: boolean }; vitepress?: { outDir?: string } }) {
17+
outDir = resolved.vitepress?.outDir
18+
isSsrBuild = Boolean(resolved.build.ssr)
19+
},
20+
async closeBundle() {
21+
if (isSsrBuild || !outDir) return
22+
const parent = path.dirname(path.resolve(outDir))
23+
for (const name of ['llms.txt', 'llms-full.txt'] as const) {
24+
const from = path.join(outDir, name)
25+
const to = path.join(parent, name)
26+
try {
27+
await fs.rename(from, to)
28+
} catch (e: unknown) {
29+
if ((e as NodeJS.ErrnoException).code !== 'ENOENT') throw e
30+
}
31+
}
32+
},
33+
}
34+
}

0 commit comments

Comments
 (0)