The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Change the way we read available versions
Joshen Lim2eecdaab24a8
diff --git a/apps/temp-docs/components/Navigation/NavBar.tsx b/apps/temp-docs/components/Navigation/NavBar.tsxindex 4d35ee4d5e4..6b5acba1d00 100644--- a/apps/temp-docs/components/Navigation/NavBar.tsx+++ b/apps/temp-docs/components/Navigation/NavBar.tsx@@ -4,19 +4,23 @@ import { useRouter } from 'next/router'import { useState, useEffect, FC } from 'react'import { IconMenu, IconSearch, Input, IconCommand, Button, IconMoon, IconSun, Listbox } from 'ui'import { useTheme } from '../Providers'+import { REFERENCES } from './Navigation.constants'interface Props {currentPage: string- versions: string[]}-const NavBar: FC<Props> = ({ currentPage, versions }) => {+const NavBar: FC<Props> = ({ currentPage }) => {const { isDarkMode, toggleTheme } = useTheme()const [mounted, setMounted] = useState(false)const { asPath, push } = useRouter()const pathSegments = asPath.split('/')+const library = pathSegments.length >= 3 ? pathSegments[2] : undefined+ const libraryMeta = REFERENCES?.[library] ?? undefined+ const versions = libraryMeta?.versions ?? []+const version = versions.includes(pathSegments[pathSegments.indexOf(library) + 1])? pathSegments[pathSegments.indexOf(library) + 1]: versions[0]diff --git a/apps/temp-docs/components/Navigation/Navigation.constants.ts b/apps/temp-docs/components/Navigation/Navigation.constants.tsindex be47bb3933c..6815a1bbb6c 100644--- a/apps/temp-docs/components/Navigation/Navigation.constants.ts+++ b/apps/temp-docs/components/Navigation/Navigation.constants.ts@@ -13,21 +13,25 @@ export const REFERENCES: References = {javascript: {name: 'supabase-js',library: 'supabase-js',+ versions: ['v2', 'v1'],icon: '/docs/img/libraries/javascript-icon.svg',},dart: {name: 'Flutter',library: 'supabase-dart',+ versions: ['v1', 'v0'],icon: '/docs/img/libraries/dart-icon.svg',},cli: {name: 'CLI',library: undefined,+ versions: [],icon: '/docs/img/libraries/cli-icon.svg',},api: {name: 'API',library: undefined,+ versions: [],icon: '/docs/img/libraries/api-icon.svg',},}diff --git a/apps/temp-docs/components/Navigation/Navigation.types.ts b/apps/temp-docs/components/Navigation/Navigation.types.tsindex 91617d172ff..3422099a2ae 100644--- a/apps/temp-docs/components/Navigation/Navigation.types.ts+++ b/apps/temp-docs/components/Navigation/Navigation.types.ts@@ -17,6 +17,7 @@ export interface References {[key: string]: {name: stringlibrary?: string+ versions: string[]icon: string}}diff --git a/apps/temp-docs/data/nav/README.md b/apps/temp-docs/data/nav/README.mdindex 521203dfe5d..452165a6740 100644--- a/apps/temp-docs/data/nav/README.md+++ b/apps/temp-docs/data/nav/README.md@@ -1,11 +1,13 @@# [WIP] Adding navigation for a new section+[Note] This isn't the best way for versioning in my opinion, but this is the current way to do it while we're migrating to Next.js+This folder holds the structure for the side navigation menu in the reference documentation pages. Each reference section (as well as their individual versions where applicable) have its own set of navigation.The following are relevant to adding navigation for a new section:- `getPageType()` from `lib/helpers`-- `menuItems` from `components/Navigation/Navigation.constants`+- `menuItems` and `REFERENCES` from `components/Navigation/Navigation.constants`- `NavMenu` from `components/Navigation/Navigation.types`## Adding navigation for a section that doesn't require versioning@@ -18,9 +20,9 @@ Finally, add the menu to `menuItems` under a new key - the key should be what yo## Adding navigation for a section that requires versioning-This is more applicable for client libraries (e.g supabase-js and supabase-dart). Versions will all sit within their own folder - if the folder doesn't exist yet, just create one.+This is more applicable for client libraries (e.g supabase-js and supabase-dart). Versions will all sit within their own folder - if the folder doesn't exist yet, just create one. The navigation for each section will then be named as 'v1', 'v2', and so on.-The navigation for each section will then be named as 'v1', 'v2', and so on. The version selector in `NavBar` will pick up what available versions there are from here.+Then, update `REFERENCES` accordingly.Thereafter, update `getPageType` to be able to get the page type based on the URL path - preferably follow the syntax of `reference/{section_name}/{version}`. Typically the latest version available will not have the `/{version}` in it.diff --git a/apps/temp-docs/layouts/Default.tsx b/apps/temp-docs/layouts/Default.tsxindex c6b07acc354..c4220745f8b 100644--- a/apps/temp-docs/layouts/Default.tsx+++ b/apps/temp-docs/layouts/Default.tsx@@ -10,17 +10,9 @@ interface Props {toc?: anymenuItems: anycurrentPage: string- versions: string[]}-const Layout: FC<Props> = ({- meta,- children,- toc,- menuItems,- currentPage,- versions = ['v2', 'v1'],-}) => {+const Layout: FC<Props> = ({ meta, children, toc, menuItems, currentPage }) => {useEffect(() => {const key = localStorage.getItem('supabaseDarkMode')if (!key) {@@ -53,7 +45,7 @@ const Layout: FC<Props> = ({</Head><main>- <NavBar currentPage={currentPage} versions={versions} />+ <NavBar currentPage={currentPage} /><div className="flex w-full flex-row"><SideBar menuItems={menuItems} /><div className="docs-width grid grid-cols-12 gap-4 justify-between p-4 pb-8 w-full">diff --git a/apps/temp-docs/lib/docs.ts b/apps/temp-docs/lib/docs.tsindex 7942f7ac243..7612b4b00c4 100644--- a/apps/temp-docs/lib/docs.ts+++ b/apps/temp-docs/lib/docs.ts@@ -63,19 +63,6 @@ export function getAllDocs() {return docs}-export function getLibraryVersions(slug: string) {- const paths = slug.split('/')- if (paths.includes('reference') && paths.length >= 3) {- const reference = REFERENCES[paths[2]]- if (reference?.library !== undefined) {- const path = `data/nav/${reference.library}`- const list = fs.readdirSync(path).map((file) => file.split('.')[0])- return list.reverse()- }- }- return []-}-function walk(dir: string) {let results: string[] = []const list = fs.readdirSync(dir)@@ -92,3 +79,18 @@ function walk(dir: string) {})return results}++// [Joshen] Initially tried to simplify the NavBar versioning by reading the directory+// but caused some issues on Vercel. Just gonna park this for now.+export function getLibraryVersions(slug: string) {+ const paths = slug.split('/')+ if (paths.includes('reference') && paths.length >= 3) {+ const reference = REFERENCES[paths[2]]+ if (reference?.library !== undefined) {+ const path = `data/nav/${reference.library}`+ const list = fs.readdirSync(path).map((file) => file.split('.')[0])+ return list.reverse()+ }+ }+ return []+}diff --git a/apps/temp-docs/pages/[...slug].tsx b/apps/temp-docs/pages/[...slug].tsxindex 5a55099aa94..3a1c8a90c0c 100644--- a/apps/temp-docs/pages/[...slug].tsx+++ b/apps/temp-docs/pages/[...slug].tsx@@ -5,7 +5,7 @@ import { serialize } from 'next-mdx-remote/serialize'import components from '../components/index'import { menuItems } from '../components/Navigation/Navigation.constants'import { getPageType } from '../lib/helpers'-import { getAllDocs, getDocsBySlug, getLibraryVersions } from '../lib/docs'+import { getAllDocs, getDocsBySlug } from '../lib/docs'import Layout from '~/layouts/Default'// table of contents extractor@@ -21,7 +21,6 @@ interface Meta {interface Props {meta: Metacontent: any- // versions: string[]toc: any}@@ -50,13 +49,11 @@ export async function getStaticProps({ params }: { params: { slug: string[] } })let doc = getDocsBySlug(slug)const content = await serialize(doc.content || '')- // const versions = getLibraryVersions(slug)return {props: {...doc,content,- // versions,toc: toc(doc.content, { maxdepth: 2 }),},}diff --git a/apps/temp-docs/pages/index.tsx b/apps/temp-docs/pages/index.tsxindex d11b16a831b..7be96f8bb61 100644--- a/apps/temp-docs/pages/index.tsx+++ b/apps/temp-docs/pages/index.tsx@@ -13,9 +13,8 @@ export default function Home({meta: { title: string; description: string }content: any}) {- console.log({ menuItems }, 'index')return (- <Layout meta={meta} menuItems={menuItems['docs']} currentPage="docs" versions={[]}>+ <Layout meta={meta} menuItems={menuItems['docs']} currentPage="docs"><MDXProvider components={components}><MDXRemote {...content} /></MDXProvider>