Skip to content

Commit 2dccb0d

Browse files
authored
Merge pull request #12 from hinter-net/llms.txt
Create llms.txt and llms.txt-full during build based on the sidebar
2 parents 2058261 + afccb36 commit 2dccb0d

File tree

4 files changed

+91
-2
lines changed

4 files changed

+91
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# Generated files
88
.docusaurus
99
.cache-loader
10+
/static/llms.txt
11+
/static/llms-full.txt
1012

1113
# Misc
1214
.DS_Store

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# Generated files
88
.docusaurus
99
.cache-loader
10+
/static/llms.txt
11+
/static/llms-full.txt
1012

1113
# Misc
1214
.DS_Store

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
"version": "0.0.0",
44
"private": true,
55
"scripts": {
6-
"build": "docusaurus build",
6+
"build": "npm run build:llms && npm run build:docusaurus",
7+
"build:docusaurus": "docusaurus build",
8+
"build:llms": "node scripts/create-llms-files.js",
79
"deploy": "docusaurus deploy",
810
"prettier": "prettier --write \"./**/*.md\"",
911
"prettier:check": "prettier --check \"./**/*.md\"",
10-
"start": "docusaurus start"
12+
"start": "npm run build:llms && docusaurus start"
1113
},
1214
"dependencies": {
1315
"@docusaurus/core": "3.8.1",

scripts/create-llms-files.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const sidebars = require('../sidebars.js').default;
4+
5+
const docsDir = path.join(__dirname, '..', 'docs');
6+
const staticDir = path.join(__dirname, '..', 'static');
7+
const llmsTxtPath = path.join(staticDir, 'llms.txt');
8+
const llmsFullTxtPath = path.join(staticDir, 'llms-full.txt');
9+
10+
function getMarkdownFiles(items) {
11+
let files = [];
12+
for (const item of items) {
13+
if (typeof item === 'string') {
14+
files.push(item);
15+
} else if (item.type === 'category') {
16+
files = files.concat(getMarkdownFiles(item.items));
17+
}
18+
}
19+
return files;
20+
}
21+
22+
function generateLlmsTxt() {
23+
let content = '# Hinter Net\n\n';
24+
content += `> Hinter Net is a peer-to-peer network for collaborative intelligence. It combines a secure, decentralized communication protocol (hinter-core) with a powerful, AI-assisted command center (hinter-cline) to help users build high-trust, private networks for sharing and contextualizing sensitive information.\n\n`;
25+
26+
const order = ['hinterNet', 'hinterCore', 'hinterCline'];
27+
28+
for (const key of order) {
29+
const sidebar = sidebars[key];
30+
if (sidebar) {
31+
const category = sidebar.find(item => item.type === 'category');
32+
if (category) {
33+
content += `## ${category.label}\n\n`;
34+
const files = getMarkdownFiles(category.items);
35+
for (const file of files) {
36+
const filePath = path.join(docsDir, `${file}.md`);
37+
if (fs.existsSync(filePath)) {
38+
const fileContent = fs.readFileSync(filePath, 'utf-8');
39+
const match = fileContent.match(/---\s*sidebar_label:\s*"(.*?)"\s*---/);
40+
const title = match ? match[1] : path.basename(file, '.md');
41+
content += `- [${title}](/docs/${file}.md)\n`;
42+
}
43+
}
44+
content += '\n';
45+
}
46+
}
47+
}
48+
49+
fs.writeFileSync(llmsTxtPath, content);
50+
console.log(`Successfully created ${llmsTxtPath}`);
51+
}
52+
53+
function generateLlmsFullTxt() {
54+
const llmsTxtContent = fs.readFileSync(llmsTxtPath, 'utf-8');
55+
const links = llmsTxtContent.match(/- \[(.*?)\]\((.*?)\)/g);
56+
let fullContent = '';
57+
58+
if (links) {
59+
for (const link of links) {
60+
const match = link.match(/- \[(.*?)\]\((.*?)\)/);
61+
if (match) {
62+
const url = match[2];
63+
const filePath = path.join(__dirname, '..', url.substring(1));
64+
if (fs.existsSync(filePath)) {
65+
fullContent += fs.readFileSync(filePath, 'utf-8') + '\n\n';
66+
}
67+
}
68+
}
69+
}
70+
71+
fs.writeFileSync(llmsFullTxtPath, fullContent);
72+
console.log(`Successfully created ${llmsFullTxtPath}`);
73+
}
74+
75+
try {
76+
if (!fs.existsSync(staticDir)) {
77+
fs.mkdirSync(staticDir, { recursive: true });
78+
}
79+
generateLlmsTxt();
80+
generateLlmsFullTxt();
81+
} catch (err) {
82+
console.error('Error creating llms files:', err);
83+
}

0 commit comments

Comments
 (0)