From f9b7ff9166ee7bde9f41de7607e9cbac7dfcc1a2 Mon Sep 17 00:00:00 2001
From: Lachlan Collins <1667261+lachlancollins@users.noreply.github.com>
Date: Fri, 26 Jan 2024 08:27:55 +1100
Subject: [PATCH] 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
---
app/projects/ranger.tsx | 71 +++++++++++++++-
app/routes/ranger.$.tsx | 31 +------
...._index.tsx => ranger.$version._index.tsx} | 17 ++--
app/routes/ranger.$version.docs.$.tsx | 44 ++++++++++
...ex.tsx => ranger.$version.docs._index.tsx} | 0
...r.$version.docs.framework.$framework.$.tsx | 45 ++++++++++
...rsion.docs.framework.$framework._index.tsx | 6 ++
....docs.framework.$framework.examples.$.tsx} | 28 +++----
....framework.$framework.examples._index.tsx} | 4 +-
app/routes/ranger.$version.docs.tsx | 55 ++++++++++++
.../{ranger.v1.tsx => ranger.$version.tsx} | 5 ++
app/routes/ranger.tsx | 7 +-
app/routes/ranger.v1.docs.$.tsx | 67 ---------------
app/routes/ranger.v1.docs.tsx | 83 -------------------
14 files changed, 255 insertions(+), 208 deletions(-)
rename app/routes/{ranger.v1._index.tsx => ranger.$version._index.tsx} (96%)
create mode 100644 app/routes/ranger.$version.docs.$.tsx
rename app/routes/{ranger.v1.docs._index.tsx => ranger.$version.docs._index.tsx} (100%)
create mode 100644 app/routes/ranger.$version.docs.framework.$framework.$.tsx
create mode 100644 app/routes/ranger.$version.docs.framework.$framework._index.tsx
rename app/routes/{ranger.v1.docs.examples.$.tsx => ranger.$version.docs.framework.$framework.examples.$.tsx} (76%)
rename app/routes/{ranger.v1.docs.examples._index.tsx => ranger.$version.docs.framework.$framework.examples._index.tsx} (61%)
create mode 100644 app/routes/ranger.$version.docs.tsx
rename app/routes/{ranger.v1.tsx => ranger.$version.tsx} (90%)
delete mode 100644 app/routes/ranger.v1.docs.$.tsx
delete mode 100644 app/routes/ranger.v1.docs.tsx
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() {