Skip to content

Commit

Permalink
Revert some redundant changes
Browse files Browse the repository at this point in the history
  • Loading branch information
fulopkovacs committed Jan 12, 2024
1 parent 117f783 commit 1692b18
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 90 deletions.
53 changes: 8 additions & 45 deletions app/routes/form.$version.docs.framework.$framework.$.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,25 @@
import type { LoaderFunctionArgs, MetaFunction } from '@remix-run/node'
import type { GithubDocsConfig } from '~/routes/form'
import { repo, getBranch } from '~/routes/form'
import { DefaultErrorBoundary } from '~/components/DefaultErrorBoundary'
import { seo } from '~/utils/seo'
import { useLoaderData, useParams } from '@remix-run/react'
import { Doc } from '~/components/Doc'
import { loadDocs } from '~/utils/docs'
import { fetchRepoFile } from '~/utils/documents.server'

export const loader = async (context: LoaderFunctionArgs) => {
const { '*': docsPath, framework, version } = context.params
const branch = getBranch(context.params.version)
const config = await fetchRepoFile(repo, branch, `docs/config.json`)

if (!config) {
throw new Error('Repo docs/config.json not found!')
}

const parsedConfig = JSON.parse(config) as GithubDocsConfig

const frameworkDoc = `framework/${framework}/${docsPath}`
let docPath = `docs/${frameworkDoc}`

if (framework) {
const stringToDrop = `framework/${framework}/`

const frameworkDocPageIds = parsedConfig.frameworkMenus
.find((f) => f.framework === framework)
?.menuItems.flatMap((m) =>
m.children.map((c) => c.to.slice(stringToDrop.length))
)

if (
frameworkDocPageIds &&
docsPath &&
frameworkDocPageIds.includes(docsPath)
) {
return loadDocs({
repo,
branch: getBranch(version),
docPath,
redirectPath: context.request.url.replace(/\/docs.*/, ``),
})
} else {
// Assume that it's a "core" doc page
return loadDocs({
repo,
branch: getBranch(version),
docPath: `docs/${docsPath}`,
redirectPath: context.request.url.replace(/\/docs.*/, ``),
})
}
}
return loadDocs({
repo,
branch: getBranch(version),
docPath: `docs/framework/${framework}/${docsPath}`,
redirectPath: context.request.url.replace(/\/docs.*/, ``),
})
}

export const meta: MetaFunction = ({ data }) => {
export const meta: MetaFunction<typeof loader> = ({ data }) => {
return seo({
title: `${data?.title} | TanStack Form Docs`,
title: `${data?.title} | TanStack Query Docs`,
description: data?.description,
})
}
Expand Down
53 changes: 8 additions & 45 deletions app/routes/store.$version.docs.framework.$framework.$.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,25 @@
import type { LoaderFunctionArgs, MetaFunction } from '@remix-run/node'
import type { GithubDocsConfig } from '~/routes/store'
import { repo, getBranch } from '~/routes/store'
import { DefaultErrorBoundary } from '~/components/DefaultErrorBoundary'
import { seo } from '~/utils/seo'
import { useLoaderData, useParams } from '@remix-run/react'
import { Doc } from '~/components/Doc'
import { loadDocs } from '~/utils/docs'
import { fetchRepoFile } from '~/utils/documents.server'

export const loader = async (context: LoaderFunctionArgs) => {
const { '*': docsPath, framework, version } = context.params
const branch = getBranch(context.params.version)
const config = await fetchRepoFile(repo, branch, `docs/config.json`)

if (!config) {
throw new Error('Repo docs/config.json not found!')
}

const parsedConfig = JSON.parse(config) as GithubDocsConfig

const frameworkDoc = `framework/${framework}/${docsPath}`
let docPath = `docs/${frameworkDoc}`

if (framework) {
const stringToDrop = `framework/${framework}/`

const frameworkDocPageIds = parsedConfig.frameworkMenus
.find((f) => f.framework === framework)
?.menuItems.flatMap((m) =>
m.children.map((c) => c.to.slice(stringToDrop.length))
)

if (
frameworkDocPageIds &&
docsPath &&
frameworkDocPageIds.includes(docsPath)
) {
return loadDocs({
repo,
branch: getBranch(version),
docPath,
redirectPath: context.request.url.replace(/\/docs.*/, ``),
})
} else {
// Assume that it's a "core" doc page
return loadDocs({
repo,
branch: getBranch(version),
docPath: `docs/${docsPath}`,
redirectPath: context.request.url.replace(/\/docs.*/, ``),
})
}
}
return loadDocs({
repo,
branch: getBranch(version),
docPath: `docs/framework/${framework}/${docsPath}`,
redirectPath: context.request.url.replace(/\/docs.*/, ``),
})
}

export const meta: MetaFunction = ({ data }) => {
export const meta: MetaFunction<typeof loader> = ({ data }) => {
return seo({
title: `${data?.title} | TanStack Store Docs`,
title: `${data?.title} | TanStack Query Docs`,
description: data?.description,
})
}
Expand Down

0 comments on commit 1692b18

Please sign in to comment.