-
Notifications
You must be signed in to change notification settings - Fork 2.1k
docs: rework llms.txt and add .md responses #10811
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 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e1d7ec1
docs: rework llms.txt and add .md responses
anthonyshew 5fd64ce
WIP 37607
anthonyshew cda2c59
WIP d0c48
anthonyshew d330a66
WIP 01bf2
anthonyshew 01c70cd
WIP ad4df
anthonyshew 9e5dbbd
WIP 85cab
anthonyshew dc16753
Update docs/site/app/llms-full.txt/route.ts
anthonyshew 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import * as fs from "node:fs/promises"; | ||
| import fg from "fast-glob"; | ||
| import matter from "gray-matter"; | ||
| import { remark } from "remark"; | ||
| import remarkStringify from "remark-stringify"; | ||
| import remarkMdx from "remark-mdx"; | ||
|
|
||
| export const DEFAULT_IGNORED_FILES = [ | ||
| "!./content/docs/acknowledgments.mdx", | ||
| "!./content/docs/community.mdx", | ||
| "!./content/docs/telemetry.mdx", | ||
| ]; | ||
|
|
||
| export async function scanDocumentationFiles( | ||
| patterns: Array<string> = ["./content/docs/**/*.mdx"], | ||
| ignorePatterns: Array<string> = DEFAULT_IGNORED_FILES | ||
| ) { | ||
| return fg([...patterns, ...ignorePatterns]); | ||
| } | ||
|
|
||
| export async function parseFileContent(filePath: string) { | ||
| const fileContent = await fs.readFile(filePath); | ||
| return matter(fileContent.toString()); | ||
| } | ||
|
|
||
| export async function processMarkdownContent(content: string): Promise<string> { | ||
| const file = await remark() | ||
| .use(remarkMdx) | ||
| .use(remarkStringify) | ||
| .process(content); | ||
|
|
||
| return String(file); | ||
| } | ||
|
|
||
| export function formatFilePath(filePath: string): string { | ||
| return filePath.replace("./content/docs", "").replace(/\.mdx$/, ".md"); | ||
| } |
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,28 @@ | ||
| // This file is mostly a copy-paste from https://fumadocs.vercel.app/docs/ui/llms. | ||
|
|
||
| import { | ||
| scanDocumentationFiles, | ||
| parseFileContent, | ||
| processMarkdownContent, | ||
| formatFilePath, | ||
| } from "../lib/llms-utils"; | ||
|
|
||
| export const revalidate = false; | ||
|
|
||
| export async function GET(): Promise<Response> { | ||
| // all scanned content | ||
| const files = await scanDocumentationFiles(); | ||
|
|
||
| const scan = files.map(async (file) => { | ||
| const { content, data } = await parseFileContent(file); | ||
|
|
||
| const processed = await processMarkdownContent(content); | ||
| return `- [${data.title}](${formatFilePath(file)}): ${data.description} | ||
|
|
||
| ${processed}`; | ||
| }); | ||
|
|
||
| const scanned = await Promise.all(scan); | ||
|
|
||
| return new Response(scanned.join("\n\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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| // This file is mostly a copy-paste from https://fumadocs.vercel.app/docs/ui/llms. | ||
|
|
||
| import { notFound } from "next/navigation"; | ||
| import { type NextRequest } from "next/server"; | ||
| import { repoDocsPages } from "../../source"; | ||
| import { parseFileContent, processMarkdownContent } from "../../lib/llms-utils"; | ||
|
|
||
| export const revalidate = false; | ||
|
|
||
| export async function GET( | ||
| _req: NextRequest, | ||
| { params }: { params: Promise<{ slug?: Array<string> }> } | ||
| ) { | ||
| const { slug } = await params; | ||
| const page = repoDocsPages.getPage(slug); | ||
| if (!page) notFound(); | ||
|
|
||
| const { data, content } = await parseFileContent( | ||
| page.data._file.absolutePath | ||
| ); | ||
| const txt = await processMarkdownContent(content); | ||
|
|
||
| const header = `# ${data.title} | ||
| Description: ${data.description} | ||
|
|
||
| `; | ||
|
|
||
| return new Response(header.concat(txt)); | ||
| } | ||
|
|
||
| export function generateStaticParams() { | ||
| return repoDocsPages.generateParams(); | ||
| } |
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 |
|---|---|---|
| @@ -1,44 +1,38 @@ | ||
| // This file is mostly a copy-paste from https://fumadocs.vercel.app/docs/ui/llms. | ||
|
|
||
| import * as fs from "node:fs/promises"; | ||
| import fg from "fast-glob"; | ||
| import matter from "gray-matter"; | ||
| import { remark } from "remark"; | ||
| import remarkStringify from "remark-stringify"; | ||
| import remarkMdx from "remark-mdx"; | ||
| import { | ||
| scanDocumentationFiles, | ||
| parseFileContent, | ||
| formatFilePath, | ||
| } from "../lib/llms-utils"; | ||
| import { PRODUCT_SLOGANS } from "../../lib/constants"; | ||
|
|
||
| export const revalidate = false; | ||
|
|
||
| export async function GET(): Promise<Response> { | ||
| // all scanned content | ||
| const files = await fg([ | ||
| "./content/docs/**/*.mdx", | ||
| "!./content/docs/acknowledgments.mdx", | ||
| "!./content/docs/community.mdx", | ||
| "!./content/docs/telemetry.mdx", | ||
| ]); | ||
|
|
||
| const scan = files.map(async (file) => { | ||
| const fileContent = await fs.readFile(file); | ||
| const { content, data } = matter(fileContent.toString()); | ||
|
|
||
| const processed = await processContent(content); | ||
| return `file: ${file} | ||
| meta: ${JSON.stringify(data, null, 2)} | ||
|
|
||
| ${processed}`; | ||
| const files = await scanDocumentationFiles(); | ||
|
|
||
| const scan = files.sort().map(async (file) => { | ||
| const { data } = await parseFileContent(file); | ||
|
|
||
| return `- [${data.title}](${formatFilePath(file)}): ${data.description}`; | ||
| }); | ||
|
|
||
| const scanned = await Promise.all(scan); | ||
|
|
||
| return new Response(scanned.join("\n\n")); | ||
| } | ||
| const header = ` | ||
| # Turborepo documentation | ||
|
|
||
| Generated at: ${new Date().toUTCString()} | ||
|
|
||
| ## Turborepo | ||
|
|
||
| > ${PRODUCT_SLOGANS.turbo} | ||
|
|
||
| ## Docs | ||
|
|
||
| async function processContent(content: string): Promise<string> { | ||
| const file = await remark() | ||
| .use(remarkMdx) | ||
| .use(remarkStringify) | ||
| .process(content); | ||
| `; | ||
|
|
||
| return String(file); | ||
| return new Response(header.concat(scanned.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
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.