-
Notifications
You must be signed in to change notification settings - Fork 4
Add script for generating llms.txt and llms-full.txt #222
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
05a6da8
Add script for generating llms.txt and llms-full.txt
bbenligiray a54c808
Use the title instead of the filename to identify links
bbenligiray 84b65ce
Don't validate llms links
bbenligiray 5f45d56
Force .html extension on llms.txt links
bbenligiray 7a91fe2
Declare the pageheader string pattern as a variable
bbenligiray 4fc15bd
Add page headers to header text as a clue in llms-full.txt
bbenligiray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
| const dappsSidebar = require('../docs/dapps/sidebar.js'); | ||
| const oevSearchersSidebar = require('../docs/oev-searchers/sidebar.js'); | ||
|
|
||
| const docsDir = path.join(__dirname, '..', 'docs'); | ||
| const staticDir = path.join(__dirname, '..', 'docs', 'public'); | ||
| const llmsTxtPath = path.join(staticDir, 'llms.txt'); | ||
| const llmsFullTxtPath = path.join(staticDir, 'llms-full.txt'); | ||
|
|
||
| function getMarkdownFiles(items) { | ||
| let files = []; | ||
| for (const item of items) { | ||
| if (item.link) { | ||
| files.push(item.link); | ||
| } | ||
| if (item.items) { | ||
| files = files.concat(getMarkdownFiles(item.items)); | ||
| } | ||
| } | ||
| return files; | ||
| } | ||
|
|
||
| function generateLlmsTxt() { | ||
| let content = '# Api3 Docs\n\n'; | ||
| content += `> Api3 Docs helps developers build dApps using Api3 data feeds and searchers recapture oracle extractable value (OEV).\n\n`; | ||
|
|
||
| const sidebars = { | ||
| dapps: dappsSidebar, | ||
| 'oev-searchers': oevSearchersSidebar, | ||
| }; | ||
|
|
||
| for (const key in sidebars) { | ||
| const sidebar = sidebars[key]; | ||
| if (sidebar) { | ||
| content += `## ${key}\n\n`; | ||
| const files = getMarkdownFiles(sidebar); | ||
| for (const file of files) { | ||
| const filePath = path.join(docsDir, `${file}.md`); | ||
| if (fs.existsSync(filePath)) { | ||
| const fileContent = fs.readFileSync(filePath, 'utf-8'); | ||
| const lines = fileContent.split('\n'); | ||
| let title = path.basename(file, '.md'); | ||
| for (const line of lines) { | ||
| if (line.startsWith('title: ')) { | ||
| title = line.substring('title: '.length); | ||
| break; | ||
| } | ||
| } | ||
| const url = `https://docs.api3.org${file}`; | ||
| content += `- [${title}](${url.replace(/\/$/, '/index')}.html)\n`; | ||
| } else { | ||
| const indexPath = path.join(docsDir, file, 'index.md'); | ||
| if (fs.existsSync(indexPath)) { | ||
| const fileContent = fs.readFileSync(indexPath, 'utf-8'); | ||
| const lines = fileContent.split('\n'); | ||
| let title = path.basename(file); | ||
| for (const line of lines) { | ||
| if (line.startsWith('title: ')) { | ||
| title = line.substring('title: '.length); | ||
| break; | ||
| } | ||
| } | ||
| const url = `https://docs.api3.org${file}`; | ||
| content += `- [${title}](${url.replace(/\/$/, '/index.html')})\n`; | ||
| } | ||
| } | ||
| } | ||
| content += '\n'; | ||
| } | ||
| } | ||
|
|
||
| fs.writeFileSync(llmsTxtPath, content); | ||
| console.log(`Successfully created ${llmsTxtPath}`); | ||
| } | ||
|
|
||
| function generateLlmsFullTxt() { | ||
| const llmsTxtContent = fs.readFileSync(llmsTxtPath, 'utf-8'); | ||
| const links = llmsTxtContent.match(/- \[(.*?)\]\((.*?)\)/g); | ||
| let fullContent = ''; | ||
| const pageHeader = '<PageHeader/>\n\n'; | ||
|
|
||
| if (links) { | ||
| for (const link of links) { | ||
| const match = link.match(/- \[(.*?)\]\((.*?)\)/); | ||
| if (match) { | ||
| const url = match[2] | ||
| .replace('https://docs.api3.org', '') | ||
| .replace('.html', '.md'); | ||
| const filePath = path.join(docsDir, url); | ||
| if (fs.existsSync(filePath)) { | ||
| let fileContent = fs.readFileSync(filePath, 'utf-8'); | ||
| const lines = fileContent.split('\n'); | ||
| let pageHeaderValue = ''; | ||
| for (const line of lines) { | ||
| if (line.startsWith('pageHeader: ')) { | ||
| pageHeaderValue = line.substring('pageHeader: '.length); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| const pageHeaderIndex = fileContent.indexOf(pageHeader); | ||
| if (pageHeaderIndex === -1) { | ||
| throw new Error(`Could not find PageHeader in ${filePath}`); | ||
| } | ||
| fileContent = fileContent.substring( | ||
| pageHeaderIndex + pageHeader.length | ||
| ); | ||
| const titleMatch = fileContent.match(/# (.*)/); | ||
| if (titleMatch && pageHeaderValue) { | ||
| fileContent = fileContent.replace( | ||
| /# (.*)/, | ||
| `# ${titleMatch[1]} (${pageHeaderValue})` | ||
| ); | ||
| } | ||
| fullContent += fileContent + '\n\n'; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fs.writeFileSync(llmsFullTxtPath, fullContent); | ||
| console.log(`Successfully created ${llmsFullTxtPath}`); | ||
| } | ||
|
|
||
| function main() { | ||
| try { | ||
| if (!fs.existsSync(staticDir)) { | ||
| fs.mkdirSync(staticDir, { recursive: true }); | ||
| } | ||
| generateLlmsTxt(); | ||
| generateLlmsFullTxt(); | ||
| } catch (err) { | ||
| console.error('Error creating llms files:', err); | ||
| process.exit(1); | ||
| } | ||
| } | ||
|
|
||
| main(); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that the links in the hinter net docs weren't full