mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 06:31:49 +00:00
38 lines
1013 B
TypeScript
38 lines
1013 B
TypeScript
import { createMiddleware, createStart } from '@tanstack/react-start';
|
|
import { isMarkdownPreferred, rewritePath } from 'fumadocs-core/negotiation';
|
|
import { redirect } from '@tanstack/react-router';
|
|
import { docsContentRoute, docsRoute } from '@/lib/shared';
|
|
|
|
const { rewrite: rewriteDocs } = rewritePath(
|
|
`${docsRoute}{/*path}`,
|
|
`${docsContentRoute}{/*path}/content.md`,
|
|
);
|
|
const { rewrite: rewriteSuffix } = rewritePath(
|
|
`${docsRoute}{/*path}.mdx`,
|
|
`${docsContentRoute}{/*path}/content.md`,
|
|
);
|
|
|
|
const llmMiddleware = createMiddleware().server(({ next, request }) => {
|
|
const url = new URL(request.url);
|
|
const path = rewriteSuffix(url.pathname);
|
|
|
|
if (path) {
|
|
throw redirect(new URL(path, url));
|
|
}
|
|
|
|
if (isMarkdownPreferred(request)) {
|
|
const docsPath = rewriteDocs(url.pathname);
|
|
if (docsPath) {
|
|
throw redirect(new URL(docsPath, url));
|
|
}
|
|
}
|
|
|
|
return next();
|
|
});
|
|
|
|
export const startInstance = createStart(() => {
|
|
return {
|
|
requestMiddleware: [llmMiddleware],
|
|
};
|
|
});
|