Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: migrate guides to app router #23101

Merged
merged 66 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
d307f0c
fix: make preview constant available on client
charislam Mar 1, 2024
8cb4703
refactor: start moving layout to app router
charislam Mar 1, 2024
70bf962
refactor: get homepage mostly working with app router
charislam Mar 1, 2024
0c17862
fix: fix all typing issues blocking build
charislam Mar 1, 2024
1581847
perf: push client components down a bit further on homepage
charislam Apr 19, 2024
d6795bd
feat: get auth section minimally building
charislam Apr 20, 2024
4312780
fix: restore codehike
charislam Apr 20, 2024
a25e96d
maintain,enhance: factor out template for all mdx guides
charislam Apr 20, 2024
a5ef29c
enhance(maintainability): convert other guides to app router
charislam Apr 21, 2024
993f14d
enhance(performance): pregenerate all app router routes
charislam Apr 21, 2024
442fd69
fix(usability): restore scroll to top on navigation
charislam Apr 21, 2024
876e1cc
dev,enh: finish migrating all guides to app router
charislam Apr 21, 2024
8f3a7b0
use,feat: helpful error pages
charislam Apr 22, 2024
57a5ec8
dev,fix: format
charislam Apr 22, 2024
815a5b9
enhance(develop): factor out guides into single layout and page
charislam Apr 22, 2024
79d4342
fix(develop): format
charislam Apr 22, 2024
cdf3f07
fix(usability): prettify top-level error page
charislam Apr 22, 2024
b3b785c
fix(dx): fix types
charislam Apr 22, 2024
1dbe255
enhance(ux): improve ux of error pages and not found
charislam Apr 23, 2024
4ffbfa4
enhance(ux): add catch-all not-found redirect
charislam Apr 23, 2024
5557bd7
temp test: REVERT THIS
charislam Apr 23, 2024
a67d7a8
Revert "temp test: REVERT THIS"
charislam Apr 23, 2024
cd64e70
fix(mktg): fix meta
charislam Apr 23, 2024
e63b8b1
fix(ux): fix mobile nav visibility
charislam Apr 23, 2024
4e01da9
enhance(dx): cleanup
charislam Apr 23, 2024
1cdeacf
rework tabs query state to work better across both routers
charislam Apr 24, 2024
a1d6220
refactor ui imports
charislam Apr 26, 2024
8490850
clean up
charislam Apr 26, 2024
370c81d
Merge branch 'master' into refactor/app-router
charislam Apr 30, 2024
419b937
Merge branch 'master' into refactor/app-router
charislam May 1, 2024
3eb306b
Merge branch 'master' into refactor/app-router
charislam May 2, 2024
b9545a6
fix database-new build
charislam May 2, 2024
8b1f351
revert strict tsconfig
charislam May 2, 2024
d1a0968
remove cache bc it might be unnecessarily complicated
charislam May 4, 2024
5b32790
Revert "remove cache bc it might be unnecessarily complicated"
charislam May 4, 2024
b4fd763
fix cache
charislam May 4, 2024
02512c7
Merge branch 'master' into refactor/app-router
charislam May 6, 2024
d8ee0cf
style: format
charislam May 6, 2024
66db1b4
Merge branch 'master' into refactor/app-router
charislam May 7, 2024
b10ec4c
Merge branch 'master' into refactor/app-router
charislam May 8, 2024
25ee40a
Merge branch 'master' into refactor/app-router
charislam May 9, 2024
6dd6956
Merge branch 'master' into refactor/app-router
charislam May 10, 2024
70ad823
Merge branch 'master' into refactor/app-router
charislam May 22, 2024
4e2bf19
Merge branch 'master' into refactor/app-router
charislam May 22, 2024
0afd746
Merge branch 'master' into refactor/app-router
charislam May 23, 2024
d3f395f
Merge branch 'master' into refactor/app-router
charislam May 29, 2024
41ac9ec
Merge branch 'master' into refactor/app-router
charislam Jun 4, 2024
8f0c7f6
Merge branch 'master' into refactor/app-router
charislam Jun 4, 2024
e10b543
Merge branch 'master' into refactor/app-router
charislam Jun 5, 2024
90ceffb
Merge branch 'master' into refactor/app-router
charislam Jun 6, 2024
f5057cb
Merge branch 'master' into refactor/app-router
charislam Jun 7, 2024
2a13a2c
Merge branch 'master' into refactor/app-router
charislam Jun 10, 2024
2c39244
Merge branch 'master' into refactor/app-router
charislam Jun 11, 2024
4d2c5d2
Merge branch 'master' into refactor/app-router
charislam Jun 12, 2024
f1ee36c
fix build failures
charislam Jun 12, 2024
1f3e8a5
Merge branch 'master' into refactor/app-router
charislam Jun 17, 2024
69e479a
Merge branch 'master' into refactor/app-router
charislam Jun 20, 2024
c0b0c68
Merge branch 'master' into refactor/app-router
charislam Jun 25, 2024
c26d2c1
Merge branch 'master' into refactor/app-router
charislam Jun 25, 2024
5afee61
Merge branch 'master' into refactor/app-router
charislam Jun 28, 2024
d39f6f2
fix: minor fixes
charislam Jun 28, 2024
043f0dd
fix: remove duplicated page
charislam Jun 28, 2024
ffe5b2d
fix: suggestions from code review
charislam Jul 1, 2024
5a272dc
Merge branch 'master' into refactor/app-router
charislam Jul 3, 2024
6b999ec
test vercel 500 fix
charislam Jul 3, 2024
5179bcf
fix: not-found page meta
charislam Jul 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions apps/docs/app/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use client'

