-
Notifications
You must be signed in to change notification settings - Fork 69
Improve API docs build performance and reduce build invalidation #601
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,29 +2,26 @@ | |
| // Include a Markdown/MDX file from the docs collection inline. | ||
| // Usage in MDX: <Include relativePath="reference/cli/includes/project-search-logic.description.md" /> | ||
|
|
||
| import { getEntry, render } from 'astro:content'; | ||
|
|
||
| interface Props { | ||
| /** Path relative to /src/content/docs (may start with or without a leading slash). */ | ||
| relativePath: string; | ||
| } | ||
|
|
||
| const { relativePath } = Astro.props as Props; | ||
|
|
||
| // Eagerly import all .md and .mdx under the docs collection so we can render by path. | ||
| const mdModules = { | ||
| ...(import.meta.glob('/src/content/docs/**/*.md', { eager: true }) as Record<string, unknown>), | ||
| ...(import.meta.glob('/src/content/docs/**/*.mdx', { eager: true }) as Record<string, unknown>), | ||
| }; | ||
|
|
||
| // Normalize the provided path to match the glob keys (absolute from project root). | ||
| const normalized = `/src/content/docs/${relativePath.replace(/^\/+/, '')}`; | ||
| const mod = mdModules[normalized] as any; | ||
| // Resolve the include through the docs collection instead of eagerly globbing | ||
| // the entire docs tree into every page that uses <Include>. | ||
|
Comment on lines
+14
to
+15
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this comment mean? Why is it saying "instead of eagerly globbing the entire docs tree"?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code before, was doing this: Which eagerly enumerated ALL matching .md and .mdx files. Which was not good for perf. |
||
| const normalizedPath = relativePath.replace(/^\/+/, ''); | ||
| const entryId = normalizedPath.replace(/\.(md|mdx)$/i, ''); | ||
| const entry = await getEntry('docs', entryId); | ||
|
|
||
| if (!mod) { | ||
| throw new Error(`Include.astro: File not found: ${normalized}`); | ||
| if (!entry) { | ||
| throw new Error(`Include.astro: File not found: ${normalizedPath} (entry id: ${entryId})`); | ||
| } | ||
|
|
||
| // MD/MDX modules may export either `Content` or a default component. | ||
| const ResolvedContent = (mod?.Content ?? mod?.default) as any; | ||
| const { Content: ResolvedContent } = await render(entry); | ||
| --- | ||
|
|
||
| {ResolvedContent ? <ResolvedContent /> : null} | ||
Uh oh!
There was an error while loading. Please reload this page.