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

feat: new docs ia #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion apps/docs/app/contributing/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default async function ContributingPage() {
const content = await readFile(contentFile, 'utf-8')

return (
<SidebarSkeleton>
<SidebarSkeleton hideSideNav>
<div className="px-8 py-16">
<article className="prose mx-auto">
<MDXProviderGuides>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import matter from 'gray-matter'
import { type Heading } from 'mdast'
import { fromMarkdown } from 'mdast-util-from-markdown'
import { toMarkdown } from 'mdast-util-to-markdown'
import { type SerializeOptions } from 'next-mdx-remote/dist/types'
import { readFile } from 'node:fs/promises'
import { join, relative } from 'node:path'
import rehypeSlug from 'rehype-slug'
import emoji from 'remark-emoji'

import { genGuideMeta, genGuidesStaticParams } from '~/features/docs/GuidesMdx.utils'
import {
genGuideMeta,
genGuidesStaticParams,
removeRedundantH1,
} from '~/features/docs/GuidesMdx.utils'
import { GuideTemplate, newEditLink } from '~/features/docs/GuidesMdx.template'
import { fetchRevalidatePerDay } from '~/features/helpers.fetch'
import { GUIDES_DIRECTORY, isValidGuideFrontmatter } from '~/lib/docs'
import { UrlTransformFunction, linkTransform } from '~/lib/mdx/plugins/rehypeLinkTransform'
import remarkMkDocsAdmonition from '~/lib/mdx/plugins/remarkAdmonition'
import { removeTitle } from '~/lib/mdx/plugins/remarkRemoveTitle'
import remarkPyMdownTabs from '~/lib/mdx/plugins/remarkTabs'
import remarkGfm from 'remark-gfm'

// We fetch these docs at build time from an external repo
const org = 'supabase'
Expand Down Expand Up @@ -184,22 +184,7 @@ const getContent = async (params: Params) => {
const rawContent = await response.text()

const { content: contentWithoutFrontmatter } = matter(rawContent)

// This is the more robust way of doing it, but problems with the rewritten
// Markdown and handling of tables this way, so saving it for later.
//
// const mdxTree = fromMarkdown(contentWithoutFrontmatter)
// const maybeH1 = mdxTree.children[0]
// if (maybeH1 && maybeH1.type === 'heading' && (maybeH1 as Heading).depth === 1) {
// mdxTree.children.shift()
// }
// content = toMarkdown(mdxTree)

content = contentWithoutFrontmatter
if (meta.title) {
const h1Regex = new RegExp(`(?:^|\n)# ${meta.title}\n+`)
content = content.replace(h1Regex, '')
}
content = removeRedundantH1(contentWithoutFrontmatter)
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { notFound } from 'next/navigation'
import { relative } from 'node:path'
import rehypeSlug from 'rehype-slug'

import { genGuideMeta } from '~/features/docs/GuidesMdx.utils'
import { genGuideMeta, removeRedundantH1 } from '~/features/docs/GuidesMdx.utils'
import { GuideTemplate, newEditLink } from '~/features/docs/GuidesMdx.template'
import { fetchRevalidatePerDay } from '~/features/helpers.fetch'
import { UrlTransformFunction, linkTransform } from '~/lib/mdx/plugins/rehypeLinkTransform'
Expand Down Expand Up @@ -83,7 +83,7 @@ const getContent = async ({ slug }: Params) => {
`https://raw.githubusercontent.com/${org}/${repo}/${branch}/${docsDir}/${remoteFile}`
)

const content = await response.text()
const content = removeRedundantH1(await response.text())

return {
pathname: `/guides/cli/github-action/${slug}` satisfies `/${string}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type SerializeOptions } from 'next-mdx-remote/dist/types'
import { notFound } from 'next/navigation'
import rehypeSlug from 'rehype-slug'

import { genGuideMeta } from '~/features/docs/GuidesMdx.utils'
import { genGuideMeta, removeRedundantH1 } from '~/features/docs/GuidesMdx.utils'
import { GuideTemplate, newEditLink } from '~/features/docs/GuidesMdx.template'
import { fetchRevalidatePerDay } from '~/features/helpers.fetch'
import { isValidGuideFrontmatter } from '~/lib/docs'
Expand Down Expand Up @@ -119,7 +119,11 @@ const getContent = async ({ slug }: Params) => {
let rawContent = await response.text()
// Strip out HTML comments
rawContent = rawContent.replace(/<!--.*?-->/, '')
const { content, data } = matter(rawContent)
let { content, data } = matter(rawContent)

// Remove the title from the content so it isn't duplicated in the final display
content = removeRedundantH1(content)

Object.assign(meta, data)

if (!isValidGuideFrontmatter(meta)) {
Expand Down
29 changes: 21 additions & 8 deletions apps/docs/app/guides/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
'use client'

import { usePathname } from 'next/navigation'
import { type PropsWithChildren } from 'react'

import { getMenuId } from '~/components/Navigation/NavigationMenu/NavigationMenu.utils'
import { supabaseMisc } from '~/lib/supabaseMisc'
import Layout from '~/layouts/guides'

const GuidesLayout = ({ children }: PropsWithChildren) => {
const pathname = usePathname()
const menuId = getMenuId(pathname)
const GuidesLayout = async ({ children }: PropsWithChildren) => {
const partners = await getPartners()
const partnerNavItems = partners.map((partner) => ({
name: partner.title,
url: `https://supabase.com/partners/integrations/${partner.slug}` as `https://${string}`,
}))

return <Layout additionalNavItems={partnerNavItems}>{children}</Layout>
}

async function getPartners() {
const { data, error } = await supabaseMisc()
.from('partners')
.select('slug, title')
.eq('type', 'technology')
.order('title')
if (error) {
console.error(new Error('Error fetching partners', { cause: error }))
}

return <Layout menuId={menuId}>{children}</Layout>
return data ?? []
}

export default GuidesLayout
5 changes: 3 additions & 2 deletions apps/docs/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import '../styles/main.scss'
import '../styles/new-docs.scss'
import '../styles/prism-okaidia.scss'

import { genFaviconData } from 'common/MetaFavicons/app-router'
import { type Metadata, type Viewport } from 'next'

import { BASE_PATH, IS_PRODUCTION } from '~/lib/constants'
import { genFaviconData } from 'common/MetaFavicons/app-router'

import { GlobalProviders } from '~/features/app.providers'
import { TopNavSkeleton } from '~/layouts/MainSkeleton'
import { BASE_PATH, IS_PRODUCTION } from '~/lib/constants'

const metadata: Metadata = {
applicationName: 'Supabase Docs',
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/components/Navigation/Navigation.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface NavMenuGroup {

export interface NavMenuSection {
name: string
url?: `/${string}`
url?: `/${string}` | `https://${string}`
items: Partial<NavMenuSection>[]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Heart, Server } from 'lucide-react'

import {
IconBranching,
IconGitHub,
Expand Down Expand Up @@ -85,8 +87,12 @@ function getMenuIcon(menuKey: string, width: number = 16, height: number = 16, c
return <IconGitHub width={width} height={height} className={className} />
case 'support':
return <IconSupport width={width} height={height} className={className} />
case 'contributing':
case 'troubleshooting':
return <IconTroubleshooting width={width} height={height} className={className} />
case 'contributing':
return <Heart width={width} height={height} className={className} />
case 'deployment':
return <Server width={width} height={height} className={className} />
default:
return <IconMenuPlatform width={width} height={height} className={className} />
}
Expand Down
Loading