-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Migrate query docs to v2 layout (#151)
* feat: Migrate query docs to v2 layout * Remove string literal
- Loading branch information
1 parent
33ef71e
commit 7ff1748
Showing
13 changed files
with
235 additions
and
361 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,37 +1,83 @@ | ||
import { FaDiscord, FaGithub } from 'react-icons/fa' | ||
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 angularLogo from '~/images/angular-logo.svg' | ||
import { useDocsConfig } from '~/utils/config' | ||
import { Link } from '@remix-run/react' | ||
import type { ConfigSchema, MenuItem } from '~/utils/config' | ||
|
||
export const repo = 'tanstack/query' | ||
|
||
export const latestBranch = 'main' | ||
export const latestVersion = 'v5' | ||
export const availableVersions = ['v5', 'v4', 'v3'] | ||
|
||
export const gradientText = | ||
'inline-block text-transparent bg-clip-text bg-gradient-to-r from-red-500 to-amber-500' | ||
|
||
export const repo = 'tanstack/query' | ||
export const frameworks = { | ||
react: { label: 'React', logo: reactLogo, value: 'react' }, | ||
solid: { label: 'Solid', logo: solidLogo, value: 'solid' }, | ||
vue: { label: 'Vue', logo: vueLogo, value: 'vue' }, | ||
svelte: { label: 'Svelte', logo: svelteLogo, value: 'svelte' }, | ||
angular: { label: 'Angular', logo: angularLogo, value: 'angular' }, | ||
} as const | ||
|
||
const latestBranch = 'main' | ||
export type Framework = keyof typeof frameworks | ||
|
||
export const latestVersion = 'v5' | ||
export const createLogo = (version?: string) => ( | ||
<> | ||
<Link to="/" className="font-light"> | ||
TanStack | ||
</Link> | ||
<Link to=".." className="font-bold"> | ||
<span className={`${gradientText}`}>Query</span>{' '} | ||
<span className="text-sm align-super"> | ||
{version === 'latest' ? latestVersion : version} | ||
</span> | ||
</Link> | ||
</> | ||
) | ||
|
||
export const availableVersions = [ | ||
{ | ||
name: 'v5', | ||
branch: latestBranch, | ||
}, | ||
{ | ||
name: 'v4', | ||
branch: 'v4', | ||
}, | ||
{ | ||
name: 'v3', | ||
branch: 'v3', | ||
}, | ||
] as const | ||
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/${repo}`, | ||
}, | ||
{ | ||
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 | ||
|
||
if (version === 'latest') { | ||
return latestBranch | ||
} | ||
|
||
return ( | ||
availableVersions.find((v) => v.name === version)?.branch ?? latestBranch | ||
) | ||
return ['latest', latestVersion].includes(version) ? latestBranch : version | ||
} | ||
|
||
export type Framework = 'angular' | 'react' | 'svelte' | 'vue' | 'solid' | ||
export const useQueryDocsConfig = (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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { LoaderFunctionArgs, MetaFunction } from '@remix-run/node' | ||
import { repo, getBranch } from '~/projects/query' | ||
import { DefaultErrorBoundary } from '~/components/DefaultErrorBoundary' | ||
import { seo } from '~/utils/seo' | ||
import { useLoaderData, useParams } from '@remix-run/react' | ||
import { loadDocs } from '~/utils/docs' | ||
import { Doc } from '~/components/Doc' | ||
|
||
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/framework/react/overview'), | ||
}) | ||
} | ||
|
||
export const meta: MetaFunction<typeof loader> = ({ data }) => { | ||
return seo({ | ||
title: `${data?.title} | TanStack Query 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} | ||
/> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
7ff1748
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