Skip to content

Commit 0014da8

Browse files
implementation for .md suffixed routes
Co-Authored-By: fuko <43729152+fulopkovacs@users.noreply.github.com>
1 parent f805803 commit 0014da8

2 files changed

Lines changed: 54 additions & 4 deletions

File tree

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1+
import { getBranch, getLibrary } from '~/libraries'
2+
import { loadDocs } from '~/utils/docs'
3+
14
export const ServerRoute = createServerFileRoute().methods({
2-
GET: async ({ request }) => {
3-
return new Response('Foo bar')
5+
GET: async ({ request, params }) => {
6+
const url = new URL(request.url)
7+
8+
const { libraryId, version, framework, _splat: docsPath } = params
9+
const library = getLibrary(libraryId)
10+
const root = library.docsRoot || 'docs'
11+
12+
const doc = await loadDocs({
13+
repo: library.repo,
14+
branch: getBranch(library, version),
15+
docsPath: `${root}/framework/${framework}/${docsPath}`,
16+
currentPath: url.pathname,
17+
redirectPath: `/${library.id}/${version}/docs/overview`,
18+
})
19+
20+
const markdownContent = `# ${doc.title}\n${doc.content}`
21+
const filename = (docsPath || 'file').split('/').join('-')
22+
23+
return new Response(markdownContent, {
24+
headers: {
25+
'Content-Type': 'text/markdown',
26+
'Content-Disposition': `inline; filename="${filename}.md"`,
27+
},
28+
})
429
},
530
})
Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1+
import { getBranch, getLibrary } from '~/libraries'
2+
import { loadDocs } from '~/utils/docs'
3+
14
export const ServerRoute = createServerFileRoute().methods({
2-
GET: async ({ request }) => {
3-
return new Response('Foo bar')
5+
GET: async ({ request, params }) => {
6+
const url = new URL(request.url)
7+
8+
const { libraryId, version, _splat: docsPath } = params
9+
const library = getLibrary(libraryId)
10+
const root = library.docsRoot || 'docs'
11+
12+
const doc = await loadDocs({
13+
repo: library.repo,
14+
branch: getBranch(library, version),
15+
docsPath: `${root}/${docsPath}`,
16+
currentPath: url.pathname,
17+
redirectPath: `/${library.id}/${version}/docs/overview`,
18+
})
19+
20+
const markdownContent = `# ${doc.title}\n${doc.content}`
21+
const filename = (docsPath || 'file').split('/').join('-')
22+
23+
return new Response(markdownContent, {
24+
headers: {
25+
'Content-Type': 'text/markdown',
26+
'Content-Disposition': `inline; filename="${filename}.md"`,
27+
},
28+
})
429
},
530
})

0 commit comments

Comments
 (0)