-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrate router docs to v2 layout
- Loading branch information
1 parent
33ef71e
commit e7bfd46
Showing
14 changed files
with
253 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,75 @@ | ||
import { Link } from '@remix-run/react' | ||
import reactLogo from '~/images/react-logo.svg' | ||
import { FaDiscord, FaGithub } from 'react-icons/fa/index' | ||
import { useDocsConfig } from '~/utils/config' | ||
import type { ConfigSchema, MenuItem } from '~/utils/config' | ||
|
||
export const repo = 'tanstack/router' | ||
|
||
export const v1branch = 'main' | ||
export const latestBranch = 'main' | ||
export const latestVersion = 'v1' | ||
export const availableVersions = ['v1'] | ||
|
||
export const gradientText = | ||
'inline-block text-transparent bg-clip-text bg-gradient-to-r from-lime-500 to-emerald-500' | ||
|
||
const frameworks = { | ||
react: { label: 'React', logo: reactLogo, value: 'react' }, | ||
} as const | ||
|
||
export type Framework = keyof typeof frameworks | ||
|
||
export const createLogo = (version?: string) => ( | ||
<> | ||
<Link to="/" className="font-light"> | ||
TanStack | ||
</Link> | ||
<Link to=".." className={`font-bold`}> | ||
<span className={`${gradientText}`}>Router</span> | ||
<span className="text-sm align-super"> | ||
{version === 'latest' ? latestVersion : version} | ||
</span> | ||
</Link> | ||
</> | ||
) | ||
|
||
export const localMenu: MenuItem = { | ||
label: 'Menu', | ||
children: [ | ||
{ | ||
label: 'Home', | ||
to: '..', | ||
}, | ||
{ | ||
label: ( | ||
<div className="flex items-center gap-2"> | ||
GitHub <FaGithub className="text-lg opacity-20" /> | ||
</div> | ||
), | ||
to: 'https://github.com/tanstack/router', | ||
}, | ||
{ | ||
label: ( | ||
<div className="flex items-center gap-2"> | ||
Discord <FaDiscord className="text-lg opacity-20" /> | ||
</div> | ||
), | ||
to: 'https://tlinz.com/discord', | ||
}, | ||
], | ||
} | ||
|
||
export function getBranch(argVersion?: string) { | ||
const version = argVersion || latestVersion | ||
|
||
return ['latest', latestVersion].includes(version) ? latestBranch : version | ||
} | ||
|
||
export const useRouterDocsConfig = (config: ConfigSchema) => { | ||
return useDocsConfig({ | ||
config, | ||
frameworks, | ||
localMenu, | ||
availableVersions, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useLoaderData, useParams } from '@remix-run/react' | ||
import type { LoaderFunctionArgs, MetaFunction } from '@remix-run/node' | ||
import { repo, getBranch } from '~/projects/router' | ||
import { DefaultErrorBoundary } from '~/components/DefaultErrorBoundary' | ||
import { seo } from '~/utils/seo' | ||
import { Doc } from '~/components/Doc' | ||
import { loadDocs } from '~/utils/docs' | ||
|
||
export const loader = async (context: LoaderFunctionArgs) => { | ||
const { '*': docsPath, version } = context.params | ||
const { url } = context.request | ||
|
||
return loadDocs({ | ||
repo, | ||
branch: getBranch(version), | ||
docPath: `docs/${docsPath}`, | ||
currentPath: url, | ||
redirectPath: url.replace(/\/docs.*/, '/docs/react/overview'), | ||
}) | ||
} | ||
|
||
export const meta: MetaFunction<typeof loader> = ({ data }) => { | ||
return seo({ | ||
title: `${data?.title ?? 'Docs'} | TanStack Router Docs`, | ||
description: data?.description, | ||
}) | ||
} | ||
|
||
export const ErrorBoundary = DefaultErrorBoundary | ||
|
||
export default function RouteReactTableDocs() { | ||
const { title, content, filePath } = useLoaderData<typeof loader>() | ||
const { version } = useParams() | ||
const branch = getBranch(version) | ||
return ( | ||
<Doc | ||
title={title} | ||
content={content} | ||
repo={repo} | ||
branch={branch} | ||
filePath={filePath} | ||
/> | ||
) | ||
} |
4 changes: 2 additions & 2 deletions
4
...routes/router.v1.docs.examples._index.tsx → app/routes/router.$version.docs._index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { redirect } from '@remix-run/node' | ||
import type { LoaderFunction } from '@remix-run/node' | ||
import { redirect } from '@remix-run/node' | ||
|
||
export const loader: LoaderFunction = (context) => { | ||
throw redirect( | ||
context.request.url.replace(/\/examples.*/, '/examples/react/basic') | ||
context.request.url.replace(/\/docs.*/, '/docs/react/overview') | ||
) | ||
} |
45 changes: 45 additions & 0 deletions
45
app/routes/router.$version.docs.framework.$framework.$.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { LoaderFunctionArgs, MetaFunction } from '@remix-run/node' | ||
import { repo, getBranch } from '~/projects/router' | ||
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' | ||
|
||
export const loader = async (context: LoaderFunctionArgs) => { | ||
const { '*': docsPath, framework, version } = context.params | ||
const { url } = context.request | ||
|
||
return loadDocs({ | ||
repo, | ||
branch: getBranch(version), | ||
docPath: `docs/framework/${framework}/${docsPath}`, | ||
currentPath: url, | ||
redirectPath: url.replace(/\/docs.*/, '/docs/react/overview'), | ||
}) | ||
} | ||
|
||
export const meta: MetaFunction<typeof loader> = ({ data }) => { | ||
return seo({ | ||
title: `${data?.title} | TanStack Router Docs`, | ||
description: data?.description, | ||
}) | ||
} | ||
|
||
export const ErrorBoundary = DefaultErrorBoundary | ||
|
||
export default function RouteDocs() { | ||
const { title, content, filePath } = useLoaderData<typeof loader>() | ||
const { version } = useParams() | ||
const branch = getBranch(version) | ||
|
||
return ( | ||
<Doc | ||
title={title} | ||
content={content} | ||
repo={repo} | ||
branch={branch} | ||
filePath={filePath} | ||
/> | ||
) | ||
} |
8 changes: 8 additions & 0 deletions
8
app/routes/router.$version.docs.framework.$framework._index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { redirect } from '@remix-run/node' | ||
import type { LoaderFunctionArgs } from '@remix-run/node' | ||
|
||
export const loader = async (context: LoaderFunctionArgs) => { | ||
throw redirect( | ||
context.request.url.replace(/\/docs.*/, '/docs/react/overview') | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
app/routes/router.v1.docs._index.tsx → ....framework.$framework.examples._index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import type { LoaderFunction } from '@remix-run/node' | ||
import { redirect } from '@remix-run/node' | ||
import type { LoaderFunction } from '@remix-run/node' | ||
|
||
export const loader: LoaderFunction = (context) => { | ||
throw redirect(context.request.url.replace(/\/docs.*/, '/docs/overview')) | ||
throw redirect(context.request.url.replace(/\/examples.*/, '/examples/basic')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Outlet, json, useLoaderData } from '@remix-run/react' | ||
import type { LoaderFunctionArgs, MetaFunction } from '@remix-run/node' | ||
import { | ||
repo, | ||
getBranch, | ||
useRouterDocsConfig, | ||
createLogo, | ||
} from '~/projects/router' | ||
import { seo } from '~/utils/seo' | ||
import { DocsLayout } from '~/components/DocsLayout' | ||
import { getTanstackDocsConfig } from '~/utils/config' | ||
|
||
export const loader = async (context: LoaderFunctionArgs) => { | ||
const { version } = context.params | ||
const branch = getBranch(version) | ||
const tanstackDocsConfig = await getTanstackDocsConfig(repo, branch) | ||
|
||
return json({ | ||
tanstackDocsConfig, | ||
version, | ||
}) | ||
} | ||
|
||
export const meta: MetaFunction = () => { | ||
return seo({ | ||
title: 'TanStack Router Docs | React Router', | ||
description: 'Modern and scalable routing for React applications', | ||
}) | ||
} | ||
|
||
export default function DocsRoute() { | ||
const { tanstackDocsConfig, version } = useLoaderData<typeof loader>() | ||
let config = useRouterDocsConfig(tanstackDocsConfig) | ||
|
||
return ( | ||
<DocsLayout | ||
v2={true} | ||
logo={createLogo(version)} | ||
colorFrom={'from-lime-500'} | ||
colorTo={'to-emerald-500'} | ||
textColor={'text-emerald-500'} | ||
config={config} | ||
framework={config.frameworkConfig} | ||
version={config.versionConfig} | ||
> | ||
<Outlet /> | ||
</DocsLayout> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.