-
Notifications
You must be signed in to change notification settings - Fork 51
feat(docs): expand ComponentGrid in llms.txt output #1509
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
6ed8858
feat(docs): expand ComponentGrid in llms.txt output
SeieunYoo 8035644
fix(docs): address ComponentGrid rule review feedback
SeieunYoo cbab001
refactor(docs): use getLLMMarkdownUrl helper in ComponentGrid rule
SeieunYoo 56a8094
Merge remote-tracking branch 'origin/dev' into joy-yoo_karrot/llms-do…
SeieunYoo 0cb61b8
refactor(docs): use gray-matter in ComponentGrid rule
SeieunYoo 10f2b41
fix(docs): warn when ComponentGrid components directory is missing
SeieunYoo e371456
fix(docs): warn when ComponentGrid transform falls back
SeieunYoo 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,8 @@ | ||
| ## Buttons | ||
|
|
||
| - [Action Button](https://example.com/llms/docs/components/action-button.txt) — 기본 인터랙션 컴포넌트입니다. | ||
| - [Floating Action Button](https://example.com/llms/docs/components/floating-action-button.txt) | ||
|
|
||
| ## Controls | ||
|
|
||
| - [Checkbox](https://example.com/llms/docs/components/checkbox.txt) — 옵션 선택 컴포넌트입니다. |
1 change: 1 addition & 0 deletions
1
docs/app/_llms/__fixtures__/component-grid/passthrough.input.mdx
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 @@ | ||
| <SomethingElse /> |
1 change: 1 addition & 0 deletions
1
docs/app/_llms/__fixtures__/component-grid/passthrough.output.mdx
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 @@ | ||
| <SomethingElse /> |
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,44 @@ | ||
| import { describe, expect, it } from "bun:test"; | ||
| import { normalizeLLMBodyWithRules } from "../normalize-llm-body"; | ||
| import { normalizeForAssert, readFixture } from "../test-utils"; | ||
| import { buildMarkdown, componentGridRule, type ComponentEntry } from "./component-grid-rule"; | ||
|
|
||
| const sampleEntries: ComponentEntry[] = [ | ||
| { | ||
| category: "Controls", | ||
| title: "Checkbox", | ||
| description: "옵션 선택 컴포넌트입니다.", | ||
| url: "https://example.com/llms/docs/components/checkbox.txt", | ||
| }, | ||
| { | ||
| category: "Buttons", | ||
| title: "Floating Action Button", | ||
| description: "", | ||
| url: "https://example.com/llms/docs/components/floating-action-button.txt", | ||
| }, | ||
| { | ||
| category: "Buttons", | ||
| title: "Action Button", | ||
| description: "기본 인터랙션 컴포넌트입니다.", | ||
| url: "https://example.com/llms/docs/components/action-button.txt", | ||
| }, | ||
| ]; | ||
|
|
||
| describe("componentGridRule", () => { | ||
| it("renders categorized markdown from entries", () => { | ||
| const expected = readFixture("component-grid", "basic.output.md"); | ||
|
|
||
| const actual = buildMarkdown(sampleEntries); | ||
|
|
||
| expect(normalizeForAssert(actual)).toBe(normalizeForAssert(expected)); | ||
| }); | ||
|
|
||
| it("non-target node passthrough", () => { | ||
| const input = readFixture("component-grid", "passthrough.input.mdx"); | ||
| const expected = readFixture("component-grid", "passthrough.output.mdx"); | ||
|
|
||
| const actual = normalizeLLMBodyWithRules(input, [componentGridRule]); | ||
|
|
||
| expect(normalizeForAssert(actual)).toBe(normalizeForAssert(expected)); | ||
| }); | ||
| }); | ||
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,115 @@ | ||
| import fs from "node:fs"; | ||
| import path from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import matter from "gray-matter"; | ||
| import type { MdxJsxFlowElement } from "mdast-util-mdx-jsx"; | ||
| import { baseUrl } from "@/app/metadata"; | ||
| import { getLLMMarkdownUrl } from "../config"; | ||
| import type { Rule } from "./types"; | ||
|
|
||
| export interface ComponentEntry { | ||
| category: string; | ||
| title: string; | ||
| description: string; | ||
| url: string; | ||
| } | ||
|
|
||
| type Frontmatter = { | ||
| title?: string; | ||
| description?: string; | ||
| deprecated?: boolean; | ||
| }; | ||
|
|
||
| function resolveComponentsDir(): string | null { | ||
| const candidates = [ | ||
| path.resolve(process.cwd(), "content/docs/components"), | ||
| path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../../../content/docs/components"), | ||
| ]; | ||
| for (const candidate of candidates) { | ||
| if (fs.existsSync(candidate)) return candidate; | ||
| } | ||
| console.warn(`[ComponentGrid] components directory not found; tried: ${candidates.join(", ")}`); | ||
| return null; | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| function titleCase(value: string): string { | ||
| return value.charAt(0).toUpperCase() + value.slice(1); | ||
| } | ||
|
|
||
| function loadEntries(): ComponentEntry[] { | ||
| const componentsDir = resolveComponentsDir(); | ||
| if (!componentsDir) return []; | ||
|
|
||
| const entries: ComponentEntry[] = []; | ||
| for (const dirent of fs.readdirSync(componentsDir, { withFileTypes: true })) { | ||
| if (!dirent.isDirectory()) continue; | ||
| const match = dirent.name.match(/^\(([^)]+)\)$/); | ||
| if (!match) continue; | ||
|
|
||
| const category = titleCase(match[1]); | ||
| const categoryDir = path.join(componentsDir, dirent.name); | ||
|
|
||
| for (const file of fs.readdirSync(categoryDir)) { | ||
| if (!file.endsWith(".mdx")) continue; | ||
|
|
||
| const source = fs.readFileSync(path.join(categoryDir, file), "utf8"); | ||
| const fm = matter(source).data as Frontmatter; | ||
| if (fm.deprecated) continue; | ||
|
|
||
| const slug = file.slice(0, -".mdx".length); | ||
| entries.push({ | ||
| category, | ||
| title: fm.title ?? slug, | ||
| description: fm.description ?? "", | ||
| url: new URL(getLLMMarkdownUrl("docs", ["components", slug]), baseUrl).toString(), | ||
| }); | ||
| } | ||
| } | ||
| return entries; | ||
| } | ||
|
|
||
| let cachedEntries: ComponentEntry[] | null = null; | ||
|
|
||
| function getEntries(): ComponentEntry[] { | ||
| if (cachedEntries === null) cachedEntries = loadEntries(); | ||
| return cachedEntries; | ||
| } | ||
|
|
||
| export function buildMarkdown(entries: ComponentEntry[]): string { | ||
| const grouped = new Map<string, ComponentEntry[]>(); | ||
| for (const entry of entries) { | ||
| if (!grouped.has(entry.category)) grouped.set(entry.category, []); | ||
| grouped.get(entry.category)!.push(entry); | ||
| } | ||
| for (const list of grouped.values()) { | ||
| list.sort((a, b) => a.title.localeCompare(b.title)); | ||
| } | ||
|
|
||
| const sections: string[] = []; | ||
| for (const [category, list] of Array.from(grouped.entries()).sort(([a], [b]) => | ||
| a.localeCompare(b), | ||
| )) { | ||
| const lines = [`## ${category}`, ""]; | ||
| for (const entry of list) { | ||
| const suffix = entry.description ? ` — ${entry.description}` : ""; | ||
| lines.push(`- [${entry.title}](${entry.url})${suffix}`); | ||
| } | ||
| sections.push(lines.join("\n")); | ||
| } | ||
| return sections.join("\n\n"); | ||
| } | ||
|
|
||
| export const componentGridRule: Rule = { | ||
| name: "ComponentGrid", | ||
| match: (node): node is MdxJsxFlowElement => | ||
| node.type === "mdxJsxFlowElement" && node.name === "ComponentGrid", | ||
| transform: (node) => { | ||
| try { | ||
| const entries = getEntries(); | ||
| if (entries.length === 0) return [node]; | ||
| return [{ type: "html", value: buildMarkdown(entries) }]; | ||
| } catch { | ||
| return [node]; | ||
| } | ||
| }, | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| }; | ||
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.