-
-
Notifications
You must be signed in to change notification settings - Fork 343
Expand file tree
/
Copy path$version.docs.framework.$framework.{$}[.]md.tsx
More file actions
32 lines (27 loc) · 1.09 KB
/
$version.docs.framework.$framework.{$}[.]md.tsx
File metadata and controls
32 lines (27 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { getBranch, getLibrary } from '~/libraries'
import { loadDocs } from '~/utils/docs'
export const ServerRoute = createServerFileRoute().methods({
GET: async ({ request, params }) => {
const url = new URL(request.url)
const { libraryId, version, framework, _splat: docsPath } = params
const library = getLibrary(libraryId)
const root = library.docsRoot || 'docs'
const doc = await loadDocs({
repo: library.repo,
branch: getBranch(library, version),
docsPath: `${root}/framework/${framework}/${docsPath}`,
currentPath: url.pathname,
redirectPath: `/${library.id}/${version}/docs/overview`,
})
const markdownContent = `# ${doc.title}\n${doc.content}`
const filename = (docsPath || 'file').split('/').join('-')
return new Response(markdownContent, {
headers: {
'Content-Type': 'text/markdown',
'Content-Disposition': `inline; filename="${filename}.md"`,
'Cache-Control': 'public, max-age=0, must-revalidate',
'Cdn-Cache-Control': 'max-age=300, stale-while-revalidate=300, durable',
},
})
},
})