Skip to content

Commit 3fe7d59

Browse files
committed
tester
1 parent 558c517 commit 3fe7d59

File tree

3 files changed

+50
-29
lines changed

3 files changed

+50
-29
lines changed

src/routes/$libraryId/$version.docs.$.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ export const Route = createFileRoute('/$libraryId/$version/docs/$')({
2626
const branch = getBranch(library, version)
2727
const docsRoot = library.docsRoot || 'docs'
2828

29+
const redirectPath = await resolveDocsRedirect({
30+
repo: library.repo,
31+
branch,
32+
docsRoot,
33+
docsPaths: docsPath ? [docsPath] : [],
34+
})
35+
36+
if (redirectPath !== null) {
37+
throw redirect({
38+
href: `/${libraryId}/${version}/docs${redirectPath ? `/${redirectPath}` : ''}`,
39+
})
40+
}
41+
2942
try {
3043
return await loadDocs({
3144
repo: library.repo,
@@ -38,19 +51,6 @@ export const Route = createFileRoute('/$libraryId/$version/docs/$')({
3851
(error && typeof error === 'object' && 'isNotFound' in error)
3952

4053
if (isNotFoundError) {
41-
const redirectPath = await resolveDocsRedirect({
42-
repo: library.repo,
43-
branch,
44-
docsRoot,
45-
docsPaths: docsPath ? [docsPath] : [],
46-
})
47-
48-
if (redirectPath !== null) {
49-
throw redirect({
50-
href: `/${libraryId}/${version}/docs${redirectPath ? `/${redirectPath}` : ''}`,
51-
})
52-
}
53-
5454
throw notFound()
5555
}
5656

src/routes/$libraryId/$version.docs.framework.$framework.$.tsx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ export const Route = createFileRoute(
2424
const branch = getBranch(library, version)
2525
const docsRoot = library.docsRoot || 'docs'
2626

27+
const redirectPath = await resolveDocsRedirect({
28+
repo: library.repo,
29+
branch,
30+
docsRoot,
31+
docsPaths: docsPath
32+
? [`framework/${framework}/${docsPath}`, `${framework}/${docsPath}`]
33+
: [],
34+
})
35+
36+
if (redirectPath !== null) {
37+
throw redirect({
38+
href: `/${libraryId}/${version}/docs${redirectPath ? `/${redirectPath}` : ''}`,
39+
})
40+
}
41+
2742
try {
2843
return await loadDocs({
2944
repo: library.repo,
@@ -39,21 +54,6 @@ export const Route = createFileRoute(
3954
(error && typeof error === 'object' && 'isNotFound' in error)
4055

4156
if (isNotFoundError) {
42-
const redirectPath = await resolveDocsRedirect({
43-
repo: library.repo,
44-
branch,
45-
docsRoot,
46-
docsPaths: docsPath
47-
? [`framework/${framework}/${docsPath}`, `${framework}/${docsPath}`]
48-
: [],
49-
})
50-
51-
if (redirectPath !== null) {
52-
throw redirect({
53-
href: `/${libraryId}/${version}/docs${redirectPath ? `/${redirectPath}` : ''}`,
54-
})
55-
}
56-
5757
throw redirect({
5858
to: '/$libraryId/$version/docs/framework/$framework',
5959
params: { libraryId, version, framework },

src/utils/docs.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ export async function resolveDocsRedirect(opts: {
132132
docsRoot: string
133133
docsPaths: Array<string>
134134
}) {
135-
const manifest = await getDocsRedirectManifest(opts)
135+
const manifest = await fetchDocsRedirectManifest({
136+
data: opts,
137+
})
136138

137139
for (const docsPath of opts.docsPaths) {
138140
const normalizedDocsPath = normalizeDocsRedirectPath(docsPath)
@@ -213,6 +215,25 @@ async function getDocsRedirectManifest(opts: {
213215
})
214216
}
215217

218+
const fetchDocsRedirectManifest = createServerFn({
219+
method: 'GET',
220+
})
221+
.inputValidator(
222+
v.object({
223+
repo: v.string(),
224+
branch: v.string(),
225+
docsRoot: v.string(),
226+
docsPaths: v.array(v.string()),
227+
}),
228+
)
229+
.handler(async ({ data }) => {
230+
return getDocsRedirectManifest({
231+
repo: data.repo,
232+
branch: data.branch,
233+
docsRoot: data.docsRoot,
234+
})
235+
})
236+
216237
function flattenDocsNodes(nodes: Array<DocsTreeNode>): Array<DocsTreeNode> {
217238
return nodes.flatMap((node) => [
218239
node,

0 commit comments

Comments
 (0)