Skip to content

feat: 文档生成 llms-full.txt #12989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@ant-design/icons-svg": "^4.2.1",
"front-matter": "^4.0.2",
"react-countup": "^6.4.2"
},
"devDependencies": {
Expand Down
10 changes: 9 additions & 1 deletion docs/scripts/generateLLms.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import frontMatter from 'front-matter';
import 'zx/globals';

async function generateLLms() {
Expand All @@ -8,21 +9,24 @@ async function generateLLms() {
let docs = await glob('**/*.md', { cwd: docsDir });

let docsIndex: Array<{ title: string; url: string }> = [];
let docsBody: string[] = [];

for (let markdown of docs) {
const mdPath = path.join(docsDir, markdown);
const isEnUS = mdPath.includes('en-US');

if (!isEnUS) {
const mdContent = fs.readFileSync(mdPath, 'utf-8');
const { body } = frontMatter(mdContent);
const mdName = markdown.replace(/\.md$/, '');
const matchedtitles = mdContent.match(/^# (.+)$/m);
const title = matchedtitles ? matchedtitles[1] : mdName;

docsIndex.push({
title: `UmiJS - ${title}`,
title,
url: `https://umijs.org/${mdName}`,
});
docsBody.push(body);
}
}
const docsIndexContent = [
Expand All @@ -36,7 +40,11 @@ async function generateLLms() {
'',
].join('\n');

const docsBodyContent = docsBody.join('\n');

fs.writeFileSync(path.join(llmsDir, 'dist/llms.txt'), docsIndexContent);
fs.writeFileSync(path.join(llmsDir, 'dist/llms-full.txt'), docsBodyContent);

console.log('Generated llms.txt');
}
(async () => {
Expand Down
Loading
Loading