import Link from 'next/link'
import { Button } from 'ui'

const ErrorPage = () => (
<div className="h-full w-full flex flex-col gap-8 p-8 items-center justify-center">
<span className="text-center text-5xl text-foreground-lighter">
Sorry, something went wrong
</span>
<Button asChild type="secondary" className="w-fit p-4 text-lg">
<Link href="/">Return to homepage</Link>
</Button>
</div>
)

export default ErrorPage
19 changes: 19 additions & 0 deletions apps/docs/app/guides/[...slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {
getGuidesMarkdown,
genGuideMeta,
genGuidesStaticParams,
} from '~/features/docs/GuidesMdx.utils'
import { GuideTemplate } from '~/features/docs/GuidesMdx.template'

type Params = { slug: string[] }

const GuidePage = async ({ params }: { params: Params }) => {
const data = await getGuidesMarkdown(params)
return <GuideTemplate {...data!} />
}

const generateStaticParams = genGuidesStaticParams()
const generateMetadata = genGuideMeta(getGuidesMarkdown)

export default GuidePage
export { generateStaticParams, generateMetadata }
133 changes: 133 additions & 0 deletions apps/docs/app/guides/ai/python/[slug]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import { type SerializeOptions } from 'next-mdx-remote/dist/types'
import { redirect } from 'next/navigation'
import { relative } from 'path'
import rehypeSlug from 'rehype-slug'
import { genGuideMeta } from '~/features/docs/GuidesMdx.utils'
import { GuideTemplate, newEditLink } from '~/features/docs/GuidesMdx.template'
import { notFoundLink } from '~/features/recommendations/NotFound.utils'
import { UrlTransformFunction, linkTransform } from '~/lib/mdx/plugins/rehypeLinkTransform'
import remarkMkDocsAdmonition from '~/lib/mdx/plugins/remarkAdmonition'
import { removeTitle } from '~/lib/mdx/plugins/remarkRemoveTitle'

// We fetch these docs at build time from an external repo
const org = 'supabase'
const repo = 'vecs'
const branch = 'main'
const docsDir = 'docs'
const externalSite = 'https://supabase.github.io/vecs'

// Each external docs page is mapped to a local page
const pageMap = [
{
slug: 'api',
meta: {
title: 'API',
},
remoteFile: 'api.md',
},
{
slug: 'collections',
meta: {
title: 'Collections',
},
remoteFile: 'concepts_collections.md',
},
{
slug: 'indexes',
meta: {
title: 'Indexes',
},
remoteFile: 'concepts_indexes.md',
},
{
slug: 'metadata',
meta: {
title: 'Metadata',
},
remoteFile: 'concepts_metadata.md',
},
]

interface Params {
slug: string
}

const PythonClientDocs = async ({ params }: { params: Params }) => {
const { meta, ...data } = await getContent(params)

const options = {
mdxOptions: {
remarkPlugins: [remarkMkDocsAdmonition, [removeTitle, meta.title]],
rehypePlugins: [[linkTransform, urlTransform], rehypeSlug],
},
} as SerializeOptions

return <GuideTemplate mdxOptions={options} meta={meta} {...data} />
}

/**
* Fetch markdown from external repo
*/
const getContent = async ({ slug }: Params) => {
const page = pageMap.find(({ slug: validSlug }) => validSlug && validSlug === slug)

if (!page) {
redirect(notFoundLink(`api/python/${slug}`))
}

const { remoteFile, meta } = page

const editLink = newEditLink(`${org}/${repo}/blob/${branch}/${docsDir}/${remoteFile}`)

const response = await fetch(
`https://raw.githubusercontent.com/${org}/${repo}/${branch}/${docsDir}/${remoteFile}`
)

const content = await response.text()

return {
pathname: `/guides/ai/python/${slug}` satisfies `/${string}`,
meta,
content,
editLink,
}
}

const urlTransform: UrlTransformFunction = (url) => {
try {
const externalSiteUrl = new URL(externalSite)

const placeholderHostname = 'placeholder'
const { hostname, pathname, hash } = new URL(url, `http://${placeholderHostname}`)

// Don't modify a url with a FQDN or a url that's only a hash
if (hostname !== placeholderHostname || pathname === '/') {
return url
}

const relativePage = (
pathname.endsWith('.md')
? pathname.replace(/\.md$/, '')
: relative(externalSiteUrl.pathname, pathname)
).replace(/^\//, '')

const page = pageMap.find(({ remoteFile }) => `${relativePage}.md` === remoteFile)

// If we have a mapping for this page, use the mapped path
if (page) {
return page.slug + hash
}

// If we don't have this page in our docs, link to original docs
return `${externalSite}/${relativePage}${hash}`
} catch (err) {
console.error('Error transforming markdown URL', err)
return url
}
}

const generateStaticParams = () => pageMap.map(({ slug }) => ({ slug }))
const generateMetadata = genGuideMeta(getContent)

export default PythonClientDocs
export { generateStaticParams, generateMetadata }
Original file line number Diff line number Diff line change
@@ -1,60 +1,45 @@
import Head from 'next/head'
import ReactMarkdown from 'react-markdown'

import { CodeBlock, cn } from 'ui'

import { CodeBlock } from 'ui'
import { Heading } from 'ui/src/components/CustomHTMLElements'
import GuidesTableOfContents from '~/components/GuidesTableOfContents'
import { MenuId } from '~/components/Navigation/NavigationMenu/NavigationMenu'
import { MainSkeleton } from '~/layouts/MainSkeleton'
import { Parameter } from '~/lib/refGenerator/refTypes'
import { type TOCHeader } from '~/components/GuidesTableOfContents'
import { genGuideMeta } from '~/features/docs/GuidesMdx.utils'
import { GuideTemplate, newEditLink } from '~/features/docs/GuidesMdx.template'
import type { Parameter } from '~/lib/refGenerator/refTypes'
import specFile from '~/spec/cli_v1_config.yaml' assert { type: 'yml' }

// Parameters are grouped on the page by tag
const tocList = []
const content = specFile.info.tags.map((tag) => {
tocList.push({ text: tag.title, link: `${tag.id}-config`, level: 2 })
const meta = {
title: 'Supabase CLI config',
}

const generateMetadata = genGuideMeta(() => ({
pathname: '/guides/cli/config',
meta,
}))

const tocList: TOCHeader[] = []
const content = specFile.info.tags.map((tag: { id: string; title: string }, id: number) => {
tocList.push({ id: `${id}`, text: tag.title, link: `${tag.id}-config`, level: 2 })
return (
<div>
<Heading tag="h2">{tag.title} Config</Heading>
{specFile.parameters
.filter((param: Parameter) => param.tags[0] === tag.id)
.map((parameter: Parameter) => {
tocList.push({ text: parameter.id, link: `#${parameter.id}`, level: 3 })
.filter((param: Parameter) => param.tags && param.tags[0] === tag.id)
.map((parameter: Parameter, id: number) => {
tocList.push({ id: `${id}`, text: parameter.id, link: `#${parameter.id}`, level: 3 })
return <Info parameter={parameter} />
})}
</div>
)
})

export default function Config() {
const Config = () => {
const editLink = newEditLink('supabase/supabase/blob/master/apps/docs/spec/cli_v1_config.yaml')

return (
<>
<Head>
<title>Supabase CLI config</title>
</Head>
<MainSkeleton menuId={MenuId.Cli}>
<div className="grid grid-cols-12 relative gap-4 px-5 max-w-7xl mx-auto py-16">
<div className="relative col-span-12 md:col-span-9 transition-all ease-out duration-100">
<div className="w-full prose">
<h1>CLI configuration</h1>
<div className="max-w-xs w-32 h-[1px] bg-gradient-to-r from-brand-300 to-brand my-8"></div>
<ReactMarkdown>{specFile.info.description}</ReactMarkdown>
<div>{content}</div>
</div>
</div>
<GuidesTableOfContents
overrideToc={tocList}
className={cn(
'col-span-3 self-start',
'hidden md:block md:col-span-3',
'sticky top-[calc(var(--header-height,40px)+2rem)]',
'max-h-[calc(100vh-60px-5rem)]'
)}
/>
</div>
</MainSkeleton>
</>
<GuideTemplate meta={meta} editLink={editLink}>
<ReactMarkdown>{specFile.info.description}</ReactMarkdown>
<div>{content}</div>
</GuideTemplate>
)
}

Expand All @@ -81,7 +66,7 @@ function Info({ parameter }: { parameter: Parameter }) {
<tr>
<td>{parameter.id}</td>
<td>{parameter.default ? parameter.default.toString() : 'None'}</td>
<td>{parameter.required.toString()}</td>
<td>{parameter.required !== undefined && parameter.required.toString()}</td>
</tr>
</tbody>
</table>
Expand Down Expand Up @@ -116,3 +101,6 @@ function Info({ parameter }: { parameter: Parameter }) {
</div>
)
}

export default Config
export { generateMetadata }
Loading
Loading