-
-
Notifications
You must be signed in to change notification settings - Fork 803
Adds llms.txt to website
#9318
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
Adds llms.txt to website
#9318
Changes from all commits
Commits
Show all changes
3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| import { | ||
| getDocsConfig, | ||
| getAllDocPages, | ||
| type DocsProduct, | ||
| type DocsNavItem, | ||
| } from "./docs"; | ||
| import { getAllBlogPosts } from "./blog"; | ||
|
|
||
| const SITE_URL = "https://chillicream.com"; | ||
|
|
||
| function buildDocUrl( | ||
| product: DocsProduct, | ||
| versionPath: string, | ||
| itemPath: string | ||
| ): string { | ||
| const parts = ["/docs", product.path]; | ||
| if (versionPath) { | ||
| parts.push(versionPath); | ||
| } | ||
| if (itemPath && itemPath !== "index") { | ||
| parts.push(itemPath); | ||
| } | ||
| return parts.join("/"); | ||
| } | ||
|
|
||
| function flattenNavItems( | ||
| product: DocsProduct, | ||
| versionPath: string, | ||
| items: DocsNavItem[], | ||
| parentPath = "" | ||
| ): { url: string; title: string }[] { | ||
| const result: { url: string; title: string }[] = []; | ||
| for (const item of items) { | ||
| const itemPath = parentPath ? `${parentPath}/${item.path}` : item.path; | ||
| // Skip nested "index" sub-items — the parent already covers this URL | ||
| if (!(parentPath && item.path === "index")) { | ||
| result.push({ | ||
| url: buildDocUrl(product, versionPath, itemPath), | ||
| title: item.title, | ||
| }); | ||
| } | ||
| if (item.items) { | ||
| result.push( | ||
| ...flattenNavItems(product, versionPath, item.items, itemPath) | ||
| ); | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| function getLatestVersion(product: DocsProduct) { | ||
| if (product.latestStableVersion) { | ||
| return product.versions.find((v) => v.path === product.latestStableVersion); | ||
| } | ||
| return product.versions[0]; | ||
| } | ||
|
|
||
| const PRODUCT_DESCRIPTIONS: Record<string, string> = { | ||
| hotchocolate: "GraphQL server framework for .NET", | ||
| strawberryshake: "Type-safe GraphQL client for .NET", | ||
| fusion: "Distributed GraphQL gateway", | ||
| nitro: "GraphQL IDE and API management", | ||
| }; | ||
|
|
||
| export function generateLlmsTxt(): string { | ||
| const products = getDocsConfig(); | ||
| const blogPosts = getAllBlogPosts(); | ||
| const allPages = getAllDocPages({ skipGitMetadata: true }); | ||
| const validSlugs = new Set(allPages.map((p) => p.slug)); | ||
|
|
||
| const lines: string[] = [ | ||
| "# ChilliCream GraphQL Platform", | ||
| "", | ||
| "> The ChilliCream GraphQL Platform is an open-source ecosystem for building GraphQL APIs in .NET, including Hot Chocolate (server), Strawberry Shake (client), Green Donut (DataLoader), Fusion (distributed GraphQL), and Nitro (GraphQL IDE).", | ||
| "", | ||
| `For complete documentation in a single file, see [Full Documentation](${SITE_URL}/llms-full.txt)`, | ||
| "", | ||
| "## Documentation", | ||
| "", | ||
| ]; | ||
|
|
||
| // Product overview links | ||
| for (const product of products) { | ||
| const version = getLatestVersion(product); | ||
| const versionPath = version?.path ?? ""; | ||
| const url = buildDocUrl(product, versionPath, "index"); | ||
| const desc = PRODUCT_DESCRIPTIONS[product.path] || product.description; | ||
| lines.push(`- [${product.title}](${url}): ${desc}`); | ||
| } | ||
| lines.push(""); | ||
|
|
||
| // Per-product nav items | ||
| for (const product of products) { | ||
| const version = getLatestVersion(product); | ||
| if (!version) continue; | ||
|
|
||
| lines.push(`### ${product.title}`, ""); | ||
| const navItems = flattenNavItems(product, version.path, version.items); | ||
| for (const item of navItems) { | ||
| if (!validSlugs.has(item.url)) continue; | ||
| lines.push(`- [${item.title}](${item.url})`); | ||
| } | ||
| lines.push(""); | ||
| } | ||
|
|
||
| // Blog | ||
| lines.push("## Blog", ""); | ||
| const recentPosts = blogPosts.slice(0, 20); | ||
| for (const post of recentPosts) { | ||
| const desc = post.description ? `: ${post.description}` : ""; | ||
| lines.push(`- [${post.title}](${post.path})${desc}`); | ||
| } | ||
| lines.push(""); | ||
|
|
||
| return lines.join("\n"); | ||
| } | ||
|
|
||
| export function generateLlmsFullTxt(): string { | ||
| const products = getDocsConfig(); | ||
| const allPages = getAllDocPages({ skipGitMetadata: true }); | ||
|
|
||
| const lines: string[] = [ | ||
| "# ChilliCream GraphQL Platform - Full Documentation", | ||
| "", | ||
| "> The ChilliCream GraphQL Platform is an open-source ecosystem for building GraphQL APIs in .NET, including Hot Chocolate (server), Strawberry Shake (client), Green Donut (DataLoader), Fusion (distributed GraphQL), and Nitro (GraphQL IDE).", | ||
| "", | ||
| ]; | ||
|
|
||
| const pagesBySlug = new Map(allPages.map((p) => [p.slug, p])); | ||
|
|
||
| for (const product of products) { | ||
| const version = getLatestVersion(product); | ||
| if (!version) continue; | ||
|
|
||
| const versionPath = version.path; | ||
| const navItems = flattenNavItems(product, versionPath, version.items); | ||
|
|
||
| for (const navItem of navItems) { | ||
| const page = pagesBySlug.get(navItem.url); | ||
| if (!page || !page.content.trim()) continue; | ||
|
PascalSenn marked this conversation as resolved.
|
||
|
|
||
| lines.push(`## ${navItem.url}`, ""); | ||
| const title = page.frontmatter?.title || navItem.title; | ||
| lines.push(`# ${title}`, ""); | ||
| lines.push(page.content.trim(), ""); | ||
| lines.push("---", ""); | ||
| } | ||
| } | ||
|
|
||
| return lines.join("\n"); | ||
| } | ||
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,30 @@ | ||
| import fs from "fs"; | ||
| import path from "path"; | ||
| import { | ||
| generateLlmsTxt, | ||
| generateLlmsFullTxt, | ||
| } from "../lib/llms-txt-generator"; | ||
|
|
||
| const outDir = path.resolve(__dirname, "../out"); | ||
|
|
||
| if (!fs.existsSync(outDir)) { | ||
| console.error(`Output directory not found: ${outDir}`); | ||
| console.error("Run 'next build' first to generate the output directory."); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log("Generating llms.txt..."); | ||
| const llmsTxt = generateLlmsTxt(); | ||
| fs.writeFileSync(path.join(outDir, "llms.txt"), llmsTxt, "utf-8"); | ||
| console.log( | ||
| ` Written: out/llms.txt (${(llmsTxt.length / 1024).toFixed(1)} KB)` | ||
| ); | ||
|
|
||
| console.log("Generating llms-full.txt..."); | ||
| const llmsFullTxt = generateLlmsFullTxt(); | ||
| fs.writeFileSync(path.join(outDir, "llms-full.txt"), llmsFullTxt, "utf-8"); | ||
| console.log( | ||
| ` Written: out/llms-full.txt (${(llmsFullTxt.length / 1024).toFixed(1)} KB)` | ||
| ); | ||
|
|
||
| console.log("Done."); |
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.