Replies: 2 comments 7 replies
|
Just to inform people. The framework is flexible enough that you can do a For example in your Next config file: {
source: '/docs/:slug',
destination: '/docs/md/:slug',
has: [
{
type: 'header',
key: 'accept',
value: '(.*)text/markdown(.*)',
},
],
},And then you'd have, export async function generateStaticParams() {
return [/* the set of slugs you wanna prerender */];
}
export async function GET(
_: Request,
{ params }: { params: Promise<{ slug: string[] }> },
) {
const { slug } = await params;
return new Response(/* your content */, {
headers: {
'Content-Type': 'text/markdown; charset=utf-8',
Vary: 'Accept',
},
});
}Unlike the |
|
The rewrite approach described above works well if you want full control over the markdown output. For cases where you want automatic conversion, I built a Next.js middleware for this - inspired by the Cloudflare feature mentioned in the original post, but at the application layer: npm install @markdown-for-agents/nextjs
// middleware.ts
import { withMarkdown } from '@markdown-for-agents/nextjs';
export default withMarkdown();Handles content negotiation via Accept: text/markdown, strips non-content elements, sets caching headers. Details in the repo: https://github.com/KKonstantinov/markdown-for-agents |
Uh oh!
There was an error while loading. Please reload this page.
Goals
text/markdownfor agents retrieve content quicklygenerateMetadatabut tentatively call itgenerateStaticMarkdownContentacceptorcontent-typerequestspage.tsx(not on page router)Non-Goals
Background
With LLMs parsing a lot of content of the pages this is becoming more relevant. Cloudflare announced recently this feature on sites served on it, but ideally full control would happen at the application: https://blog.cloudflare.com/markdown-for-agents/
Proposal
app-render.tsxto allow support fortext/markdownin headergenerateStaticTextContentsimilar togenerateStaticParamsthat will allow control on what to be served. If that function exists for a page, that page will support the markdown alternative routeAll reactions