diff --git a/app/projects/ranger.tsx b/app/projects/ranger.tsx index 8e655c4d..1a73ae82 100644 --- a/app/projects/ranger.tsx +++ b/app/projects/ranger.tsx @@ -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) => ( + <> + + TanStack + + + Ranger{' '} + + {version === 'latest' ? latestVersion : version} + + + +) + +const localMenu: MenuItem = { + label: 'Menu', + children: [ + { + label: 'Home', + to: '..', + }, + { + label: ( +
+ GitHub +
+ ), + to: 'https://github.com/tanstack/ranger', + }, + { + label: ( +
+ Discord +
+ ), + 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, + }) +} diff --git a/app/routes/ranger.$.tsx b/app/routes/ranger.$.tsx index 35cec549..34ad5bec 100644 --- a/app/routes/ranger.$.tsx +++ b/app/routes/ranger.$.tsx @@ -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[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') } diff --git a/app/routes/ranger.v1._index.tsx b/app/routes/ranger.$version._index.tsx similarity index 96% rename from app/routes/ranger.v1._index.tsx rename to app/routes/ranger.$version._index.tsx index 6dee03d4..c1872dcd 100644 --- a/app/routes/ranger.v1._index.tsx +++ b/app/routes/ranger.$version._index.tsx @@ -7,17 +7,17 @@ import { FaGithub, FaTshirt, } from 'react-icons/fa' -import { Link, useLoaderData } from '@remix-run/react' +import { Link, useLoaderData, useParams } from '@remix-run/react' import { json } from '@remix-run/node' import { TbHeartHandshake, TbZoomQuestion } from 'react-icons/tb' import { VscPreview } from 'react-icons/vsc' import { RiLightbulbFlashLine } from 'react-icons/ri' -import { gradientText, v1branch } from '~/projects/ranger' +import { gradientText, getBranch } from '~/projects/ranger' import { Carbon } from '~/components/Carbon' import { Footer } from '~/components/Footer' import SponsorPack from '~/components/SponsorPack' import { getSponsorsForSponsorPack } from '~/server/sponsors' -import type { LoaderFunction } from '@remix-run/node' +import type { Framework } from '~/projects/ranger' const menu = [ { @@ -70,7 +70,7 @@ const menu = [ }, ] -export const loader: LoaderFunction = async () => { +export const loader = async () => { const sponsors = await getSponsorsForSponsorPack() return json({ @@ -80,10 +80,9 @@ export const loader: LoaderFunction = async () => { export default function TanStackRouterRoute() { const { sponsors } = useLoaderData() - const [framework] = React.useState< - 'react' | 'preact' | 'svelte' | 'vue' | 'solid' - >('react') - + const { version } = useParams() + const branch = getBranch(version) + const [framework] = React.useState('react') const [isDark, setIsDark] = React.useState(true) React.useEffect(() => { @@ -317,7 +316,7 @@ export default function TanStackRouterRoute() {