|
| 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