aboutsummaryrefslogtreecommitdiff
path: root/website/scripts/patch-starlight-llms.mjs
blob: 16d3ba9ba7769e156b654445588c92e4af28ac51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { readFile, writeFile } from 'node:fs/promises';
import { resolve } from 'node:path';

const path = resolve('node_modules/starlight-llms-txt/llms-full.txt.ts');
const original = await readFile(path, 'utf8');
const importLine = "import { starlightLllmsTxtContext } from 'virtual:starlight-llms-txt/context';";
const excludeLine = '\t\texclude: starlightLllmsTxtContext.exclude,';

if (original.includes(importLine) && original.includes(excludeLine)) process.exit(0);

const withImport = original.replace(
  "import { generateLlmsTxt } from './generator';",
  `${importLine}\nimport { generateLlmsTxt } from './generator';`,
);
const patched = withImport.replace(
  '\t\tdescription: `This is the full developer documentation for ${getSiteTitle()}`,',
  '\t\tdescription: `This is the full developer documentation for ${getSiteTitle()}`,\n' + excludeLine,
);

if (patched === original || !patched.includes(importLine) || !patched.includes(excludeLine)) {
  throw new Error('starlight-llms-txt changed: update the stable-only llms-full compatibility patch');
}

await writeFile(path, patched, 'utf8');