-
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 ranger docs to v2 layout (#153)
* feat: Migrate ranger docs to v2 layout * Remove useless string literal * Quick fixes * Fix v1 redirect list * Change to v1 * Fix version redirects * Better redirect
- Loading branch information
1 parent
f1fca89
commit f9b7ff9
Showing
14 changed files
with
255 additions
and
208 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/ranger' | ||
|
||
export const v1branch = 'main' | ||
export const latestBranch = 'main' | ||
export const latestVersion = 'v0' | ||
export const availableVersions = ['v0'] | ||
|
||
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}`}>Ranger</span>{' '} | ||
<span className="text-sm align-super"> | ||
{version === 'latest' ? latestVersion : version} | ||
</span> | ||
</Link> | ||
</> | ||
) | ||
|
||
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/ranger', | ||
}, | ||
{ | ||
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 useRangerDocsConfig = (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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,5 @@ | ||
import type { LoaderFunction } from '@remix-run/node' | ||
import { redirect } from '@remix-run/node' | ||
|
||
export const loader: LoaderFunction = (context) => { | ||
handleRedirects(context) | ||
|
||
return redirect('/ranger/v1') | ||
} | ||
|
||
function handleRedirects(context: Parameters<LoaderFunction>[0]) { | ||
const url = new URL(context.request.url) | ||
// prettier-ignore | ||
const reactRangerV1List = [ | ||
{from: 'docs/overview',to: 'docs/guide/introduction',}, | ||
{from: 'docs/installation',to: 'docs/guide/installation',}, | ||
{from: 'examples/basic',to: 'docs/examples/react/basic',}, | ||
{from: 'examples/custom-steps',to: 'docs/examples/react/custom-steps',}, | ||
{from: 'examples/custom-styles',to: 'docs/examples/react/custom-styles',}, | ||
{from: 'examples/logarithmic-interpolator',to: 'docs/examples/react/logarithmic-interpolator',}, | ||
{from: 'examples/update-on-drag',to: 'docs/examples/react/update-on-drag',}, | ||
{from: '',to: '',}, | ||
] | ||
|
||
reactRangerV1List.forEach((item) => { | ||
if (url.pathname.startsWith(`/ranger/v1/${item.from}`)) { | ||
throw redirect( | ||
`/ranger/v1/${item.to}?from=reactRangerV1&original=https://react-ranger-v1.tanstack.com/${item.from}`, | ||
301 | ||
) | ||
} | ||
}) | ||
export const loader = () => { | ||
return redirect('/ranger/latest') | ||
} |
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/ranger' | ||
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/overview'), | ||
}) | ||
} | ||
|
||
export const meta: MetaFunction<typeof loader> = ({ data }) => { | ||
return seo({ | ||
title: `${data?.title ?? 'Docs'} | TanStack Ranger Docs`, | ||
description: data?.description, | ||
}) | ||
} | ||
|
||
export const ErrorBoundary = DefaultErrorBoundary | ||
|
||
export default function RouteReactRangerDocs() { | ||
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} | ||
/> | ||
) | ||
} |
File renamed without changes.
45 changes: 45 additions & 0 deletions
45
app/routes/ranger.$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/ranger' | ||
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/overview'), | ||
}) | ||
} | ||
|
||
export const meta: MetaFunction<typeof loader> = ({ data }) => { | ||
return seo({ | ||
title: `${data?.title} | TanStack Ranger 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} | ||
/> | ||
) | ||
} |
6 changes: 6 additions & 0 deletions
6
app/routes/ranger.$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,6 @@ | ||
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/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
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,55 @@ | ||
import * as React from 'react' | ||
import { Outlet, json, redirect, useLoaderData } from '@remix-run/react' | ||
import { | ||
useRangerDocsConfig, | ||
repo, | ||
getBranch, | ||
createLogo, | ||
} from '~/projects/ranger' | ||
import { seo } from '~/utils/seo' | ||
import { DocsLayout } from '~/components/DocsLayout' | ||
import { getTanstackDocsConfig } from '~/utils/config' | ||
import type { MetaFunction, LoaderFunctionArgs } from '@remix-run/node' | ||
import { availableVersions } from '~/projects/form' | ||
|
||
export const loader = async (context: LoaderFunctionArgs) => { | ||
const { version } = context.params | ||
const branch = getBranch(version) | ||
|
||
if (!availableVersions.concat('latest').includes(version!)) { | ||
throw redirect(context.request.url.replace(version!, 'latest')) | ||
} | ||
|
||
const tanstackDocsConfig = await getTanstackDocsConfig(repo, branch) | ||
|
||
return json({ | ||
tanstackDocsConfig, | ||
version, | ||
}) | ||
} | ||
|
||
export const meta: MetaFunction = () => { | ||
return seo({ | ||
title: 'TanStack Ranger Docs | React Ranger', | ||
description: 'Modern and headless ranger UI library', | ||
}) | ||
} | ||
|
||
export default function DocsRoute() { | ||
const { version, tanstackDocsConfig } = useLoaderData<typeof loader>() | ||
let config = useRangerDocsConfig(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> | ||
) | ||
} |
Oops, something went wrong.
f9b7ff9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
tanstack-com – ./
tanstack-com.vercel.app
tanstack-com-tanstack.vercel.app
tanstack-com-git-main-tanstack.vercel.app
tanstack.com