-
Notifications
You must be signed in to change notification settings - Fork 13
chore: improve llms.txt for AI agents #715
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
10 commits
Select commit
Hold shift + click to select a range
b8c7d0e
chore: add response header
rsbh 80e69dd
chore: always append .mdx in llms.txt links
rsbh c6c40e4
feat: add script to generate tokens md file
rsbh 923ed3f
feat: add tokens.md file
rsbh 98d7aed
feat: add route to return tokens.md
rsbh 7ba4c61
chore: append tokens link to llms.txt
rsbh 3c57a2b
chore: update tokens.md format
rsbh 56fc369
chore: split the tokens file
rsbh 6922481
refactor: read CSS tokens directly in route instead of generating files
rsbh d9f5399
chore: add rewrite for /tokens/*.mdx public URLs
rsbh 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import { promises as fs } from 'fs'; | ||
| import { notFound } from 'next/navigation'; | ||
| import path from 'path'; | ||
|
|
||
| const STYLES_DIR = path.resolve( | ||
| process.cwd(), | ||
| '../../packages/raystack/styles' | ||
| ); | ||
rsbh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export const revalidate = false; | ||
|
|
||
| function stripVar(value: string) { | ||
| return value.replace(/var\((--[\w-]+)\)/g, '$1'); | ||
| } | ||
|
|
||
| function parseCSSFile(content: string) { | ||
| const sections: { | ||
| selector: string; | ||
| comment: string | null; | ||
| tokens: { name: string; value: string }[]; | ||
| }[] = []; | ||
| let currentSelector: string | null = null; | ||
| let currentComment: string | null = null; | ||
| let tokens: { name: string; value: string }[] = []; | ||
|
|
||
| for (const line of content.split('\n')) { | ||
| const trimmed = line.trim(); | ||
|
|
||
| const selectorMatch = trimmed.match(/^(:root|\[[\w-]+="[\w-]+"\])\s*\{/); | ||
| if (selectorMatch) { | ||
| currentSelector = selectorMatch[1]; | ||
| continue; | ||
| } | ||
|
|
||
| if (trimmed === '}') { | ||
| if (currentSelector && tokens.length) { | ||
| sections.push({ | ||
| selector: currentSelector, | ||
| comment: currentComment, | ||
| tokens: [...tokens] | ||
| }); | ||
| } | ||
| currentSelector = null; | ||
| tokens = []; | ||
| currentComment = null; | ||
| continue; | ||
| } | ||
|
|
||
| const commentMatch = trimmed.match(/^\/\*\s*(.+?)\s*\*\/$/); | ||
| if (commentMatch && currentSelector) { | ||
| if (tokens.length) { | ||
| sections.push({ | ||
| selector: currentSelector, | ||
| comment: currentComment, | ||
| tokens: [...tokens] | ||
| }); | ||
| tokens = []; | ||
| } | ||
| currentComment = commentMatch[1]; | ||
| if (currentComment.startsWith('Example usage:')) currentComment = null; | ||
| continue; | ||
| } | ||
|
|
||
| const varMatch = trimmed.match( | ||
| /^(--[\w-]+)\s*:\s*(.+?)\s*;(?:\s*\/\*\s*(.+?)\s*\*\/)?$/ | ||
| ); | ||
| if (varMatch && currentSelector) { | ||
| tokens.push({ name: varMatch[1], value: stripVar(varMatch[2]) }); | ||
| } | ||
| } | ||
|
|
||
| return sections; | ||
| } | ||
|
|
||
| function toMarkdown( | ||
| category: string, | ||
| sections: ReturnType<typeof parseCSSFile> | ||
| ) { | ||
| const title = category.charAt(0).toUpperCase() + category.slice(1); | ||
| let output = `# ${title} Tokens\n`; | ||
|
|
||
| for (const section of sections) { | ||
| const prefix = | ||
| section.selector === ':root' ? title : `${title} (${section.selector})`; | ||
| const heading = section.comment ? `${prefix} - ${section.comment}` : prefix; | ||
|
|
||
| output += `\n## ${heading}\n`; | ||
| for (const t of section.tokens) { | ||
| output += `${t.name}: ${t.value}\n`; | ||
| } | ||
| } | ||
|
|
||
| return output; | ||
| } | ||
|
|
||
| const CATEGORIES = ['colors', 'effects', 'radius', 'spacing', 'typography']; | ||
|
|
||
| export async function GET( | ||
| _req: Request, | ||
| { params }: { params: Promise<{ category: string }> } | ||
| ) { | ||
| const { category } = await params; | ||
|
|
||
| if (!CATEGORIES.includes(category)) notFound(); | ||
|
|
||
| const filePath = path.join(STYLES_DIR, `${category}.css`); | ||
| const exists = await fs.stat(filePath).then( | ||
| () => true, | ||
| () => false | ||
| ); | ||
| if (!exists) notFound(); | ||
|
|
||
| const content = await fs.readFile(filePath, 'utf-8'); | ||
|
|
||
| const sections = parseCSSFile(content); | ||
| return new Response(toMarkdown(category, sections), { | ||
| headers: { 'Content-Type': 'text/markdown' } | ||
| }); | ||
| } | ||
|
|
||
| export function generateStaticParams() { | ||
| return CATEGORIES.map(category => ({ category })); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.