mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-24 20:09:02 +00:00
31 lines
807 B
TypeScript
31 lines
807 B
TypeScript
import { createMiddleware, createStart } from '@tanstack/react-start';
|
|
import { isMarkdownPreferred } from 'fumadocs-core/negotiation';
|
|
import { redirect } from '@tanstack/react-router';
|
|
import { docsRoute, encodeMarkdownUrl } from '@/lib/shared';
|
|
|
|
const llmMiddleware = createMiddleware().server(({ next, request }) => {
|
|
const url = new URL(request.url);
|
|
|
|
if (
|
|
url.pathname.startsWith(docsRoute) &&
|
|
!url.pathname.endsWith('.md') &&
|
|
isMarkdownPreferred(request)
|
|
) {
|
|
const slugs = url.pathname
|
|
.slice(docsRoute.length)
|
|
.split('/')
|
|
.filter((v) => v.length > 0);
|
|
url.pathname = encodeMarkdownUrl(slugs);
|
|
|
|
throw redirect(url);
|
|
}
|
|
|
|
return next();
|
|
});
|
|
|
|
export const startInstance = createStart(() => {
|
|
return {
|
|
requestMiddleware: [llmMiddleware],
|
|
};
|
|
});
|