-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add llms.txt with Mapbox/MapLibre split #2593
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
Open
tordans
wants to merge
2
commits into
visgl:master
Choose a base branch
from
tordans:llm-txt
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+293
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const SITE_URL = 'https://visgl.github.io/react-map-gl'; | ||
| const BUILD_DIR = path.join(__dirname, '../build'); | ||
| const REPO_ROOT = path.join(__dirname, '../..'); | ||
| const EXAMPLES_TOC = path.join(__dirname, '../src/examples/table-of-contents.json'); | ||
|
|
||
| function getExampleIdsByStack(toc) { | ||
| const stacks = {mapbox: [], maplibre: []}; | ||
|
|
||
| for (const entry of toc) { | ||
| if (entry.type !== 'category') { | ||
| continue; | ||
| } | ||
| const label = entry.label.toLowerCase(); | ||
| if (label === 'mapbox') { | ||
| stacks.mapbox = entry.items; | ||
| } else if (label === 'maplibre') { | ||
| stacks.maplibre = entry.items; | ||
| } | ||
| } | ||
|
|
||
| return stacks; | ||
| } | ||
|
|
||
| function readTitle(exampleId) { | ||
| const mdxPath = path.join(__dirname, '../src/examples', `${exampleId}.mdx`); | ||
| if (fs.existsSync(mdxPath)) { | ||
| const firstLine = fs.readFileSync(mdxPath, 'utf8').split('\n')[0]; | ||
| const match = firstLine.match(/^#\s+(.+)$/); | ||
| if (match) { | ||
| return match[1].trim(); | ||
| } | ||
| } | ||
|
|
||
| const readmePath = path.join(REPO_ROOT, 'examples', exampleId, 'README.md'); | ||
| if (fs.existsSync(readmePath)) { | ||
| const firstLine = fs.readFileSync(readmePath, 'utf8').split('\n')[0]; | ||
| const match = firstLine.match(/^#\s+Example:\s*(.+)$/); | ||
| if (match) { | ||
| return match[1].trim(); | ||
| } | ||
| } | ||
|
|
||
| const slug = exampleId.split('/').pop(); | ||
| return slug | ||
| .split('-') | ||
| .map(word => word.charAt(0).toUpperCase() + word.slice(1)) | ||
| .join(' '); | ||
| } | ||
|
|
||
| function readBlurb(exampleId) { | ||
| const readmePath = path.join(REPO_ROOT, 'examples', exampleId, 'README.md'); | ||
| if (!fs.existsSync(readmePath)) { | ||
| return null; | ||
| } | ||
|
|
||
| const content = fs.readFileSync(readmePath, 'utf8'); | ||
| const showcaseMatch = content.match(/This example showcases how to ([^\n.]+(?:\.[^\n.]+)*)\./i); | ||
| if (showcaseMatch) { | ||
| return showcaseMatch[1].trim().replace(/\.$/, ''); | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| function readReadmeIntro(exampleId) { | ||
| const readmePath = path.join(REPO_ROOT, 'examples', exampleId, 'README.md'); | ||
| if (!fs.existsSync(readmePath)) { | ||
| return null; | ||
| } | ||
|
|
||
| const lines = fs.readFileSync(readmePath, 'utf8').split('\n'); | ||
| const intro = []; | ||
|
|
||
| for (let i = 1; i < lines.length; i++) { | ||
| const line = lines[i].trim(); | ||
| if (line.startsWith('## Usage')) { | ||
| break; | ||
| } | ||
| if (line) { | ||
| intro.push(line); | ||
| } | ||
| } | ||
|
|
||
| return intro.join('\n').trim() || null; | ||
| } | ||
|
|
||
| function buildExampleLinks(exampleIds) { | ||
| return exampleIds.map(exampleId => { | ||
| const title = readTitle(exampleId); | ||
| const blurb = readBlurb(exampleId); | ||
| const url = `${SITE_URL}/examples/${exampleId}`; | ||
| const description = blurb ? `: ${blurb}` : ''; | ||
| return `- [${title}](${url})${description}`; | ||
| }); | ||
| } | ||
|
|
||
| function buildExampleSections(exampleIds) { | ||
| const sections = []; | ||
|
|
||
| for (const exampleId of exampleIds) { | ||
| const title = readTitle(exampleId); | ||
| const url = `${SITE_URL}/examples/${exampleId}`; | ||
| const intro = readReadmeIntro(exampleId); | ||
| const blurb = readBlurb(exampleId); | ||
|
|
||
| sections.push(`### ${title}\n\n[View example](${url})`); | ||
| if (intro) { | ||
| sections.push(`\n${intro}`); | ||
| } else if (blurb) { | ||
| sections.push(`\nThis example showcases how to ${blurb}.`); | ||
| } | ||
| sections.push(''); | ||
| } | ||
|
|
||
| return sections.join('\n'); | ||
| } | ||
|
|
||
| function appendSection(filePath, section) { | ||
| if (!fs.existsSync(filePath)) { | ||
| console.warn(`Skipping ${path.basename(filePath)} — file not found`); | ||
| return; | ||
| } | ||
|
|
||
| const content = fs.readFileSync(filePath, 'utf8').trimEnd(); | ||
| fs.writeFileSync(filePath, `${content}\n\n${section}\n`); | ||
| } | ||
|
|
||
| function fixDocUrls(content) { | ||
| return content | ||
| .replace( | ||
| /https:\/\/visgl\.github\.io\/docs\/\.\.\/docs\/README\.md/g, | ||
| `${SITE_URL}/docs` | ||
| ) | ||
| .replace( | ||
| /https:\/\/visgl\.github\.io\/react-map-gl\/docs\/get-started\/get-started\.md/g, | ||
| `${SITE_URL}/docs/get-started.md` | ||
| ); | ||
| } | ||
|
|
||
| function fixUrlsInLlmsFiles() { | ||
| const llmsFiles = fs | ||
| .readdirSync(BUILD_DIR) | ||
| .filter(name => name.startsWith('llms') && name.endsWith('.txt')) | ||
| .map(name => path.join(BUILD_DIR, name)); | ||
|
|
||
| for (const filePath of llmsFiles) { | ||
| const fixed = fixDocUrls(fs.readFileSync(filePath, 'utf8')); | ||
| fs.writeFileSync(filePath, fixed); | ||
| } | ||
| } | ||
|
|
||
| function main() { | ||
| const toc = JSON.parse(fs.readFileSync(EXAMPLES_TOC, 'utf8')); | ||
| const stacks = getExampleIdsByStack(toc); | ||
|
|
||
| for (const [stack, exampleIds] of Object.entries(stacks)) { | ||
| if (exampleIds.length === 0) { | ||
| continue; | ||
| } | ||
|
|
||
| const linksSection = `## Examples\n\n${buildExampleLinks(exampleIds).join('\n')}`; | ||
| appendSection(path.join(BUILD_DIR, `llms-${stack}.txt`), linksSection); | ||
|
|
||
| const fullSection = `## Examples\n\n${buildExampleSections(exampleIds)}`; | ||
| appendSection(path.join(BUILD_DIR, `llms-${stack}-full.txt`), fullSection); | ||
|
|
||
| console.log(`Appended ${exampleIds.length} ${stack} examples to llms-${stack}.txt`); | ||
| } | ||
|
|
||
| fixUrlsInLlmsFiles(); | ||
| console.log('Fixed doc URLs in generated llms files'); | ||
| } | ||
|
|
||
| main(); |
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
Oops, something went wrong.
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.
Index links point to missing markdown
Medium Severity
generateMarkdownFilesis set tofalse, butdocusaurus-plugin-llmsv0.4.0 still appends.mdto doc links in the generated index files. Those URLs do not exist in the static build (live pages are HTML paths without.md), so agents followingllms.txt/llms-mapbox.txt/llms-maplibre.txtlinks get 404s unless they only use the full-content bundles.Reviewed by Cursor Bugbot for commit 13514f5. Configure here.
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.
This seems to be true - the index links end in .md, while the deployed Docusaurus routes generally do not.