WIP - Serve raw MDX from any docs page#439
Open
aptkingston wants to merge 2 commits into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prototypes serving raw MDX source for docs pages via ?format=mdx, using a Next.js proxy rewrite to a static route handler.
Changes:
- Adds a
src/proxy.tsinterceptor that rewrites recognizedformatquery requests to internal format routes. - Adds
loadAllMdxPaths()to map docs URLs back to MDX source files. - Adds
/mdx/[...slug]route handling to return raw MDX content.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/proxy.ts |
Adds query-based rewrite handling for alternate content formats. |
src/lib/markdown/util.ts |
Adds cross-section MDX URL-to-file path mapping. |
src/app/mdx/[...slug]/route.ts |
Adds static route handler for serving raw MDX source. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+55
to
+56
| ...guides.filter((info) => info.slug !== '').map((info) => ({ urlPath: `/guides/${info.slug}`, file: info.file })), | ||
| ...api.filter((info) => info.slug !== '').map((info) => ({ urlPath: `/api/${info.slug}`, file: info.file })), |
| @@ -0,0 +1,42 @@ | |||
| import { NextRequest, NextResponse } from 'next/server'; | |||
| @@ -0,0 +1,33 @@ | |||
| import { readFile } from 'node:fs/promises'; | |||
Comment on lines
+6
to
+10
| * Currently one format is supported on any MDX-backed page (optimised for LLMs | ||
| * reading the docs): | ||
| * ?format=mdx - the raw .mdx source | ||
| * The format param is the extension point for future formats - add new values | ||
| * here, each mapping to its own rewrite target / route handler. An unrecognised |
| * Used to map an incoming request path back to its underlying source file (e.g. | ||
| * for serving raw markdown via ?format=mdx). | ||
| */ | ||
| export const loadAllMdxPaths = async (): Promise<MdxPath[]> => { |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Prototype for testing