-
-
Notifications
You must be signed in to change notification settings - Fork 333
Expand file tree
/
Copy path$version.docs.framework.$framework.{$}[.]md.tsx
More file actions
77 lines (67 loc) · 2.26 KB
/
$version.docs.framework.$framework.{$}[.]md.tsx
File metadata and controls
77 lines (67 loc) · 2.26 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { findLibrary, getBranch } from '~/libraries'
import { isDocsNotFoundError } from '~/utils/docs-errors'
import { loadDocs } from '~/utils/docs'
import { notFound, createFileRoute } from '@tanstack/react-router'
import { filterFrameworkContent } from '~/utils/markdown/filterFrameworkContent'
import { getPackageManager } from '~/utils/markdown/installCommand'
export const Route = createFileRoute(
'/$libraryId/$version/docs/framework/$framework/{$}.md',
)({
server: {
handlers: {
GET: async ({
request,
params,
}: {
request: Request
params: {
libraryId: string
version: string
framework: string
_splat: string
}
}) => {
const url = new URL(request.url)
const pm = getPackageManager(url.searchParams.get('pm'))
const keepMarkers = url.searchParams.get('keep_markers') === 'true'
const { libraryId, version, framework, _splat: docsPath } = params
const library = findLibrary(libraryId)
if (!library) {
throw notFound()
}
const root = library.docsRoot || 'docs'
let doc
try {
doc = await loadDocs({
repo: library.repo,
branch: getBranch(library, version),
docsRoot: root,
docsPath: `framework/${framework}/${docsPath}`,
})
} catch (error) {
if (isDocsNotFoundError(error)) {
throw notFound()
}
throw error
}
// Filter framework-specific content using framework from URL path
const filteredContent = filterFrameworkContent(doc.content, {
framework,
packageManager: pm,
keepMarkers,
})
const markdownContent = `# ${doc.title}\n${filteredContent}`
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',
},
})
},
},
},
})