Skip to content

Commit 7a5aab1

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 refactor: improve type definitions and enhance error handling feat: enhance with optional sidebars and flat document generation feat: introduce visibility check for documents and streamline description refactor: simplify llms generator feat: add llms-full txt link in llmstxt refactor: streamline line generation and remove unused function feat: enhance markdown processing feat: enhance markdown URL handling for README files
1 parent 16df72f commit 7a5aab1

File tree

8 files changed

+2409
-0
lines changed

8 files changed

+2409
-0
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,

src/plugins/llms/capture.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 hashString(value: string): string {
10+
return crypto.createHash('sha1').update(value).digest('hex');
11+
}
12+
13+
export function captureDirForSite(siteDir: string): string {
14+
return path.join(siteDir, '.docusaurus', 'llms-export', 'trees');
15+
}
16+
17+
export function capturedTreePathForSource(
18+
sourceAbsPath: string,
19+
siteDir: string,
20+
): string {
21+
let absolutePath: string;
22+
try {
23+
absolutePath = fs.realpathSync(sourceAbsPath);
24+
} catch {
25+
absolutePath = path.resolve(sourceAbsPath);
26+
}
27+
return path.join(
28+
captureDirForSite(siteDir),
29+
`${hashString(absolutePath)}.json`,
30+
);
31+
}
32+
33+
export function wrapCapturedTree(tree: unknown): {
34+
version: number;
35+
tree: unknown;
36+
} {
37+
return {version: CAPTURE_TREE_VERSION, tree};
38+
}
39+
40+
export function unwrapCapturedTree(payload: unknown): MdastNode | null {
41+
if (!payload || typeof payload !== 'object') return null;
42+
43+
const record = payload as Record<string, unknown>;
44+
45+
// Handle versioned format
46+
if ('version' in record && 'tree' in record) {
47+
const version = Number(record.version);
48+
if (version !== CAPTURE_TREE_VERSION) return null;
49+
return (record.tree as MdastNode) ?? null;
50+
}
51+
52+
// Legacy format support (version 1 only)
53+
if (CAPTURE_TREE_VERSION === 1) {
54+
return payload as MdastNode;
55+
}
56+
57+
return null;
58+
}

0 commit comments

Comments
 (0)