-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrate virtual docs to v2 layout (#152)
* feat: Migrate virtual docs to v2 layout * Remove reference to v3branch * Fix redirect * Remove useless string literal
- Loading branch information
1 parent
7ff1748
commit f1fca89
Showing
14 changed files
with
259 additions
and
189 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,80 @@ | ||
import { Link } from '@remix-run/react' | ||
import reactLogo from '~/images/react-logo.svg' | ||
import solidLogo from '~/images/solid-logo.svg' | ||
import vueLogo from '~/images/vue-logo.svg' | ||
import svelteLogo from '~/images/svelte-logo.svg' | ||
import { FaDiscord, FaGithub } from 'react-icons/fa' | ||
import { useDocsConfig, type ConfigSchema, type MenuItem } from '~/utils/config' | ||
|
||
export const repo = 'tanstack/virtual' | ||
|
||
export const v3branch = 'main' | ||
export const latestBranch = 'main' | ||
export const latestVersion = 'v3' | ||
export const availableVersions = ['v3'] | ||
|
||
export const gradientText = | ||
'inline-block text-transparent bg-clip-text bg-gradient-to-r from-rose-500 to-violet-600' | ||
|
||
const frameworks = { | ||
react: { label: 'React', logo: reactLogo, value: 'react' }, | ||
solid: { label: 'Solid', logo: solidLogo, value: 'solid' }, | ||
svelte: { label: 'Svelte', logo: svelteLogo, value: 'svelte' }, | ||
vue: { label: 'Vue', logo: vueLogo, value: 'vue' }, | ||
} as const | ||
|
||
export type Framework = keyof typeof frameworks | ||
|
||
export function getBranch(argVersion?: string) { | ||
const version = argVersion || latestVersion | ||
|
||
return ['latest', latestVersion].includes(version) ? latestBranch : version | ||
} | ||
|
||
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/virtual', | ||
}, | ||
{ | ||
label: ( | ||
<div className="flex items-center gap-2"> | ||
Discord <FaDiscord className="text-lg opacity-20" /> | ||
</div> | ||
), | ||
to: 'https://tlinz.com/discord', | ||
}, | ||
], | ||
} | ||
|
||
export const createLogo = (version?: string) => ( | ||
<> | ||
<Link to="/" className="font-light"> | ||
TanStack | ||
</Link> | ||
<Link to=".." className="font-bold"> | ||
<span className={`${gradientText}`}>Virtual</span>{' '} | ||
<span className="text-sm align-super"> | ||
{version === 'latest' ? latestVersion : version} | ||
</span> | ||
</Link> | ||
</> | ||
) | ||
|
||
export const useVirtualDocsConfig = (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/virtual' | ||
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/introduction'), | ||
}) | ||
} | ||
|
||
export const meta: MetaFunction<typeof loader> = ({ data }) => { | ||
return seo({ | ||
title: `${data?.title ?? 'Docs'} | TanStack Virtual 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} | ||
/> | ||
) | ||
} |
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
45 changes: 45 additions & 0 deletions
45
app/routes/virtual.$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/virtual' | ||
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/introduction'), | ||
}) | ||
} | ||
|
||
export const meta: MetaFunction<typeof loader> = ({ data }) => { | ||
return seo({ | ||
title: `${data?.title} | TanStack Virtual 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/virtual.$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/introduction')) | ||
} |
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,51 @@ | ||
import { Outlet, json, useLoaderData } from '@remix-run/react' | ||
import { | ||
createLogo, | ||
getBranch, | ||
repo, | ||
useVirtualDocsConfig, | ||
} from '~/projects/virtual' | ||
import { seo } from '~/utils/seo' | ||
import { DocsLayout } from '~/components/DocsLayout' | ||
import { getTanstackDocsConfig } from '~/utils/config' | ||
import type { LoaderFunctionArgs, MetaFunction } from '@remix-run/node' | ||
|
||
export const loader = async (context: LoaderFunctionArgs) => { | ||
const version = context.params.version | ||
const branch = getBranch(version) | ||
const tanstackDocsConfig = await getTanstackDocsConfig(repo, branch) | ||
|
||
return json({ | ||
tanstackDocsConfig, | ||
version, | ||
}) | ||
} | ||
|
||
export const meta: MetaFunction = () => { | ||
return seo({ | ||
title: | ||
'TanStack Virtual Docs | React Virtual, Solid Virtual, Svelte Virtual, Vue Virtual', | ||
description: | ||
'Headless UI for virtualizing long scrollable lists with TS/JS, React, Solid, Svelte and Vue', | ||
}) | ||
} | ||
|
||
export default function RouteVirtual() { | ||
const { version, tanstackDocsConfig } = useLoaderData<typeof loader>() | ||
let config = useVirtualDocsConfig(tanstackDocsConfig) | ||
|
||
return ( | ||
<DocsLayout | ||
v2={true} | ||
logo={createLogo(version)} | ||
colorFrom={'from-rose-500'} | ||
colorTo={'to-violet-500'} | ||
textColor={'text-violet-500'} | ||
config={config} | ||
framework={config.frameworkConfig} | ||
version={config.versionConfig} | ||
> | ||
<Outlet /> | ||
</DocsLayout> | ||
) | ||
} |
Oops, something went wrong.
f1fca89
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
tanstack-com-git-main-tanstack.vercel.app