Skip to content

Commit 358b65b

Browse files
feat: add llms capture and export functionality for llmstxt standard
feat: enhance description handling and markdown export fix: remove llms-capture plugin and update markdown processing feat: llms capture and processing enhancements for md export feat: enhance markdown processing fix: docusaurus build feat: type definitions for llms-export plugin feat: normalized sidebar item types and markdown file generation feat: implement URL conversion to .md format for llms links refactor: streamline llms plugin code and enhance markdown processing refactor: enhance type definitions and improve markdown processing in llms plugin
1 parent 95e2365 commit 358b65b

File tree

9 files changed

+2318
-1
lines changed

9 files changed

+2318
-1
lines changed

docusaurus.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import type * as Preset from '@docusaurus/preset-classic';
55
import {editLinkUrl as editUrlFunction} from './src/editUrl';
66
import crossRepoLinksPlugin from './src/remark/cross-repo-links';
77
import {plugin as codeBlockSnippetsPlugin} from './src/remark/code-block-snippets';
8+
import llmsCapture from './src/remark/llms-capture';
9+
import llmsPlugin from './src/plugins/llms';
810
import {redirectsOptions} from './redirects';
911

12+
const siteDir = __dirname;
13+
1014
const config: Config = {
1115
title: 'Oasis Documentation',
1216
tagline: '',
@@ -46,6 +50,7 @@ const config: Config = {
4650
converters:['pnpm','yarn'], // Package managers to use.
4751
},
4852
],
53+
[llmsCapture, {siteDir}],
4954
],
5055
routeBasePath: '/',
5156
showLastUpdateTime: true,
@@ -89,6 +94,7 @@ const config: Config = {
8994
}
9095
};
9196
},
97+
llmsPlugin,
9298
[
9399
'@docusaurus/plugin-client-redirects',
94100
redirectsOptions,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"scripts": {
66
"docusaurus": "docusaurus",
77
"start": "docusaurus start --no-open",
8-
"build": "docusaurus build",
8+
"build": "docusaurus clear && docusaurus build",
99
"mermaid:theme": "CSS_STRING=$(tr -s ' ' < mermaid-theme.css | tr -d '\n') && jq --arg themeCSS \"$CSS_STRING\" '.themeCSS = $themeCSS' mermaid.config.json > mermaid.config.json.temp && mv mermaid.config.json.temp mermaid.config.json",
1010
"diagrams": "yarn mermaid:theme && find -L docs -name '*.mmd' -exec mmdc -i {} -p puppeteer-config.json -c mermaid.config.json --backgroundColor transparent ';'",
1111
"swizzle": "docusaurus swizzle",

src/plugins/llms/capture.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import * as crypto from 'crypto';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
4+
5+
import type {MdastNode} from './types';
6+
7+
export const CAPTURE_TREE_VERSION = 1;
8+
9+
function hash(value: string) {
10+
return crypto.createHash('sha1').update(value).digest('hex');
11+
}
12+
13+
export function captureDirForSite(siteDir: string) {
14+
return path.join(siteDir, '.docusaurus', 'llms-export', 'trees');
15+
}
16+
17+
export function capturedTreePathForSource(
18+
sourceAbsPath: string,
19+
siteDir: string,
20+
) {
21+
let abs = sourceAbsPath;
22+
try {
23+
abs = fs.realpathSync(sourceAbsPath);
24+
} catch {
25+
abs = path.resolve(sourceAbsPath);
26+
}
27+
return path.join(captureDirForSite(siteDir), `${hash(abs)}.json`);
28+
}
29+
30+
export function wrapCapturedTree(tree: unknown) {
31+
return {version: CAPTURE_TREE_VERSION, tree};
32+
}
33+
34+
export function unwrapCapturedTree(payload: unknown): MdastNode | null {
35+
if (!payload || typeof payload !== 'object') return null;
36+
37+
const record = payload as Record<string, unknown>;
38+
if ('version' in record && 'tree' in record) {
39+
const version = Number(record.version);
40+
if (version !== CAPTURE_TREE_VERSION) return null;
41+
return (record.tree as MdastNode) ?? null;
42+
}
43+
44+
// Legacy format support (version 1 only)
45+
return CAPTURE_TREE_VERSION === 1 ? (payload as MdastNode) : null;
46+
}

0 commit comments

Comments
 (0)