Fumadocs

谈判

用于协商功能的小型封装器。

概览

🌐 Overview

对于支持中间件的 React.js 框架,你可以使用 Fumadocs 的 Negotiation API 来实现基本功能。

🌐 For React.js frameworks supporting middlewares, you can use the Negotiation API of Fumadocs for basic functionalities.

它是 negotiator 的一个小型封装。

🌐 It is a tiny wrapper of negotiator.

接受 Markdown

🌐 Accept Markdown

根据 Accept 头部提供 Markdown 或 HTML,这可以改善 AI 代理的体验。

🌐 Serve markdown or HTML depending on the Accept header, this can improve the experience for AI agents.

proxy.ts (Next.js)
import { NextRequest, NextResponse } from 'next/server';
import { isMarkdownPreferred, rewritePath } from 'fumadocs-core/negotiation';

const { rewrite: rewriteLLM } = rewritePath('/docs/*path', '/llms.mdx/*path');

export default function proxy(request: NextRequest) {
  if (isMarkdownPreferred(request)) {
    const result = rewriteLLM(request.nextUrl.pathname);

    if (result) {
      return NextResponse.rewrite(new URL(result, request.nextUrl));
    }
  }

  return NextResponse.next();
}

Last updated on

On this page