From bc6dc86dab5859486557273465e0372b9d0ac209 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Thu, 4 May 2023 16:32:01 -0600 Subject: [PATCH 01/18] fix: prevent prefetch of hidden page links --- .../components/CustomHTMLElements/CustomHTMLElements.utils.ts | 3 +-- apps/docs/components/Navigation/NavigationMenu/HomeMenu.tsx | 4 ++++ .../Navigation/NavigationMenu/NavigationMenuGuideList.tsx | 4 ++++ .../NavigationMenu/NavigationMenuGuideListItems.tsx | 2 +- .../Navigation/NavigationMenu/NavigationMenuRefList.tsx | 4 ++++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/docs/components/CustomHTMLElements/CustomHTMLElements.utils.ts b/apps/docs/components/CustomHTMLElements/CustomHTMLElements.utils.ts index eb214e4963b..0103cef6aa7 100644 --- a/apps/docs/components/CustomHTMLElements/CustomHTMLElements.utils.ts +++ b/apps/docs/components/CustomHTMLElements/CustomHTMLElements.utils.ts @@ -79,7 +79,7 @@ export const unHighlightSelectedTocItems = () => { } export const highlightSelectedNavItem = (id: string) => { - const navMenuItems = document.querySelectorAll('.function-link-item a') + const navMenuItems = document.querySelectorAll('.function-link-item a') // find any currently active items and remove them const currentActiveItems = document.querySelectorAll('.function-link-list .text-brand-900') @@ -87,7 +87,6 @@ export const highlightSelectedNavItem = (id: string) => { // Add active class to the current item navMenuItems.forEach((item) => { - // @ts-ignore if (item.href.split('/').at(-1) === id) { item.classList.add('text-brand-900') } diff --git a/apps/docs/components/Navigation/NavigationMenu/HomeMenu.tsx b/apps/docs/components/Navigation/NavigationMenu/HomeMenu.tsx index db93e1616a2..b262cc1318c 100644 --- a/apps/docs/components/Navigation/NavigationMenu/HomeMenu.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/HomeMenu.tsx @@ -144,6 +144,10 @@ const NavigationMenuHome = ({ active }) => { const router = useRouter() const { isDarkMode } = useTheme() + if (!active) { + return null + } + return (
= ({ id, active, value }) => { const router = useRouter() + if (!active) { + return null + } + const menu = NavItems[id] // get url diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideListItems.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideListItems.tsx index 22a7d049827..6e8abf6a477 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideListItems.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideListItems.tsx @@ -121,7 +121,7 @@ const ContentLink = React.memo(function ContentLink(props: any) { return (
  • - + = ({ active, spec, }) => { + if (!active) { + return null + } + const filteredSections = commonSections.filter((section) => { return !section.excludes?.includes(id) }) From 6189cfa12d9cea7e8a490167e73d87137dc4c0ab Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Thu, 4 May 2023 16:47:28 -0600 Subject: [PATCH 02/18] feat: add font-display swap to prevent FOIT --- apps/docs/styles/main.scss | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apps/docs/styles/main.scss b/apps/docs/styles/main.scss index dedeb72ffd9..6f627fe2991 100644 --- a/apps/docs/styles/main.scss +++ b/apps/docs/styles/main.scss @@ -8,6 +8,7 @@ url(../../../packages/common/assets/fonts/CustomFont-Book.woff) format('woff'); font-weight: 400; font-style: normal; + font-display: swap; } @font-face { @@ -16,6 +17,7 @@ url(../../../packages/common/assets/fonts/CustomFont-Medium.woff) format('woff'); font-weight: 500; font-style: normal; + font-display: swap; } :root { From de1634a4a936649be7b60385085db9eadf493830 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Thu, 4 May 2023 17:53:39 -0600 Subject: [PATCH 03/18] chore(docs): bundle analyzer --- apps/docs/next.config.mjs | 19 +++++++++++++++---- apps/docs/package.json | 2 ++ package-lock.json | 16 +++++++++------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/apps/docs/next.config.mjs b/apps/docs/next.config.mjs index b3c71cae82e..029a3767707 100644 --- a/apps/docs/next.config.mjs +++ b/apps/docs/next.config.mjs @@ -6,6 +6,12 @@ import rehypeSlug from 'rehype-slug' import withTM from 'next-transpile-modules' import withYaml from 'next-plugin-yaml' +import configureBundleAnalyzer from '@next/bundle-analyzer' + +const withBundleAnalyzer = configureBundleAnalyzer({ + enabled: process.env.ANALYZE === 'true', +}) + // import admonitions from 'remark-admonitions' // import { remarkCodeHike } from '@code-hike/mdx' @@ -92,9 +98,14 @@ const nextConfig = { }, } -// next.config.js -export default () => { - // const plugins = [withMDX]/ - const plugins = [withTM(['ui', 'common', '@supabase/auth-helpers-nextjs']), withMDX, withYaml] +const configExport = () => { + const plugins = [ + withTM(['ui', 'common', '@supabase/auth-helpers-nextjs']), + withMDX, + withYaml, + withBundleAnalyzer, + ] return plugins.reduce((acc, next) => next(acc), nextConfig) } + +export default configExport diff --git a/apps/docs/package.json b/apps/docs/package.json index 0eb29301d62..a4d4a7133da 100644 --- a/apps/docs/package.json +++ b/apps/docs/package.json @@ -6,6 +6,7 @@ "dev": "next dev --port 3001", "dev:secrets:pull": "AWS_PROFILE=supabase-dev node internals/getSecrets.js", "build": "npm run generate:all && next build", + "build:analyze": "ANALYZE=true next build", "start": "next start", "lint": "next lint", "build:sitemap": "node ./internals/generate-sitemap.mjs", @@ -46,6 +47,7 @@ "@docsearch/react": "^3.3.0", "@mdx-js/loader": "^1.6.22", "@mdx-js/react": "^1.6.22", + "@next/bundle-analyzer": "^13.4.0", "@next/mdx": "^12.0.4", "@octokit/auth-app": "^4.0.9", "@octokit/core": "^4.2.0", diff --git a/package-lock.json b/package-lock.json index 0881d78353b..6237c010baa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,6 +41,7 @@ "@docsearch/react": "^3.3.0", "@mdx-js/loader": "^1.6.22", "@mdx-js/react": "^1.6.22", + "@next/bundle-analyzer": "^13.4.0", "@next/mdx": "^12.0.4", "@octokit/auth-app": "^4.0.9", "@octokit/core": "^4.2.0", @@ -5267,9 +5268,9 @@ } }, "node_modules/@next/bundle-analyzer": { - "version": "13.2.4", - "resolved": "https://registry.npmjs.org/@next/bundle-analyzer/-/bundle-analyzer-13.2.4.tgz", - "integrity": "sha512-bY4Clt7f1roJextpeQOQQWfNiXI0O5UvfOEyfuM5YUGPQMOCAZD2zjLjolakdn9Dm2yyMQUQ6JDE+iJK0dIeLA==", + "version": "13.4.0", + "resolved": "https://registry.npmjs.org/@next/bundle-analyzer/-/bundle-analyzer-13.4.0.tgz", + "integrity": "sha512-3ni7Ple1By7RNk2MB/y4CC4aFJuyI2mYSRxDo8n5VckVJeLVasmmmvzdN45dKzgs8AHu3dPWIsS3+2NJKMyU+A==", "dependencies": { "webpack-bundle-analyzer": "4.7.0" } @@ -43187,9 +43188,9 @@ "integrity": "sha512-3fkKj25kEjsfObL6IlKPAlHYPq/oYwUkkQ03zsTTiDjD7vg/RxjdiLeCydqtxHZP0JgsXL3D/X5oAkMGzuUp/Q==" }, "@next/bundle-analyzer": { - "version": "13.2.4", - "resolved": "https://registry.npmjs.org/@next/bundle-analyzer/-/bundle-analyzer-13.2.4.tgz", - "integrity": "sha512-bY4Clt7f1roJextpeQOQQWfNiXI0O5UvfOEyfuM5YUGPQMOCAZD2zjLjolakdn9Dm2yyMQUQ6JDE+iJK0dIeLA==", + "version": "13.4.0", + "resolved": "https://registry.npmjs.org/@next/bundle-analyzer/-/bundle-analyzer-13.4.0.tgz", + "integrity": "sha512-3ni7Ple1By7RNk2MB/y4CC4aFJuyI2mYSRxDo8n5VckVJeLVasmmmvzdN45dKzgs8AHu3dPWIsS3+2NJKMyU+A==", "requires": { "webpack-bundle-analyzer": "4.7.0" } @@ -51526,6 +51527,7 @@ "@docsearch/react": "^3.3.0", "@mdx-js/loader": "^1.6.22", "@mdx-js/react": "^1.6.22", + "@next/bundle-analyzer": "^13.4.0", "@next/mdx": "^12.0.4", "@octokit/auth-app": "^4.0.9", "@octokit/core": "^4.2.0", @@ -68107,7 +68109,7 @@ "@types/react": "^17.0.37", "@types/react-copy-to-clipboard": "^5.0.4", "@types/react-dom": "^17.0.11", - "@types/react-syntax-highlighter": "*", + "@types/react-syntax-highlighter": "^15.5.6", "autoprefixer": "^10.4.2", "clsx": "^1.2.1", "cmdk-supabase": "^0.2.2", From e165bbf252d1a9fdb64ac984aadd803cfcb9327e Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Thu, 4 May 2023 17:54:08 -0600 Subject: [PATCH 04/18] chore(ui): indicate no side effects for future tree shaking --- packages/ui/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/ui/package.json b/packages/ui/package.json index e3befbec3fc..7ec616945d6 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -4,6 +4,7 @@ "main": "./index.tsx", "types": "./index.tsx", "license": "MIT", + "sideEffects": false, "scripts": { "build:icons": "node --experimental-modules internals/populate-icons.js", "storybook": "start-storybook -p 6006", From ed8798e60c9328a878e611eb726a4d92fc448799 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Thu, 4 May 2023 17:54:45 -0600 Subject: [PATCH 05/18] chore(docs): lodash tree shaking --- apps/docs/generator/helpers.ts | 6 +++--- apps/docs/next.config.mjs | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/docs/generator/helpers.ts b/apps/docs/generator/helpers.ts index e7796c9101f..30b8037d818 100644 --- a/apps/docs/generator/helpers.ts +++ b/apps/docs/generator/helpers.ts @@ -1,5 +1,5 @@ -import * as _ from 'lodash' import * as fs from 'fs' +import { mapValues, values } from 'lodash' export const slugify = (text: string) => { if (!text) return '' @@ -34,8 +34,8 @@ export const writeToDisk = (fileName: string, content: any) => { * Convert Object to Array of values */ export const toArrayWithKey = (obj: object, keyAs: string) => - _.values( - _.mapValues(obj, (value: any, key: string) => { + values( + mapValues(obj, (value: any, key: string) => { value[keyAs] = key return value }) diff --git a/apps/docs/next.config.mjs b/apps/docs/next.config.mjs index 029a3767707..5f38a0d35c6 100644 --- a/apps/docs/next.config.mjs +++ b/apps/docs/next.config.mjs @@ -45,7 +45,7 @@ const withMDX = nextMdx({ }, }) -// /** @type {NextConfig} */ +/** @type {import('next').NextConfig} nextConfig */ const nextConfig = { // Append the default value with md extensions pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'], @@ -64,6 +64,11 @@ const nextConfig = { }, experimental: { mdxRs: true, + modularizeImports: { + lodash: { + transform: 'lodash/{{member}}', + }, + }, }, async headers() { return [ From 695b00c0ceca44b6a8744bcb0bc4bf18c122cf62 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Thu, 4 May 2023 18:48:08 -0600 Subject: [PATCH 06/18] chore(docs): yaml import types --- .../Navigation/NavigationMenu/NavigationMenu.tsx | 8 +------- .../NavigationMenu/NavigationMenuCliList.tsx | 1 - .../docs/components/reference/CLICommandSection.tsx | 1 - .../enrichments/cli/CliGlobalFlagsHandler.tsx | 1 - apps/docs/lib/mdx/getConfig.tsx | 5 ----- apps/docs/pages/reference/analytics/config.tsx | 1 - apps/docs/pages/reference/auth/config.tsx | 1 - apps/docs/pages/reference/cli/[...slug].tsx | 1 - apps/docs/pages/reference/cli/config.tsx | 1 - apps/docs/pages/reference/csharp/[...slug].tsx | 1 - .../pages/reference/csharp/crawlers/[...slug].tsx | 1 - apps/docs/pages/reference/csharp/v0/[...slug].tsx | 1 - .../reference/csharp/v0/crawlers/[...slug].tsx | 1 - apps/docs/pages/reference/dart/[...slug].tsx | 1 - .../pages/reference/dart/crawlers/[...slug].tsx | 1 - apps/docs/pages/reference/dart/v0/[...slug].tsx | 1 - .../pages/reference/dart/v0/crawlers/[...slug].tsx | 1 - apps/docs/pages/reference/javascript/[...slug].tsx | 1 - .../reference/javascript/crawlers/[...slug].tsx | 1 - .../pages/reference/javascript/v1/[...slug].tsx | 1 - .../reference/javascript/v1/crawlers/[...slug].tsx | 1 - apps/docs/pages/reference/python/[...slug].tsx | 1 - .../pages/reference/python/crawlers/[...slug].tsx | 1 - apps/docs/pages/reference/realtime/config.tsx | 1 - apps/docs/pages/reference/storage/config.tsx | 1 - apps/docs/pages/reference/swift/[...slug].tsx | 1 - .../pages/reference/swift/crawlers/[...slug].tsx | 1 - apps/docs/pages/reference/swift/v0/[...slug].tsx | 1 - .../pages/reference/swift/v0/crawlers/[...slug].tsx | 1 - apps/docs/types/index.ts | 2 ++ apps/docs/types/yaml.d.ts | 13 +++++++++++++ 31 files changed, 16 insertions(+), 39 deletions(-) create mode 100644 apps/docs/types/yaml.d.ts diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx index 3d22d69e9d1..be2973bde7e 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx @@ -3,19 +3,13 @@ import { memo, useEffect } from 'react' import { menuState, useMenuLevelId } from '~/hooks/useMenuState' import NavigationMenuGuideList from './NavigationMenuGuideList' import NavigationMenuRefList from './NavigationMenuRefList' -// @ts-expect-error + import spec_js_v2 from '~/../../spec/supabase_js_v2.yml' assert { type: 'yml' } -// @ts-expect-error import spec_js_v1 from '~/../../spec/supabase_js_v1.yml' assert { type: 'yml' } -// @ts-expect-error import spec_dart_v1 from '~/../../spec/supabase_dart_v1.yml' assert { type: 'yml' } -// @ts-expect-error import spec_dart_v0 from '~/../../spec/supabase_dart_v0.yml' assert { type: 'yml' } -// @ts-expect-error import spec_csharp_v0 from '~/../../spec/supabase_csharp_v0.yml' assert { type: 'yml' } -// @ts-expect-error import spec_python_v2 from '~/../../spec/supabase_py_v2.yml' assert { type: 'yml' } -// @ts-expect-error import spec_swift_v0 from '~/../../spec/supabase_swift_v0.yml' assert { type: 'yml' } // import { gen_v3 } from '~/lib/refGenerator/helpers' diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuCliList.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuCliList.tsx index cae120747b8..e90a3ceb0b7 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuCliList.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuCliList.tsx @@ -3,7 +3,6 @@ import { useRouter } from 'next/router' import { IconChevronLeft } from 'ui' import * as NavItems from './NavigationMenu.constants' -// @ts-expect-error import clientLibsCommon from '~/../../spec/common-cli.yml' assert { type: 'yml' } const NavigationMenuCliList = ({ currentLevel, setLevel, id }) => { diff --git a/apps/docs/components/reference/CLICommandSection.tsx b/apps/docs/components/reference/CLICommandSection.tsx index f25d32e74cf..400b3fa7287 100644 --- a/apps/docs/components/reference/CLICommandSection.tsx +++ b/apps/docs/components/reference/CLICommandSection.tsx @@ -1,6 +1,5 @@ import ReactMarkdown from 'react-markdown' import { CodeBlock, IconChevronRight, Tabs } from 'ui' -// @ts-expect-error import spec from '~/../../spec/cli_v1_commands.yaml' assert { type: 'yml' } import Options from '~/components/Options' import Param from '~/components/Params' diff --git a/apps/docs/components/reference/enrichments/cli/CliGlobalFlagsHandler.tsx b/apps/docs/components/reference/enrichments/cli/CliGlobalFlagsHandler.tsx index 1de9c1971d0..e108730f65a 100644 --- a/apps/docs/components/reference/enrichments/cli/CliGlobalFlagsHandler.tsx +++ b/apps/docs/components/reference/enrichments/cli/CliGlobalFlagsHandler.tsx @@ -1,6 +1,5 @@ import RefSubLayout from '~/layouts/ref/RefSubLayout' -// @ts-expect-error import spec from '~/../../spec/cli_v1_commands.yaml' assert { type: 'yaml' } import Param from '~/components/Params' import Options from '~/components/Options' diff --git a/apps/docs/lib/mdx/getConfig.tsx b/apps/docs/lib/mdx/getConfig.tsx index 4cd95686c7f..2341e23b3e2 100644 --- a/apps/docs/lib/mdx/getConfig.tsx +++ b/apps/docs/lib/mdx/getConfig.tsx @@ -1,12 +1,7 @@ -// @ts-expect-error import specStorageV0 from '~/../../spec/storage_v0_config.yaml' assert { type: 'yml' } -// @ts-expect-error import specRealtimeV0 from '~/../../spec/realtime_v0_config.yaml' assert { type: 'yml' } -// @ts-expect-error import specAuthV1 from '~/../../spec/gotrue_v1_config.yaml' assert { type: 'yml' } -// @ts-expect-error import specAnalyticsV0 from '~/../../spec/analytics_v0_config.yaml' assert { type: 'yml' } -// @ts-expect-error import specFunctionsV0 from '~/../../spec/functions_v0_config.yaml' assert { type: 'yml' } function getStorageConfigV0() { diff --git a/apps/docs/pages/reference/analytics/config.tsx b/apps/docs/pages/reference/analytics/config.tsx index e22dfe2e911..ed0c0dc07a6 100644 --- a/apps/docs/pages/reference/analytics/config.tsx +++ b/apps/docs/pages/reference/analytics/config.tsx @@ -4,7 +4,6 @@ import components from '~/components/index' import { MDXRemote } from 'next-mdx-remote' import { serialize } from 'next-mdx-remote/serialize' -// @ts-expect-error import specFile from '~/../../spec/analytics_v0_config.yaml' assert { type: 'yml' } import { Parameter } from '~/lib/refGenerator/refTypes' diff --git a/apps/docs/pages/reference/auth/config.tsx b/apps/docs/pages/reference/auth/config.tsx index c024dbe9ecc..41b9437f148 100644 --- a/apps/docs/pages/reference/auth/config.tsx +++ b/apps/docs/pages/reference/auth/config.tsx @@ -1,4 +1,3 @@ -// @ts-expect-error import specFile from '~/../../spec/gotrue_v1_config.yaml' assert { type: 'yml' } import { Parameter } from '~/lib/refGenerator/refTypes' import ReactMarkdown from 'react-markdown' diff --git a/apps/docs/pages/reference/cli/[...slug].tsx b/apps/docs/pages/reference/cli/[...slug].tsx index 3555095ee72..5af245300ef 100644 --- a/apps/docs/pages/reference/cli/[...slug].tsx +++ b/apps/docs/pages/reference/cli/[...slug].tsx @@ -1,4 +1,3 @@ -// @ts-expect-error import spec from '~/../../spec/cli_v1_commands.yaml' assert { type: 'yml' } import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/cli/config.tsx b/apps/docs/pages/reference/cli/config.tsx index a40295b3802..6a167f1ec03 100644 --- a/apps/docs/pages/reference/cli/config.tsx +++ b/apps/docs/pages/reference/cli/config.tsx @@ -1,4 +1,3 @@ -// @ts-expect-error import specFile from '~/../../spec/cli_v1_config.yaml' assert { type: 'yml' } import { Parameter } from '~/lib/refGenerator/refTypes' import ReactMarkdown from 'react-markdown' diff --git a/apps/docs/pages/reference/csharp/[...slug].tsx b/apps/docs/pages/reference/csharp/[...slug].tsx index f3e510ece23..17b26f498a4 100644 --- a/apps/docs/pages/reference/csharp/[...slug].tsx +++ b/apps/docs/pages/reference/csharp/[...slug].tsx @@ -1,5 +1,4 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' -// @ts-expect-error import spec from '~/../../spec/supabase_csharp_v0.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/csharp/crawlers/[...slug].tsx b/apps/docs/pages/reference/csharp/crawlers/[...slug].tsx index 89d58eb1478..f94729d7482 100644 --- a/apps/docs/pages/reference/csharp/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/csharp/crawlers/[...slug].tsx @@ -1,6 +1,5 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' -// @ts-expect-error import spec from '~/../../spec/supabase_csharp_v0.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/csharp/v0/[...slug].tsx b/apps/docs/pages/reference/csharp/v0/[...slug].tsx index 41b28c0a1ef..92e4d0a5b9c 100644 --- a/apps/docs/pages/reference/csharp/v0/[...slug].tsx +++ b/apps/docs/pages/reference/csharp/v0/[...slug].tsx @@ -1,5 +1,4 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' -// @ts-expect-error import spec from '~/../../spec/supabase_csharp_v0.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/csharp/v0/crawlers/[...slug].tsx b/apps/docs/pages/reference/csharp/v0/crawlers/[...slug].tsx index 059df1c75b1..d4c26ddf9dd 100644 --- a/apps/docs/pages/reference/csharp/v0/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/csharp/v0/crawlers/[...slug].tsx @@ -1,6 +1,5 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' -// @ts-expect-error import spec from '~/../../spec/supabase_csharp_v0.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/dart/[...slug].tsx b/apps/docs/pages/reference/dart/[...slug].tsx index f35f74c6120..6cd14595a69 100644 --- a/apps/docs/pages/reference/dart/[...slug].tsx +++ b/apps/docs/pages/reference/dart/[...slug].tsx @@ -1,5 +1,4 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' -// @ts-expect-error import spec from '~/../../spec/supabase_dart_v1.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/dart/crawlers/[...slug].tsx b/apps/docs/pages/reference/dart/crawlers/[...slug].tsx index 84497018cdb..54aef81d9c1 100644 --- a/apps/docs/pages/reference/dart/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/dart/crawlers/[...slug].tsx @@ -1,6 +1,5 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' -// @ts-expect-error import spec from '~/../../spec/supabase_dart_v1.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/dart/v0/[...slug].tsx b/apps/docs/pages/reference/dart/v0/[...slug].tsx index 4b6a485d9c6..455b8cdfbe5 100644 --- a/apps/docs/pages/reference/dart/v0/[...slug].tsx +++ b/apps/docs/pages/reference/dart/v0/[...slug].tsx @@ -1,5 +1,4 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' -// @ts-expect-error import spec from '~/../../spec/supabase_dart_v0.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/dart/v0/crawlers/[...slug].tsx b/apps/docs/pages/reference/dart/v0/crawlers/[...slug].tsx index 997b56deec2..459912b8b35 100644 --- a/apps/docs/pages/reference/dart/v0/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/dart/v0/crawlers/[...slug].tsx @@ -1,6 +1,5 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' -// @ts-expect-error import spec from '~/../../spec/supabase_dart_v0.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/javascript/[...slug].tsx b/apps/docs/pages/reference/javascript/[...slug].tsx index 3cbbcc08694..244fe6c28ae 100644 --- a/apps/docs/pages/reference/javascript/[...slug].tsx +++ b/apps/docs/pages/reference/javascript/[...slug].tsx @@ -1,6 +1,5 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' -// @ts-expect-error import spec from '~/../../spec/supabase_js_v2.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/javascript/crawlers/[...slug].tsx b/apps/docs/pages/reference/javascript/crawlers/[...slug].tsx index df4a97dcdc5..34c4ee78943 100644 --- a/apps/docs/pages/reference/javascript/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/javascript/crawlers/[...slug].tsx @@ -1,6 +1,5 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' -// @ts-expect-error import spec from '~/../../spec/supabase_js_v2.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/javascript/v1/[...slug].tsx b/apps/docs/pages/reference/javascript/v1/[...slug].tsx index 4dd32c156ca..e7a5b4bf8d1 100644 --- a/apps/docs/pages/reference/javascript/v1/[...slug].tsx +++ b/apps/docs/pages/reference/javascript/v1/[...slug].tsx @@ -1,6 +1,5 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v1/combined.json' -// @ts-expect-error import spec from '~/../../spec/supabase_js_v1.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/javascript/v1/crawlers/[...slug].tsx b/apps/docs/pages/reference/javascript/v1/crawlers/[...slug].tsx index 19278fccd67..64a6816669d 100644 --- a/apps/docs/pages/reference/javascript/v1/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/javascript/v1/crawlers/[...slug].tsx @@ -1,6 +1,5 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' -// @ts-expect-error import spec from '~/../../spec/supabase_js_v1.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/python/[...slug].tsx b/apps/docs/pages/reference/python/[...slug].tsx index a93ce7bcf52..d0b6ae951dd 100644 --- a/apps/docs/pages/reference/python/[...slug].tsx +++ b/apps/docs/pages/reference/python/[...slug].tsx @@ -1,6 +1,5 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' -// @ts-expect-error import spec from '~/../../spec/supabase_py_v2.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/python/crawlers/[...slug].tsx b/apps/docs/pages/reference/python/crawlers/[...slug].tsx index 593da6371f7..0ccb2c18cce 100644 --- a/apps/docs/pages/reference/python/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/python/crawlers/[...slug].tsx @@ -1,6 +1,5 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' -// @ts-expect-error import spec from '~/../../spec/supabase_py_v2.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/realtime/config.tsx b/apps/docs/pages/reference/realtime/config.tsx index eaa7763e7fa..aab317af44d 100644 --- a/apps/docs/pages/reference/realtime/config.tsx +++ b/apps/docs/pages/reference/realtime/config.tsx @@ -4,7 +4,6 @@ import components from '~/components/index' import { MDXRemote } from 'next-mdx-remote' import { serialize } from 'next-mdx-remote/serialize' -// @ts-expect-error import specFile from '~/../../spec/realtime_v0_config.yaml' assert { type: 'yml' } import { Parameter } from '~/lib/refGenerator/refTypes' diff --git a/apps/docs/pages/reference/storage/config.tsx b/apps/docs/pages/reference/storage/config.tsx index 8af901cba03..94dee5d9e55 100644 --- a/apps/docs/pages/reference/storage/config.tsx +++ b/apps/docs/pages/reference/storage/config.tsx @@ -1,4 +1,3 @@ -// @ts-expect-error import specFile from '~/../../spec/storage_v0_config.yaml' assert { type: 'yml' } import { Parameter } from '~/lib/refGenerator/refTypes' diff --git a/apps/docs/pages/reference/swift/[...slug].tsx b/apps/docs/pages/reference/swift/[...slug].tsx index d0e994ed1d6..dd1ffb3354e 100644 --- a/apps/docs/pages/reference/swift/[...slug].tsx +++ b/apps/docs/pages/reference/swift/[...slug].tsx @@ -1,5 +1,4 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' -// @ts-expect-error import spec from '~/../../spec/supabase_swift_v0.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/swift/crawlers/[...slug].tsx b/apps/docs/pages/reference/swift/crawlers/[...slug].tsx index 308eda7006f..644925aeac4 100644 --- a/apps/docs/pages/reference/swift/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/swift/crawlers/[...slug].tsx @@ -1,6 +1,5 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' -// @ts-expect-error import spec from '~/../../spec/supabase_swift_v0.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/swift/v0/[...slug].tsx b/apps/docs/pages/reference/swift/v0/[...slug].tsx index c27937c271f..3e2e253dc6a 100644 --- a/apps/docs/pages/reference/swift/v0/[...slug].tsx +++ b/apps/docs/pages/reference/swift/v0/[...slug].tsx @@ -1,5 +1,4 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' -// @ts-expect-error import spec from '~/../../spec/supabase_swift_v0.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/pages/reference/swift/v0/crawlers/[...slug].tsx b/apps/docs/pages/reference/swift/v0/crawlers/[...slug].tsx index d89222f1f22..099dfb582a8 100644 --- a/apps/docs/pages/reference/swift/v0/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/swift/v0/crawlers/[...slug].tsx @@ -1,6 +1,5 @@ import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' -// @ts-expect-error import spec from '~/../../spec/supabase_swift_v0.yml' assert { type: 'yml' } import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' diff --git a/apps/docs/types/index.ts b/apps/docs/types/index.ts index c1e58ad998a..88cdf87ab6b 100644 --- a/apps/docs/types/index.ts +++ b/apps/docs/types/index.ts @@ -1 +1,3 @@ export * from './next' + +export type Json = string | number | boolean | { [key: string]: Json } | Json[] diff --git a/apps/docs/types/yaml.d.ts b/apps/docs/types/yaml.d.ts new file mode 100644 index 00000000000..519982d6518 --- /dev/null +++ b/apps/docs/types/yaml.d.ts @@ -0,0 +1,13 @@ +declare module '*.yml' { + import { Json } from '.' + + const value: Json + export default value +} + +declare module '*.yaml' { + import { Json } from '.' + + const value: Json + export default value +} From 0a4700f2a1dda5afb23fbf0c4aef91ccded7d111 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Mon, 8 May 2023 12:46:33 -0600 Subject: [PATCH 07/18] refactor: simplify reference docs nav menu & code split --- .../NavigationMenu/NavigationMenu.tsx | 569 ++++++++---------- .../NavigationMenu/NavigationMenu.utils.ts | 25 + .../NavigationMenu/NavigationMenuRefList.tsx | 82 +-- .../NavigationMenuRefListItems.tsx | 266 +++----- .../reference/RefSectionHandler.tsx | 52 +- .../components/reference/Reference.types.ts | 58 +- apps/docs/layouts/SiteLayout.tsx | 40 +- apps/docs/lib/helpers.ts | 37 +- apps/docs/lib/refGenerator/helpers.ts | 10 +- .../scripts/search/sources/reference-doc.ts | 8 +- spec/common-api-sections.json | 8 +- spec/common-cli-sections.json | 16 + spec/common-client-libs-sections.json | 6 + ...ommon-self-hosting-analytics-sections.json | 1 + spec/common-self-hosting-auth-sections.json | 1 + .../common-self-hosting-storage-sections.json | 1 + 16 files changed, 556 insertions(+), 624 deletions(-) diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx index be2973bde7e..4e5ecf473e4 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx @@ -3,177 +3,261 @@ import { memo, useEffect } from 'react' import { menuState, useMenuLevelId } from '~/hooks/useMenuState' import NavigationMenuGuideList from './NavigationMenuGuideList' import NavigationMenuRefList from './NavigationMenuRefList' - -import spec_js_v2 from '~/../../spec/supabase_js_v2.yml' assert { type: 'yml' } -import spec_js_v1 from '~/../../spec/supabase_js_v1.yml' assert { type: 'yml' } -import spec_dart_v1 from '~/../../spec/supabase_dart_v1.yml' assert { type: 'yml' } -import spec_dart_v0 from '~/../../spec/supabase_dart_v0.yml' assert { type: 'yml' } -import spec_csharp_v0 from '~/../../spec/supabase_csharp_v0.yml' assert { type: 'yml' } -import spec_python_v2 from '~/../../spec/supabase_py_v2.yml' assert { type: 'yml' } -import spec_swift_v0 from '~/../../spec/supabase_swift_v0.yml' assert { type: 'yml' } - -// import { gen_v3 } from '~/lib/refGenerator/helpers' -import apiCommonSections from '~/../../spec/common-api-sections.json' -import cliCommonSections from '~/../../spec/common-cli-sections.json' -import libCommonSections from '~/../../spec/common-client-libs-sections.json' -import authServerCommonSections from '~/../../spec/common-self-hosting-auth-sections.json' -import realtimeServerCommonSections from '~/../../spec/common-self-hosting-realtime-sections.json' -import analyticsServerCommonSections from '~/../../spec/common-self-hosting-analytics-sections.json' -import functionsServerCommonSections from '~/../../spec/common-self-hosting-functions-sections.json' -import storageServerCommonSections from '~/../../spec/common-self-hosting-storage-sections.json' -import { flattenSections } from '~/lib/helpers' import NavigationMenuHome from './HomeMenu' +import { Json } from '~/types' +import { ICommonBase } from '~/components/reference/Reference.types' -// Filter libCommonSections for just the relevant sections in the current library -export function generateAllowedClientLibKeys(sections, spec) { - // Filter parent sections first - - const specIds = spec.functions.map((func) => { - return func.id - }) - - const newShape = flattenSections(sections).filter((section) => { - if (specIds.includes(section.id)) { - return section - } - }) - - const final = newShape.map((func) => { - return func.id - }) - - return final +// Import dynamically to code split / reduce app bundle size +const specImports = { + specJsV1: async () => (await import('~/../../spec/supabase_js_v1.yml')).default, + specJsV2: async () => (await import('~/../../spec/supabase_js_v2.yml')).default, + specDartV0: async () => (await import('~/../../spec/supabase_dart_v0.yml')).default, + specDartV1: async () => (await import('~/../../spec/supabase_dart_v1.yml')).default, + specPythonV2: async () => (await import('~/../../spec/supabase_py_v2.yml')).default, + specCSharpV0: async () => (await import('~/../../spec/supabase_csharp_v0.yml')).default, + specSwiftV0: async () => (await import('~/../../spec/supabase_swift_v0.yml')).default, } -export type RefIdOptions = - | 'reference_javascript_v1' - | 'reference_javascript_v2' - | 'reference_dart_v0' - | 'reference_dart_v1' - | 'reference_csharp_v0' - | 'reference_python_v2' - | 'reference_swift_v0' - | 'reference_cli' - | 'reference_api' - | 'reference_self_hosting_auth' - | 'reference_self_hosting_storage' - | 'reference_self_hosting_realtime' - | 'reference_self_hosting_analytics' - | 'reference_self_hosting_functions' +const commonSectionImports = { + apiCommonSections: async () => (await import('~/../../spec/common-api-sections.json')).default, + cliCommonSections: async () => (await import('~/../../spec/common-cli-sections.json')).default, + libCommonSections: async () => + (await import('~/../../spec/common-client-libs-sections.json')).default, + analyticsServerCommonSections: async () => + (await import('~/../../spec/common-self-hosting-analytics-sections.json')).default, + authServerCommonSections: async () => + (await import('~/../../spec/common-self-hosting-auth-sections.json')).default, + functionsServerCommonSections: async () => + (await import('~/../../spec/common-self-hosting-functions-sections.json')).default, + realtimeServerCommonSections: async () => + (await import('~/../../spec/common-self-hosting-realtime-sections.json')).default, + storageServerCommonSections: async () => + (await import('~/../../spec/common-self-hosting-storage-sections.json')).default, +} -export type RefKeyOptions = - | 'javascript' - | 'dart' - | 'csharp' - | 'python' - | 'swift' - | 'cli' - | 'api' - | 'self-hosting-auth' - | 'self-hosting-storage' - | 'self-hosting-realtime' - | 'self-hosting-analytics' - | 'self-hosting-functions' +interface BaseMenu { + id: string + path: string + type: string +} + +interface HomeMenu extends BaseMenu { + type: 'home' +} + +interface GuideMenu extends BaseMenu { + type: 'guide' +} + +interface ReferenceMenu extends BaseMenu { + type: 'reference' + commonSectionImport: () => Promise + specImport?: () => Promise +} + +type Menu = HomeMenu | GuideMenu | ReferenceMenu + +const menus: Menu[] = [ + { + id: 'home', + path: '/', + type: 'home', + }, + { + id: 'gettingstarted', + path: '/guides/getting-started', + type: 'guide', + }, + { + id: 'database', + path: '/guides/database', + type: 'guide', + }, + { + id: 'api', + path: '/guides/api', + type: 'guide', + }, + { + id: 'auth', + path: '/guides/auth', + type: 'guide', + }, + { + id: 'functions', + path: '/guides/functions', + type: 'guide', + }, + { + id: 'realtime', + path: '/guides/realtime', + type: 'guide', + }, + { + id: 'storage', + path: '/guides/storage', + type: 'guide', + }, + { + id: 'platform', + path: '/guides/platform', + type: 'guide', + }, + { + id: 'resources', + path: '/guides/resources', + type: 'guide', + }, + { + id: 'self_hosting', + path: '/guides/self-hosting', + type: 'guide', + }, + { + id: 'integrations', + path: '/guides/integrations', + type: 'guide', + }, + { + id: 'supabase_cli', + // TODO: Add path '/reference/cli/config' + path: '/guides/cli', + type: 'guide', + }, + { + id: 'reference_javascript_v1', + path: '/reference/javascript/v1', + commonSectionImport: commonSectionImports.libCommonSections, + specImport: specImports.specJsV1, + type: 'reference', + }, + { + id: 'reference_javascript_v2', + path: '/reference/javascript', + commonSectionImport: commonSectionImports.libCommonSections, + specImport: specImports.specJsV2, + type: 'reference', + }, + { + id: 'reference_dart_v0', + path: '/reference/dart/v0', + commonSectionImport: commonSectionImports.libCommonSections, + specImport: specImports.specDartV0, + type: 'reference', + }, + { + id: 'reference_dart_v1', + path: '/reference/dart', + commonSectionImport: commonSectionImports.libCommonSections, + specImport: specImports.specDartV1, + type: 'reference', + }, + { + id: 'reference_csharp_v0', + path: '/reference/csharp', + commonSectionImport: commonSectionImports.libCommonSections, + specImport: specImports.specCSharpV0, + type: 'reference', + }, + { + id: 'reference_python_v2', + path: '/reference/python', + commonSectionImport: commonSectionImports.libCommonSections, + specImport: specImports.specPythonV2, + type: 'reference', + }, + { + id: 'reference_swift_v0', + path: '/reference/swift', + commonSectionImport: commonSectionImports.libCommonSections, + specImport: specImports.specSwiftV0, + type: 'reference', + }, + { + id: 'reference_cli', + path: '/reference/cli', + commonSectionImport: commonSectionImports.cliCommonSections, + type: 'reference', + }, + { + id: 'reference_api', + path: '/reference/api', + commonSectionImport: commonSectionImports.apiCommonSections, + type: 'reference', + }, + { + id: 'reference_self_hosting_auth', + path: '/reference/self-hosting-auth', + commonSectionImport: commonSectionImports.authServerCommonSections, + type: 'reference', + }, + { + id: 'reference_self_hosting_storage', + path: '/reference/self-hosting-storage', + commonSectionImport: commonSectionImports.storageServerCommonSections, + type: 'reference', + }, + { + id: 'reference_self_hosting_realtime', + path: '/reference/self-hosting-realtime', + commonSectionImport: commonSectionImports.realtimeServerCommonSections, + type: 'reference', + }, + { + id: 'reference_self_hosting_analytics', + path: '/reference/self-hosting-analytics', + commonSectionImport: commonSectionImports.analyticsServerCommonSections, + type: 'reference', + }, + { + id: 'reference_self_hosting_functions', + path: '/reference/self-hosting-functions', + commonSectionImport: commonSectionImports.functionsServerCommonSections, + type: 'reference', + }, +] + +function getMenuById(id: string) { + return menus.find((menu) => menu.id === id) +} + +function getMenuByUrl(basePath: string, url: string) { + // If multiple matches, choose the menu with the longest path + const [menu] = menus + .filter(({ path }) => url.startsWith(`${basePath}${path}`)) + .sort((a, b) => b.path.length - a.path.length) + + return menu +} + +function getMenuElement(menu: Menu) { + const menuType = menu.type + switch (menuType) { + case 'home': + return + case 'guide': + return + case 'reference': + return ( + + ) + default: + throw new Error(`Unknown menu type '${menuType}'`) + } +} const NavigationMenu = () => { const router = useRouter() function handleRouteChange(url: string) { - switch (url) { - case `/docs`: - menuState.setMenuLevelId('home') - break - case url.includes(`/docs/guides/getting-started`) && url: - menuState.setMenuLevelId('gettingstarted') - break - case url.includes(`/docs/guides/database`) && url: - menuState.setMenuLevelId('database') - break - case url.includes(`/docs/guides/api`) && url: - menuState.setMenuLevelId('api') - break - case url.includes(`/docs/guides/auth`) && url: - menuState.setMenuLevelId('auth') - break - case url.includes(`/docs/guides/functions`) && url: - menuState.setMenuLevelId('functions') - break - case url.includes(`/docs/guides/realtime`) && url: - menuState.setMenuLevelId('realtime') - break - case url.includes(`/docs/guides/storage`) && url: - menuState.setMenuLevelId('storage') - break - case url.includes(`/docs/guides/platform`) && url: - menuState.setMenuLevelId('platform') - break - case url.includes(`/docs/guides/resources`) && url: - menuState.setMenuLevelId('resources') - break - case url.includes(`/docs/guides/self-hosting`) && url: - menuState.setMenuLevelId('self_hosting') - break - case url.includes(`/docs/guides/integrations`) && url: - menuState.setMenuLevelId('integrations') - break - case url.includes(`/docs/guides/cli`) && url: - menuState.setMenuLevelId('supabase_cli') - break - // JS v1 - case url.includes(`/docs/reference/javascript/v1`) && url: - menuState.setMenuLevelId('reference_javascript_v1') - break - // JS v2 (latest) - case url.includes(`/docs/reference/javascript`) && url: - menuState.setMenuLevelId('reference_javascript_v2') - break - // dart v0 - case url.includes(`/docs/reference/dart/v0`) && url: - menuState.setMenuLevelId('reference_dart_v0') - break - // dart v1 (latest) - case url.includes(`/docs/reference/dart`) && url: - menuState.setMenuLevelId('reference_dart_v1') - break - // C# v0 (latest) - case url.includes(`/docs/reference/csharp`) && url: - menuState.setMenuLevelId('reference_csharp_v0') - break - // python v2 (latest) - case url.includes(`/docs/reference/python`) && url: - menuState.setMenuLevelId('reference_python_v2') - break - // swift v1 (latest) - case url.includes(`/docs/reference/swift`) && url: - menuState.setMenuLevelId('reference_swift_v0') - break - case url.includes(`/docs/reference/cli/config`) && url: - menuState.setMenuLevelId('supabase_cli') - break - case url.includes(`/docs/reference/cli`) && url: - menuState.setMenuLevelId('reference_cli') - break - case url.includes(`/docs/reference/api`) && url: - menuState.setMenuLevelId('reference_api') - break - case url.includes(`/docs/reference/self-hosting-auth`) && url: - menuState.setMenuLevelId('reference_self_hosting_auth') - break - case url.includes(`/docs/reference/self-hosting-storage`) && url: - menuState.setMenuLevelId('reference_self_hosting_storage') - break - case url.includes(`/docs/reference/self-hosting-realtime`) && url: - menuState.setMenuLevelId('reference_self_hosting_realtime') - break - case url.includes(`/docs/reference/self-hosting-analytics`) && url: - menuState.setMenuLevelId('reference_self_hosting_analytics') - break - case url.includes(`/docs/reference/self-hosting-functions`) && url: - menuState.setMenuLevelId('reference_self_hosting_functions') - break - - default: - break + const menu = getMenuByUrl(router.basePath, url) + if (menu) { + menuState.setMenuLevelId(menu.id) } } @@ -187,168 +271,9 @@ const NavigationMenu = () => { }, [router.events]) const level = useMenuLevelId() + const menu = getMenuById(level) - const isHomeActive = 'home' === level - const isGettingStartedActive = 'gettingstarted' === level - const isDatabaseActive = 'database' === level - const isApiActive = 'api' === level - const isAuthActive = 'auth' === level - const isFunctionsActive = 'functions' === level - const isRealtimeActive = 'realtime' === level - const isStorageActive = 'storage' === level - const issupabase_cliActive = 'supabase_cli' === level - const isPlatformActive = 'platform' === level - const isResourcesActive = 'resources' === level - const isSelfHosting = 'self_hosting' === level - const isIntegrationsActive = 'integrations' === level - const isReferenceActive = 'reference' === level - - const isReference_Javascript_V1 = 'reference_javascript_v1' === level - const isReference_Javascript_V2 = 'reference_javascript_v2' === level - const isReference_Dart_V0 = 'reference_dart_v0' === level - const isReference_Dart_V1 = 'reference_dart_v1' === level - const isReference_Csharp_V0 = 'reference_csharp_v0' === level - const isReference_Python_V2 = 'reference_python_v2' === level - const isReference_Swift_V0 = 'reference_swift_v0' === level - const isReference_Cli = 'reference_cli' === level - const isReference_Api = 'reference_api' === level - const isReference_Self_Hosting_Auth = 'reference_self_hosting_auth' === level - const isReference_Self_Hosting_Storage = 'reference_self_hosting_storage' === level - const isReference_Self_Hosting_Realtime = 'reference_self_hosting_realtime' === level - const isReference_Self_Hosting_Analytics = 'reference_self_hosting_analytics' === level - const isReference_Self_Hosting_Functions = 'reference_self_hosting_functions' === level - - return ( -
    - {/* // main menu */} - - - - - - - - - - - - - - - {/* // Client Libs */} - - - - - - - - {/* // Tools */} - - - {/* // Self Hosting Server */} - - - - - -
    - ) + return getMenuElement(menu) } export default memo(NavigationMenu) diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.utils.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.utils.ts index ad3d100450f..8fce6ebf334 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.utils.ts +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.utils.ts @@ -1,6 +1,31 @@ +import { ICommonItem } from '~/components/reference/Reference.types' + // check if the link is allowed to be displayed export function isFuncNotInLibraryOrVersion(id, type, allowedKeys) { if (id && allowedKeys && !allowedKeys.includes(id) && type !== 'markdown') { return true } } + +/** + * Recursively filter common sections and their sub items based on + * what is available in their spec + */ +export function deepFilterSections(sections: ICommonItem[], specFunctionIds: string[]) { + return sections + .filter( + (section) => + section.type === 'category' || + section.type === 'markdown' || + specFunctionIds.includes(section.id) + ) + .map((section) => { + if ('items' in section) { + return { + ...section, + items: deepFilterSections(section.items, specFunctionIds), + } + } + return section + }) +} diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefList.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefList.tsx index e14787749fb..b4ee50d55d7 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefList.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefList.tsx @@ -1,31 +1,51 @@ -// import apiCommonSections from '~/../../spec/common-client-libs-sections.json' - -import { RefIdOptions, RefKeyOptions } from './NavigationMenu' +import { Json } from '~/types' import NavigationMenuRefListItems from './NavigationMenuRefListItems' -import React from 'react' +import React, { useEffect, useState } from 'react' +import { ICommonBase, ICommonItem } from '~/components/reference/Reference.types' -interface INavigationMenuRefList { - id: RefIdOptions - lib: RefKeyOptions - commonSections: any[] // to do type up - - // the keys of menu items that are allowed to be shown on the side menu - // if undefined, we show all the menu items - allowedClientKeys?: string[] - active: boolean - spec?: any +interface NavigationMenuRefListProps { + id: string + basePath: string + commonSectionsImport: () => Promise + specImport?: () => Promise } -const NavigationMenuRefList: React.FC = ({ +const NavigationMenuRefList = ({ id, - lib, - commonSections, + basePath, + commonSectionsImport, + specImport, +}: NavigationMenuRefListProps) => { + const [commonSections, setCommonSections] = useState() + const [spec, setSpec] = useState() - active, - spec, -}) => { - if (!active) { + // Dynamic imports allow for code splitting which + // dramatically reduces app bundle size + useEffect(() => { + async function fetchCommonSections() { + const commonSections = await commonSectionsImport() + setCommonSections(commonSections as ICommonItem[]) + } + fetchCommonSections() + }, [commonSectionsImport]) + + useEffect(() => { + if (!specImport) { + return + } + async function fetchSpec() { + const spec = await specImport() + setSpec(spec) + } + fetchSpec() + }, [specImport]) + + if (!commonSections) { + return null + } + + if (specImport && !spec) { return null } @@ -34,19 +54,13 @@ const NavigationMenuRefList: React.FC = ({ }) return ( -
    - +
    +
    ) } diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx index b81f6c5a1dd..9b79c109a6f 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx @@ -4,17 +4,15 @@ import { useRouter } from 'next/router' import { IconChevronLeft } from 'ui' import * as NavItems from './NavigationMenu.constants' -import { find } from 'lodash' -import Image from 'next/image' import { useTheme } from 'common/Providers' +import Image from 'next/image' import RevVersionDropdown from '~/components/RefVersionDropdown' import { useMenuActiveRefId } from '~/hooks/useMenuState' -import { RefIdOptions, RefKeyOptions } from './NavigationMenu' import React, { Fragment } from 'react' -import { generateAllowedClientLibKeys } from '~/lib/refGenerator/helpers' -import { isFuncNotInLibraryOrVersion } from './NavigationMenu.utils' +import { ICommonItem, ICommonSection } from '~/components/reference/Reference.types' +import { deepFilterSections } from './NavigationMenu.utils' const HeaderImage = React.memo(function HeaderImage(props: any) { const router = useRouter() @@ -40,38 +38,29 @@ const HeaderLink = React.memo(function HeaderLink(props: any) { ) }) -const FunctionLink = React.memo(function FunctionLink({ - title, - id, - icon, - library, - slug, -}: { +interface FunctionLinkProps { title: string name?: string id: string icon?: string - product?: string - library: string + basePath: string slug: string -}) { +} + +const FunctionLink = React.memo(function FunctionLink({ + title, + id, + icon, + basePath, + slug, +}: FunctionLinkProps) { const router = useRouter() - const activeAccordianItem = useMenuActiveRefId() + const activeAccordionItem = useMenuActiveRefId() - // check if we're on a versioned page - let version = '' - if (router.asPath.includes('v1')) { - version = 'v1' - } - - if (router.asPath.includes('v0')) { - version = 'v0' - } - - const active = activeAccordianItem === id + const active = activeAccordionItem === id return ( -
  • - +
  • + + ) } + let active = section.items.some((item) => item.id === activeAccordionItem) + return ( - - - - - {props.items && - props.items - .filter((item) => props.allowedKeys.includes(item.id)) - .map((item) => { - return ( - - ) - })} - - - + <> + + + + + {section.items.map((item) => { + return ( + + ) + })} + + + + ) }) @@ -158,67 +127,25 @@ const Divider = () => { return
    } -interface INavigationMenuRefList { - id: RefIdOptions - lib: RefKeyOptions - commonSections: any[] // to do type up - - // the keys of menu items that are allowed to be shown on the side menu - // if undefined, we show all the menu items - allowedClientKeys?: string[] +interface NavigationMenuRefListItemsProps { + id: string + basePath: string + commonSections: ICommonItem[] spec?: any } -const Content: React.FC = ({ id, lib, commonSections, spec }) => { - const allowedClientKeys = spec ? generateAllowedClientLibKeys(commonSections, spec) : undefined - - let sections = commonSections - - const allowedKeys = allowedClientKeys - - if (!sections) console.error('no common sections imported') - +const NavigationMenuRefListItems = ({ + id, + basePath, + commonSections, + spec, +}: NavigationMenuRefListItemsProps) => { const menu = NavItems[id] - const databaseFunctions = find(sections, { title: 'Database' }) - ? find(sections, { title: 'Database' }).items - : [] - const authFunctions = find(sections, { title: 'Auth' }) - ? find(sections, { title: 'Auth' }).items - : [] - - const filterIds = - databaseFunctions.length > 0 - ? find(databaseFunctions, { - id: 'using-filters', - }) && - find(databaseFunctions, { - id: 'using-filters', - }) - .items.filter((x) => allowedKeys.includes(x.id)) - .map((x) => x.id) - : [] - const modifierIds = - databaseFunctions.length > 0 - ? find(databaseFunctions, { - id: 'using-modifiers', - }) && - find(databaseFunctions, { - id: 'using-modifiers', - }) - .items.filter((x) => allowedKeys.includes(x.id)) - .map((x) => x.id) - : [] - - const authServerIds = - databaseFunctions.length > 0 - ? find(authFunctions, { - id: 'admin-api', - }) && - find(authFunctions, { - id: 'admin-api', - }).items.map((x) => x.id) - : [] + const specFunctionIds = spec?.functions.map(({ id }) => id) + const filteredSections = spec + ? deepFilterSections(commonSections, specFunctionIds) + : commonSections return (
    @@ -237,61 +164,26 @@ const Content: React.FC = ({ id, lib, commonSections, sp Back to Main Menu -
    -
      - {sections.map((fn: any, fnIndex) => { - // run allow check - if (isFuncNotInLibraryOrVersion(fn.id, fn.type, allowedKeys)) { - return - } - - // handle subtitles with subitems - return fn.id ? ( - - - {fn.items && - fn.items.map((item) => ( - - ))} - - ) : ( - - - - {fn.items && - fn.items.map((item, i) => { - // run allow check - if (isFuncNotInLibraryOrVersion(item.id, item.type, allowedKeys)) - return - return ( - - ) - })} + {filteredSections.map((section) => { + return ( + + {section.type === 'category' ? ( + <> + + + {section.items.map((item) => ( + + ))} + + ) : ( + + )} ) })} @@ -300,4 +192,4 @@ const Content: React.FC = ({ id, lib, commonSections, sp ) } -export default React.memo(Content) +export default React.memo(NavigationMenuRefListItems) diff --git a/apps/docs/components/reference/RefSectionHandler.tsx b/apps/docs/components/reference/RefSectionHandler.tsx index b1b5bebf134..eb0dbdc7455 100644 --- a/apps/docs/components/reference/RefSectionHandler.tsx +++ b/apps/docs/components/reference/RefSectionHandler.tsx @@ -8,10 +8,10 @@ import RefFunctionSection from '~/components/reference/RefFunctionSection' import RefSubLayout from '~/layouts/ref/RefSubLayout' import ApiOperationSection from './ApiOperationSection' import CliCommandSection from './CLICommandSection' -import { IAPISpec, ICommonFunc, IRefStaticDoc, ISpec, TypeSpec } from './Reference.types' +import { IAPISpec, ICommonSection, IRefStaticDoc, ISpec, TypeSpec } from './Reference.types' interface RefSectionHandlerProps { - sections: ICommonFunc[] + sections: ICommonSection[] spec?: ISpec | IAPISpec typeSpec?: TypeSpec pageProps: { docs: IRefStaticDoc[] } @@ -59,46 +59,48 @@ const RefSectionHandler = (props: RefSectionHandlerProps) => { - {props.sections.map((x, i) => { - switch (x.type) { + {props.sections.map((section, i) => { + const sectionType = section.type + switch (sectionType) { case 'markdown': - const markdownData = props.pageProps.docs.find((doc) => doc.id === x.id) + const markdownData = props.pageProps.docs.find((doc) => doc.id === section.id) - return - break + return ( + + ) case 'function': return ( ) case 'cli-command': - return - break + return ( + + ) case 'operation': return ( ) default: - return ( - - ) - break + throw new Error(`Unknown common section type '${sectionType}'`) } })} diff --git a/apps/docs/components/reference/Reference.types.ts b/apps/docs/components/reference/Reference.types.ts index 4ff54b1b991..ce15320180e 100644 --- a/apps/docs/components/reference/Reference.types.ts +++ b/apps/docs/components/reference/Reference.types.ts @@ -33,19 +33,61 @@ export interface IFunctionDefinition { examples?: [] } -export interface ICommonFunc { - id?: string +export interface ICommonBase { + type: string title: string - slug?: string - product?: string - type?: string - parent?: string - items?: ICommonFunc[] + summary?: string } +export interface ICommonBaseSection extends ICommonBase { + id: string + slug: string + excludes?: string[] +} + +export interface ICommonCategory extends ICommonBase { + type: 'category' + items: ICommonSection[] + excludes?: string[] +} + +export interface ICommonMarkdown extends ICommonBaseSection { + type: 'markdown' +} + +export interface ICommonFunctionGroup extends ICommonBaseSection { + type: 'function' + isFunc: false + product: string + items: ICommonFunction[] +} + +export interface ICommonFunction extends ICommonBaseSection { + type: 'function' + product: string + parent?: string +} + +export interface ICommonCliCommand extends ICommonBaseSection { + type: 'cli-command' +} + +export interface ICommonApiOperation extends ICommonBaseSection { + type: 'operation' +} + +export type ICommonSection = + | ICommonMarkdown + | ICommonFunctionGroup + | ICommonFunction + | ICommonCliCommand + | ICommonApiOperation + +export type ICommonItem = ICommonCategory | ICommonSection + export interface IRefFunctionSection { funcData: any - commonFuncData: ICommonFunc + commonFuncData: ICommonFunction spec: any typeSpec?: TypeSpec } diff --git a/apps/docs/layouts/SiteLayout.tsx b/apps/docs/layouts/SiteLayout.tsx index 0185f4918ae..ec0f9952786 100644 --- a/apps/docs/layouts/SiteLayout.tsx +++ b/apps/docs/layouts/SiteLayout.tsx @@ -4,10 +4,10 @@ import Link from 'next/link' import NavigationMenu from '~/components/Navigation/NavigationMenu/NavigationMenu' import TopNavBarRef from '~/components/Navigation/NavigationMenu/TopNavBarRef' -import { memo, useEffect } from 'react' +import Head from 'next/head' +import { PropsWithChildren, memo } from 'react' import Footer from '~/components/Navigation/Footer' import { menuState, useMenuLevelId, useMenuMobileOpen } from '~/hooks/useMenuState' -import Head from 'next/head' const levelsData = { home: { @@ -207,25 +207,6 @@ const MobileMenuBackdrop = memo(function MobileMenuBackdrop() { ) }) -const SideMenu = memo(function SideMenu() { - return ( -
      - -
      - ) -}) - const HeaderLogo = memo(function HeaderLogo() { const { isDarkMode } = useTheme() return ( @@ -311,13 +292,26 @@ const NavContainer = memo(function NavContainer() {
  • - +
    + +
    ) }) -const SiteLayout = ({ children }) => { +const SiteLayout = ({ children }: PropsWithChildren<{}>) => { return ( <> diff --git a/apps/docs/lib/helpers.ts b/apps/docs/lib/helpers.ts index 7a6c5de3d45..112898e065a 100644 --- a/apps/docs/lib/helpers.ts +++ b/apps/docs/lib/helpers.ts @@ -1,6 +1,4 @@ -// [Joshen] I think this can be done better, as its mostly used to choose what - -import { ICommonFunc } from '../components/reference/Reference.types' +import { ICommonBase, ICommonItem, ICommonSection } from '../components/reference/Reference.types' // menus to render in the SideBar.js (Ref Nav.constants.ts) export function getPageType(asPath: string) { @@ -36,18 +34,25 @@ export function getPageType(asPath: string) { return page } -export function flattenSections(sections: ICommonFunc[]) { - let a: ICommonFunc[] = [] - for (let i = 0; i < sections.length; i++) { - if (sections[i].id) { - // only push a section that has an id - // these are reserved for sidebar subtitles - a.push(sections[i]) +/** + * Flattens common sections recursively by their `items`. + * + * _Note:_ `sections` type set to `ICommonBase[]` instead of + * `ICommonItem[]` until TypeScript supports JSON imports as const: + * https://github.com/microsoft/TypeScript/issues/32063 + */ +export function flattenSections(sections: ICommonBase[]): ICommonSection[] { + return sections.reduce((acc, section: ICommonItem) => { + // Flatten sub-items + if ('items' in section) { + let newSections = acc + + if (section.type !== 'category') { + newSections.push(section) + } + + return newSections.concat(flattenSections(section.items)) } - if (sections[i].items) { - // if there are subitems, loop through - a = a.concat(flattenSections(sections[i].items)) - } - } - return a + return acc.concat(section) + }, []) } diff --git a/apps/docs/lib/refGenerator/helpers.ts b/apps/docs/lib/refGenerator/helpers.ts index 3325d45786f..d7c6ec52147 100644 --- a/apps/docs/lib/refGenerator/helpers.ts +++ b/apps/docs/lib/refGenerator/helpers.ts @@ -3,6 +3,7 @@ import { TsDoc } from '../../generator/legacy/definitions' import { values, mapValues } from 'lodash' import { OpenAPIV3 } from 'openapi-types' import { flattenSections } from '../helpers' +import { ICommonItem } from '~/components/reference/Reference.types' export function extractTsDocNode(nodeToFind: string, definition: any) { const nodePath = nodeToFind.split('.') @@ -294,12 +295,13 @@ export const toArrayWithKey = (obj: object, keyAs: string) => }) ) -export function generateAllowedClientLibKeys(sections, spec) { +/** + * Get a list of common section IDs that are available in this spec + */ +export function getAvailableSectionIds(sections: ICommonItem[], spec: any) { // Filter parent sections first - const specIds = spec.functions.map((func) => { - return func.id - }) + const specIds = spec.functions.map(({ id }) => id) const newShape = flattenSections(sections).filter((section) => { if (specIds.includes(section.id)) { diff --git a/apps/docs/scripts/search/sources/reference-doc.ts b/apps/docs/scripts/search/sources/reference-doc.ts index 61743a7748f..c3e5acecbed 100644 --- a/apps/docs/scripts/search/sources/reference-doc.ts +++ b/apps/docs/scripts/search/sources/reference-doc.ts @@ -3,7 +3,7 @@ import { readFile } from 'fs/promises' import yaml from 'js-yaml' import { OpenAPIV3 } from 'openapi-types' import { - ICommonFunc, + ICommonFunction, IFunctionDefinition, ISpec, } from '../../../components/reference/Reference.types' @@ -29,7 +29,7 @@ export abstract class ReferenceSource extends BaseSource { const specContents = await readFile(this.specFilePath, 'utf8') const refSectionsContents = await readFile(this.sectionsFilePath, 'utf8') - const refSections: ICommonFunc[] = JSON.parse(refSectionsContents) + const refSections: ICommonFunction[] = JSON.parse(refSectionsContents) const flattenedRefSections = flattenSections(refSections) const checksum = createHash('sha256') @@ -69,7 +69,7 @@ export abstract class ReferenceSource extends BaseSource { abstract getSpecSections(specContents: string): SpecSection[] abstract matchSpecSection(specSections: SpecSection[], id: string): SpecSection - abstract formatSection(specSection: SpecSection, refSection: ICommonFunc): string + abstract formatSection(specSection: SpecSection, refSection: ICommonFunction): string } export class OpenApiReferenceSource extends ReferenceSource { @@ -106,7 +106,7 @@ export class ClientLibReferenceSource extends ReferenceSource functionDefinition.id === id) } - formatSection(functionDefinition: IFunctionDefinition, refSection: ICommonFunc): string { + formatSection(functionDefinition: IFunctionDefinition, refSection: ICommonFunction): string { const { title } = refSection const { description, title: functionName } = functionDefinition diff --git a/spec/common-api-sections.json b/spec/common-api-sections.json index 59bb6396028..13f5c689c57 100644 --- a/spec/common-api-sections.json +++ b/spec/common-api-sections.json @@ -6,6 +6,7 @@ "type": "markdown" }, { + "type": "category", "title": "Projects", "items": [ { @@ -35,6 +36,7 @@ ] }, { + "type": "category", "title": "Secrets", "items": [ { @@ -58,6 +60,7 @@ ] }, { + "type": "category", "title": "Typescript", "items": [ { @@ -69,6 +72,7 @@ ] }, { + "type": "category", "title": "Functions", "items": [ { @@ -109,8 +113,8 @@ } ] }, - { + "type": "category", "title": "Custom Hostname", "items": [ { @@ -146,6 +150,7 @@ ] }, { + "type": "category", "title": "pgsodium", "items": [ { @@ -163,6 +168,7 @@ ] }, { + "type": "category", "title": "Network", "items": [ { diff --git a/spec/common-cli-sections.json b/spec/common-cli-sections.json index e01f4d5ece2..b624e7ec6c5 100644 --- a/spec/common-cli-sections.json +++ b/spec/common-cli-sections.json @@ -14,6 +14,7 @@ "type": "markdown" }, { + "type": "category", "title": "General", "items": [ { @@ -55,6 +56,7 @@ ] }, { + "type": "category", "title": "Testing", "items": [ { @@ -72,6 +74,7 @@ ] }, { + "type": "category", "title": "Generate Types", "items": [ { @@ -95,6 +98,7 @@ ] }, { + "type": "category", "title": "Database", "items": [ { @@ -148,6 +152,7 @@ ] }, { + "type": "category", "title": "Migrations", "items": [ { @@ -177,6 +182,7 @@ ] }, { + "type": "category", "title": "Projects", "items": [ { @@ -200,6 +206,7 @@ ] }, { + "type": "category", "title": "Organizations", "items": [ { @@ -217,6 +224,7 @@ ] }, { + "type": "category", "title": "Edge Functions", "items": [ { @@ -258,6 +266,7 @@ ] }, { + "type": "category", "title": "Secrets", "items": [ { @@ -287,6 +296,7 @@ ] }, { + "type": "category", "title": "Authentication", "items": [ { @@ -334,6 +344,7 @@ ] }, { + "type": "category", "title": "Custom Domains", "items": [ { @@ -375,6 +386,7 @@ ] }, { + "type": "category", "title": "Vanity Subdomains", "items": [ { @@ -410,6 +422,7 @@ ] }, { + "type": "category", "title": "Network Bans", "items": [ { @@ -433,6 +446,7 @@ ] }, { + "type": "category", "title": "Network Restrictions", "items": [ { @@ -456,6 +470,7 @@ ] }, { + "type": "category", "title": "SSL Enforcement", "items": [ { @@ -479,6 +494,7 @@ ] }, { + "type": "category", "title": "Autocompletion Scripts", "items": [ { diff --git a/spec/common-client-libs-sections.json b/spec/common-client-libs-sections.json index 06bacd153c6..03e7d4a9c32 100644 --- a/spec/common-client-libs-sections.json +++ b/spec/common-client-libs-sections.json @@ -51,6 +51,7 @@ ] }, { + "type": "category", "title": "Database", "items": [ { @@ -375,6 +376,7 @@ ] }, { + "type": "category", "title": "Auth", "items": [ { @@ -688,6 +690,7 @@ ] }, { + "type": "category", "title": "Functions", "items": [ { @@ -700,6 +703,7 @@ ] }, { + "type": "category", "title": "Realtime", "items": [ { @@ -761,6 +765,7 @@ ] }, { + "type": "category", "title": "Storage", "items": [ { @@ -892,6 +897,7 @@ ] }, { + "type": "category", "title": "Misc", "excludes": [ "reference_dart_v1", diff --git a/spec/common-self-hosting-analytics-sections.json b/spec/common-self-hosting-analytics-sections.json index 21732ffa309..4579dd3a298 100644 --- a/spec/common-self-hosting-analytics-sections.json +++ b/spec/common-self-hosting-analytics-sections.json @@ -7,6 +7,7 @@ "type": "markdown" }, { + "type": "category", "title": "Management API", "items": [ { diff --git a/spec/common-self-hosting-auth-sections.json b/spec/common-self-hosting-auth-sections.json index 82b090de047..2814fb67584 100644 --- a/spec/common-self-hosting-auth-sections.json +++ b/spec/common-self-hosting-auth-sections.json @@ -7,6 +7,7 @@ "type": "markdown" }, { + "type": "category", "title": "Usage", "items": [ { diff --git a/spec/common-self-hosting-storage-sections.json b/spec/common-self-hosting-storage-sections.json index cdcd9bcf537..0e90c80c252 100644 --- a/spec/common-self-hosting-storage-sections.json +++ b/spec/common-self-hosting-storage-sections.json @@ -7,6 +7,7 @@ "type": "markdown" }, { + "type": "category", "title": "Usage", "items": [ { From 03531a8a386df067bbb538a6c483f5c5bab0c4e8 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Mon, 8 May 2023 14:08:18 -0600 Subject: [PATCH 08/18] docs: sets 'using modifiers' text to sentence case --- spec/common-client-libs-sections.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/common-client-libs-sections.json b/spec/common-client-libs-sections.json index 03e7d4a9c32..4894689b9b8 100644 --- a/spec/common-client-libs-sections.json +++ b/spec/common-client-libs-sections.json @@ -293,7 +293,7 @@ { "id": "using-modifiers", "isFunc": false, - "title": "Using Modifiers", + "title": "Using modifiers", "slug": "using-modifiers", "product": "database", "parent": "modifiers", From 290ed9c406d4037bf816d84f7118dd08ec86fb1f Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Mon, 8 May 2023 14:08:57 -0600 Subject: [PATCH 09/18] fix(embeddings): reference doc typings --- apps/docs/scripts/search/sources/reference-doc.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/docs/scripts/search/sources/reference-doc.ts b/apps/docs/scripts/search/sources/reference-doc.ts index c3e5acecbed..34a907bb64a 100644 --- a/apps/docs/scripts/search/sources/reference-doc.ts +++ b/apps/docs/scripts/search/sources/reference-doc.ts @@ -3,7 +3,7 @@ import { readFile } from 'fs/promises' import yaml from 'js-yaml' import { OpenAPIV3 } from 'openapi-types' import { - ICommonFunction, + ICommonItem, IFunctionDefinition, ISpec, } from '../../../components/reference/Reference.types' @@ -29,7 +29,7 @@ export abstract class ReferenceSource extends BaseSource { const specContents = await readFile(this.specFilePath, 'utf8') const refSectionsContents = await readFile(this.sectionsFilePath, 'utf8') - const refSections: ICommonFunction[] = JSON.parse(refSectionsContents) + const refSections: ICommonItem[] = JSON.parse(refSectionsContents) const flattenedRefSections = flattenSections(refSections) const checksum = createHash('sha256') @@ -69,7 +69,7 @@ export abstract class ReferenceSource extends BaseSource { abstract getSpecSections(specContents: string): SpecSection[] abstract matchSpecSection(specSections: SpecSection[], id: string): SpecSection - abstract formatSection(specSection: SpecSection, refSection: ICommonFunction): string + abstract formatSection(specSection: SpecSection, refSection: ICommonItem): string } export class OpenApiReferenceSource extends ReferenceSource { @@ -106,7 +106,7 @@ export class ClientLibReferenceSource extends ReferenceSource functionDefinition.id === id) } - formatSection(functionDefinition: IFunctionDefinition, refSection: ICommonFunction): string { + formatSection(functionDefinition: IFunctionDefinition, refSection: ICommonItem): string { const { title } = refSection const { description, title: functionName } = functionDefinition From 83fa524e15df74b642b3129457c43236616164e2 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Mon, 8 May 2023 17:52:31 -0600 Subject: [PATCH 10/18] perf: code split CommandMenu --- apps/docs/pages/_app.tsx | 3 --- packages/ui/src/components/Command/CommandMenuProvider.tsx | 7 ++++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/docs/pages/_app.tsx b/apps/docs/pages/_app.tsx index 82ea66f90af..23cd007b9fb 100644 --- a/apps/docs/pages/_app.tsx +++ b/apps/docs/pages/_app.tsx @@ -3,11 +3,8 @@ import { SessionContextProvider } from '@supabase/auth-helpers-react' import { AuthProvider, ThemeProvider } from 'common' import { useRouter } from 'next/router' import { useEffect, useState } from 'react' -import ReactMarkdown from 'react-markdown' -import remarkGfm from 'remark-gfm' import { AppPropsWithLayout } from 'types' import { CommandMenuProvider } from 'ui' -import components from '~/components' import Favicons from '~/components/Favicons' import SiteLayout from '~/layouts/SiteLayout' import { IS_PLATFORM, LOCAL_SUPABASE } from '~/lib/constants' diff --git a/packages/ui/src/components/Command/CommandMenuProvider.tsx b/packages/ui/src/components/Command/CommandMenuProvider.tsx index 2152b8be161..8457c0ed97d 100644 --- a/packages/ui/src/components/Command/CommandMenuProvider.tsx +++ b/packages/ui/src/components/Command/CommandMenuProvider.tsx @@ -1,6 +1,11 @@ import { useTheme, UseThemeProps } from 'common' +import dynamic from 'next/dynamic' import { createContext, PropsWithChildren, useContext, useEffect, useState } from 'react' -import CommandMenu from './CommandMenu' + +// `CommandMenu` is heavy - code split to reduce app bundle size +const CommandMenu = dynamic(() => import('./CommandMenu'), { + loading: () =>

    Loading...

    , +}) export interface CommandMenuContextValue { isOpen: boolean From 44f904d5c815b390cca39bd8e2495cfcd62b030e Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Mon, 8 May 2023 20:09:47 -0600 Subject: [PATCH 11/18] fix: deepFilterSections typing --- .../Navigation/NavigationMenu/NavigationMenu.utils.ts | 5 ++++- .../Navigation/NavigationMenu/NavigationMenuRefListItems.tsx | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.utils.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.utils.ts index 8fce6ebf334..26bb5ed5023 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.utils.ts +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.utils.ts @@ -11,7 +11,10 @@ export function isFuncNotInLibraryOrVersion(id, type, allowedKeys) { * Recursively filter common sections and their sub items based on * what is available in their spec */ -export function deepFilterSections(sections: ICommonItem[], specFunctionIds: string[]) { +export function deepFilterSections( + sections: T[], + specFunctionIds: string[] +): T[] { return sections .filter( (section) => diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx index 9b79c109a6f..2e47a29d463 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx @@ -178,7 +178,7 @@ const NavigationMenuRefListItems = ({ {section.items.map((item) => ( - + ))} ) : ( From 13a9ba50ce3ff2a3a8d6c99120613b81575ec448 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Mon, 8 May 2023 21:35:34 -0600 Subject: [PATCH 12/18] fix(nav): expand function group accordion if active --- .../Navigation/NavigationMenu/NavigationMenuRefListItems.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx index 2e47a29d463..f7fc346557b 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx @@ -89,7 +89,9 @@ const RenderLink = React.memo(function RenderLink({ section, basePath }: RenderL ) } - let active = section.items.some((item) => item.id === activeAccordionItem) + let active = + section.id === activeAccordionItem || + section.items.some((item) => item.id === activeAccordionItem) return ( <> From 52cf9443d48e17b869b2d0b90dfb164a5f4bf3c6 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Mon, 8 May 2023 22:26:07 -0600 Subject: [PATCH 13/18] perf: snappy nav links in reference docs --- .../NavigationMenuRefListItems.tsx | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx index f7fc346557b..eb352b1d7e5 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx @@ -57,20 +57,30 @@ const FunctionLink = React.memo(function FunctionLink({ const router = useRouter() const activeAccordionItem = useMenuActiveRefId() + const url = `${router.basePath}${basePath}/${slug}` const active = activeAccordionItem === id + return (
  • - - - {icon && {icon}} - {title} - - + { + e.preventDefault() + history.pushState({}, '', url) + document.getElementById(slug)?.scrollIntoView() + }} + className={[ + 'cursor-pointer transition text-sm hover:text-brand-900 flex gap-3', + active ? 'text-brand-900' : 'text-scale-1000', + ].join(' ')} + > + {icon && {icon}} + {title} +
  • ) }) From 8e19b5fdf526de16aeec0950fde7955c034f6755 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Mon, 8 May 2023 22:43:32 -0600 Subject: [PATCH 14/18] fix: scroll to ref doc section when going back/forward --- .../components/reference/RefSectionHandler.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/docs/components/reference/RefSectionHandler.tsx b/apps/docs/components/reference/RefSectionHandler.tsx index eb0dbdc7455..107a2c788a3 100644 --- a/apps/docs/components/reference/RefSectionHandler.tsx +++ b/apps/docs/components/reference/RefSectionHandler.tsx @@ -26,10 +26,21 @@ const RefSectionHandler = (props: RefSectionHandlerProps) => { // When user lands on a url like http://supabase.com/docs/reference/javascript/sign-up // find the #sign-up element and scroll to that useEffect(() => { - if (document && slug !== 'start') { - document.querySelector(`#${slug}`) && document.querySelector(`#${slug}`).scrollIntoView() + document.getElementById(slug)?.scrollIntoView() + }, [slug]) + + useEffect(() => { + function handler(e: PopStateEvent) { + const [slug] = window.location.pathname.split('/').slice(-1) + document.getElementById(slug)?.scrollIntoView() } - }) + + window.addEventListener('popstate', handler) + + return () => { + window.removeEventListener('popstate', handler) + } + }, []) function getPageTitle() { switch (props.type) { From 4f9c7da788cfc90a0baa96ee032d298b65451088 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Mon, 8 May 2023 22:46:46 -0600 Subject: [PATCH 15/18] chore: remove unused active prop on nav menus --- .../Navigation/NavigationMenu/HomeMenu.tsx | 13 ++----------- .../NavigationMenu/NavigationMenu.tsx | 4 ++-- .../NavigationMenu/NavigationMenuGuideList.tsx | 18 ++---------------- 3 files changed, 6 insertions(+), 29 deletions(-) diff --git a/apps/docs/components/Navigation/NavigationMenu/HomeMenu.tsx b/apps/docs/components/Navigation/NavigationMenu/HomeMenu.tsx index b262cc1318c..968d4318a2c 100644 --- a/apps/docs/components/Navigation/NavigationMenu/HomeMenu.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/HomeMenu.tsx @@ -140,21 +140,12 @@ const home = [ ], ] -const NavigationMenuHome = ({ active }) => { +const NavigationMenuHome = () => { const router = useRouter() const { isDarkMode } = useTheme() - if (!active) { - return null - } - return ( -
    +
      {home.map((section, sectionIndex) => { return ( diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx index 4e5ecf473e4..88d09b3e194 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx @@ -234,9 +234,9 @@ function getMenuElement(menu: Menu) { const menuType = menu.type switch (menuType) { case 'home': - return + return case 'guide': - return + return case 'reference': return ( = ({ id, active, value }) => { +const NavigationMenuGuideList: React.FC = ({ id, value }) => { const router = useRouter() - if (!active) { - return null - } - const menu = NavItems[id] // get url @@ -39,16 +34,7 @@ const NavigationMenuGuideList: React.FC = ({ id, active, value }) => { key={id} type={value ? 'multiple' : 'single'} value={value ?? firstLevelRoute} - className={[ - 'transition-all duration-150 ease-out', - // enabled - active && 'opacity-100 ml-0 delay-150', - // level === 'home' && 'ml-12', - - // disabled - // level !== 'home' && level !== id ? '-ml-8' : '', - !active ? 'opacity-0 invisible absolute h-0 overflow-hidden' : '', - ].join(' ')} + className="transition-all duration-150 ease-out opacity-100 ml-0 delay-150" > From 48a52e3178a641199cb87f549955f579c2bb2458 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Tue, 9 May 2023 12:25:30 -0600 Subject: [PATCH 16/18] refactor: simplify dynamic imports for ref docs --- .../NavigationMenu/NavigationMenu.tsx | 82 ++++++------------- .../NavigationMenu/NavigationMenu.utils.ts | 64 +++++++++++++-- .../NavigationMenu/NavigationMenuRefList.tsx | 40 ++------- 3 files changed, 92 insertions(+), 94 deletions(-) diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx index 88d09b3e194..de73c85aea9 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.tsx @@ -1,39 +1,9 @@ import { useRouter } from 'next/router' import { memo, useEffect } from 'react' import { menuState, useMenuLevelId } from '~/hooks/useMenuState' +import NavigationMenuHome from './HomeMenu' import NavigationMenuGuideList from './NavigationMenuGuideList' import NavigationMenuRefList from './NavigationMenuRefList' -import NavigationMenuHome from './HomeMenu' -import { Json } from '~/types' -import { ICommonBase } from '~/components/reference/Reference.types' - -// Import dynamically to code split / reduce app bundle size -const specImports = { - specJsV1: async () => (await import('~/../../spec/supabase_js_v1.yml')).default, - specJsV2: async () => (await import('~/../../spec/supabase_js_v2.yml')).default, - specDartV0: async () => (await import('~/../../spec/supabase_dart_v0.yml')).default, - specDartV1: async () => (await import('~/../../spec/supabase_dart_v1.yml')).default, - specPythonV2: async () => (await import('~/../../spec/supabase_py_v2.yml')).default, - specCSharpV0: async () => (await import('~/../../spec/supabase_csharp_v0.yml')).default, - specSwiftV0: async () => (await import('~/../../spec/supabase_swift_v0.yml')).default, -} - -const commonSectionImports = { - apiCommonSections: async () => (await import('~/../../spec/common-api-sections.json')).default, - cliCommonSections: async () => (await import('~/../../spec/common-cli-sections.json')).default, - libCommonSections: async () => - (await import('~/../../spec/common-client-libs-sections.json')).default, - analyticsServerCommonSections: async () => - (await import('~/../../spec/common-self-hosting-analytics-sections.json')).default, - authServerCommonSections: async () => - (await import('~/../../spec/common-self-hosting-auth-sections.json')).default, - functionsServerCommonSections: async () => - (await import('~/../../spec/common-self-hosting-functions-sections.json')).default, - realtimeServerCommonSections: async () => - (await import('~/../../spec/common-self-hosting-realtime-sections.json')).default, - storageServerCommonSections: async () => - (await import('~/../../spec/common-self-hosting-storage-sections.json')).default, -} interface BaseMenu { id: string @@ -51,8 +21,8 @@ interface GuideMenu extends BaseMenu { interface ReferenceMenu extends BaseMenu { type: 'reference' - commonSectionImport: () => Promise - specImport?: () => Promise + commonSectionsFile: string + specFile?: string } type Menu = HomeMenu | GuideMenu | ReferenceMenu @@ -127,92 +97,92 @@ const menus: Menu[] = [ { id: 'reference_javascript_v1', path: '/reference/javascript/v1', - commonSectionImport: commonSectionImports.libCommonSections, - specImport: specImports.specJsV1, + commonSectionsFile: 'common-client-libs-sections.json', + specFile: 'supabase_js_v1.yml', type: 'reference', }, { id: 'reference_javascript_v2', path: '/reference/javascript', - commonSectionImport: commonSectionImports.libCommonSections, - specImport: specImports.specJsV2, + commonSectionsFile: 'common-client-libs-sections.json', + specFile: 'supabase_js_v2.yml', type: 'reference', }, { id: 'reference_dart_v0', path: '/reference/dart/v0', - commonSectionImport: commonSectionImports.libCommonSections, - specImport: specImports.specDartV0, + commonSectionsFile: 'common-client-libs-sections.json', + specFile: 'supabase_dart_v0.yml', type: 'reference', }, { id: 'reference_dart_v1', path: '/reference/dart', - commonSectionImport: commonSectionImports.libCommonSections, - specImport: specImports.specDartV1, + commonSectionsFile: 'common-client-libs-sections.json', + specFile: 'supabase_dart_v1.yml', type: 'reference', }, { id: 'reference_csharp_v0', path: '/reference/csharp', - commonSectionImport: commonSectionImports.libCommonSections, - specImport: specImports.specCSharpV0, + commonSectionsFile: 'common-client-libs-sections.json', + specFile: 'supabase_csharp_v0.yml', type: 'reference', }, { id: 'reference_python_v2', path: '/reference/python', - commonSectionImport: commonSectionImports.libCommonSections, - specImport: specImports.specPythonV2, + commonSectionsFile: 'common-client-libs-sections.json', + specFile: 'supabase_py_v2.yml', type: 'reference', }, { id: 'reference_swift_v0', path: '/reference/swift', - commonSectionImport: commonSectionImports.libCommonSections, - specImport: specImports.specSwiftV0, + commonSectionsFile: 'common-client-libs-sections.json', + specFile: 'supabase_swift_v0.yml', type: 'reference', }, { id: 'reference_cli', path: '/reference/cli', - commonSectionImport: commonSectionImports.cliCommonSections, + commonSectionsFile: 'common-cli-sections.json', type: 'reference', }, { id: 'reference_api', path: '/reference/api', - commonSectionImport: commonSectionImports.apiCommonSections, + commonSectionsFile: 'common-api-sections.json', type: 'reference', }, { id: 'reference_self_hosting_auth', path: '/reference/self-hosting-auth', - commonSectionImport: commonSectionImports.authServerCommonSections, + commonSectionsFile: 'common-self-hosting-auth-sections.json', type: 'reference', }, { id: 'reference_self_hosting_storage', path: '/reference/self-hosting-storage', - commonSectionImport: commonSectionImports.storageServerCommonSections, + commonSectionsFile: 'common-self-hosting-storage-sections.json', type: 'reference', }, { id: 'reference_self_hosting_realtime', path: '/reference/self-hosting-realtime', - commonSectionImport: commonSectionImports.realtimeServerCommonSections, + commonSectionsFile: 'common-self-hosting-realtime-sections.json', type: 'reference', }, { id: 'reference_self_hosting_analytics', path: '/reference/self-hosting-analytics', - commonSectionImport: commonSectionImports.analyticsServerCommonSections, + commonSectionsFile: 'common-self-hosting-analytics-sections.json', type: 'reference', }, { id: 'reference_self_hosting_functions', path: '/reference/self-hosting-functions', - commonSectionImport: commonSectionImports.functionsServerCommonSections, + commonSectionsFile: 'common-self-hosting-functions-sections.json', type: 'reference', }, ] @@ -242,8 +212,8 @@ function getMenuElement(menu: Menu) { ) default: diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.utils.ts b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.utils.ts index 26bb5ed5023..18aec08d326 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.utils.ts +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenu.utils.ts @@ -1,11 +1,6 @@ +import { useEffect, useState } from 'react' import { ICommonItem } from '~/components/reference/Reference.types' - -// check if the link is allowed to be displayed -export function isFuncNotInLibraryOrVersion(id, type, allowedKeys) { - if (id && allowedKeys && !allowedKeys.includes(id) && type !== 'markdown') { - return true - } -} +import { Json } from '~/types' /** * Recursively filter common sections and their sub items based on @@ -32,3 +27,58 @@ export function deepFilterSections( return section }) } + +/** + * Imports common sections file dynamically. + * + * Dynamic imports allow for code splitting which + * dramatically reduces app bundle size. + * + * See https://webpack.js.org/api/module-methods/#dynamic-expressions-in-import + */ +export function useCommonSections(commonSectionsFile: string) { + const [commonSections, setCommonSections] = useState() + + useEffect(() => { + async function fetchCommonSections() { + const commonSections = await import( + /* webpackInclude: /common-.*\.json$/ */ + /* webpackMode: "lazy" */ + `~/../../spec/${commonSectionsFile}` + ) + setCommonSections(commonSections.default) + } + fetchCommonSections() + }, [commonSectionsFile]) + + return commonSections +} + +/** + * Imports spec file dynamically. + * + * Dynamic imports allow for code splitting which + * dramatically reduces app bundle size. + * + * See https://webpack.js.org/api/module-methods/#dynamic-expressions-in-import + */ +export function useSpec(specFile?: string) { + const [spec, setSpec] = useState() + + useEffect(() => { + if (!specFile) { + return + } + async function fetchSpec() { + const spec = await import( + /* webpackInclude: /supabase_.*\.ya?ml$/ */ + /* webpackMode: "lazy" */ + `~/../../spec/${specFile}` + ) + setSpec(spec.default) + } + fetchSpec() + }, [specFile]) + + return spec +} diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefList.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefList.tsx index b4ee50d55d7..9725daa229b 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefList.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefList.tsx @@ -1,51 +1,29 @@ -import { Json } from '~/types' +import { useCommonSections, useSpec } from './NavigationMenu.utils' import NavigationMenuRefListItems from './NavigationMenuRefListItems' -import React, { useEffect, useState } from 'react' -import { ICommonBase, ICommonItem } from '~/components/reference/Reference.types' +import React from 'react' interface NavigationMenuRefListProps { id: string basePath: string - commonSectionsImport: () => Promise - specImport?: () => Promise + commonSectionsFile: string + specFile?: string } const NavigationMenuRefList = ({ id, basePath, - commonSectionsImport, - specImport, + commonSectionsFile, + specFile, }: NavigationMenuRefListProps) => { - const [commonSections, setCommonSections] = useState() - const [spec, setSpec] = useState() - - // Dynamic imports allow for code splitting which - // dramatically reduces app bundle size - useEffect(() => { - async function fetchCommonSections() { - const commonSections = await commonSectionsImport() - setCommonSections(commonSections as ICommonItem[]) - } - fetchCommonSections() - }, [commonSectionsImport]) - - useEffect(() => { - if (!specImport) { - return - } - async function fetchSpec() { - const spec = await specImport() - setSpec(spec) - } - fetchSpec() - }, [specImport]) + const commonSections = useCommonSections(commonSectionsFile) + const spec = useSpec(specFile) if (!commonSections) { return null } - if (specImport && !spec) { + if (specFile && !spec) { return null } From bb1c9b974434e30d4f242e377d1d814d570ebb87 Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Tue, 9 May 2023 15:08:19 -0600 Subject: [PATCH 17/18] fix: broken nav menu styling from merge conflicts --- .../NavigationMenuRefListItems.tsx | 73 +++++++++++-------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx index f05ebca6776..0069b311827 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuRefListItems.tsx @@ -4,17 +4,16 @@ import { useRouter } from 'next/router' import { IconChevronLeft, IconChevronUp } from 'ui' import * as NavItems from './NavigationMenu.constants' -import { useTheme } from 'common/Providers' import Image from 'next/image' import RevVersionDropdown from '~/components/RefVersionDropdown' import { useMenuActiveRefId } from '~/hooks/useMenuState' import React, { Fragment } from 'react' -import { ICommonItem, ICommonSection } from '~/components/reference/Reference.types' -import { deepFilterSections } from './NavigationMenu.utils' import { cn } from 'ui/src/utils/cn' +import { ICommonItem, ICommonSection } from '~/components/reference/Reference.types' import HomeMenuIconPicker from './HomeMenuIconPicker' +import { deepFilterSections } from './NavigationMenu.utils' const HeaderLink = React.memo(function HeaderLink(props: any) { return ( @@ -51,7 +50,7 @@ const FunctionLink = React.memo(function FunctionLink({ const active = activeAccordionItem === id return ( -
    • +
    • {icon && {icon}} {title} @@ -98,7 +97,14 @@ const RenderLink = React.memo(function RenderLink({ section, basePath }: RenderL if (!('items' in section)) { return ( - + ) } @@ -107,26 +113,33 @@ const RenderLink = React.memo(function RenderLink({ section, basePath }: RenderL section.items.some((item) => item.id === activeAccordionItem) return ( - <> - - - - - {section.items.map((item) => { - return ( - - ) - })} - - - - + + + + + {section.items.map((item) => { + return ( + + ) + })} + + + ) }) @@ -184,7 +197,7 @@ const NavigationMenuRefListItems = ({
    -
      +
        {filteredSections.map((section) => { return ( From 875bfab1b81d987d354b64f9da4e9e78bb09a33c Mon Sep 17 00:00:00 2001 From: Greg Richardson Date: Tue, 9 May 2023 16:10:32 -0600 Subject: [PATCH 18/18] fix: generate static page for each ref doc path --- apps/docs/lib/mdx/generateRefMarkdown.tsx | 17 ++++++----------- apps/docs/lib/mdx/handleRefStaticPaths.tsx | 13 +++++++------ apps/docs/lib/mdx/handleRefStaticProps.tsx | 8 ++++++-- apps/docs/pages/reference/api/[...slug].tsx | 8 ++++---- apps/docs/pages/reference/cli/[...slug].tsx | 7 ++++--- apps/docs/pages/reference/csharp/[...slug].tsx | 9 +++++---- .../reference/csharp/crawlers/[...slug].tsx | 9 +++++---- .../pages/reference/csharp/v0/[...slug].tsx | 9 +++++---- .../reference/csharp/v0/crawlers/[...slug].tsx | 7 ++++--- apps/docs/pages/reference/dart/[...slug].tsx | 9 +++++---- .../pages/reference/dart/crawlers/[...slug].tsx | 9 +++++---- apps/docs/pages/reference/dart/v0/[...slug].tsx | 7 ++++--- .../reference/dart/v0/crawlers/[...slug].tsx | 9 +++++---- .../pages/reference/javascript/[...slug].tsx | 8 +++++--- .../reference/javascript/crawlers/[...slug].tsx | 7 ++++--- .../pages/reference/javascript/v1/[...slug].tsx | 8 +++++--- .../javascript/v1/crawlers/[...slug].tsx | 8 +++++--- apps/docs/pages/reference/python/[...slug].tsx | 7 ++++--- .../reference/python/crawlers/[...slug].tsx | 7 ++++--- .../self-hosting-analytics/[...slug].tsx | 9 +++++---- .../reference/self-hosting-auth/[...slug].tsx | 9 +++++---- .../self-hosting-functions/[...slug].tsx | 9 +++++---- .../self-hosting-realtime/[...slug].tsx | 10 +++++----- .../self-hosting-storage/[...slug].tsx | 9 +++++---- apps/docs/pages/reference/swift/[...slug].tsx | 9 +++++---- .../reference/swift/crawlers/[...slug].tsx | 9 +++++---- .../docs/pages/reference/swift/v0/[...slug].tsx | 9 +++++---- .../reference/swift/v0/crawlers/[...slug].tsx | 9 +++++---- 28 files changed, 137 insertions(+), 111 deletions(-) diff --git a/apps/docs/lib/mdx/generateRefMarkdown.tsx b/apps/docs/lib/mdx/generateRefMarkdown.tsx index 1d5f7a539e9..5d959560ade 100644 --- a/apps/docs/lib/mdx/generateRefMarkdown.tsx +++ b/apps/docs/lib/mdx/generateRefMarkdown.tsx @@ -2,12 +2,9 @@ import fs from 'fs' import matter from 'gray-matter' import { serialize } from 'next-mdx-remote/serialize' +import { ICommonMarkdown } from '~/components/reference/Reference.types' -// import { remarkCodeHike } from '@code-hike/mdx' -// import codeHikeTheme from '~/codeHikeTheme.js' -// import theme from 'shiki/themes/solarized-dark.json' - -async function generateRefMarkdown(sections, slug) { +async function generateRefMarkdown(sections: ICommonMarkdown[], slug: string) { let markdownContent = [] /** * Read all the markdown files that might have @@ -16,10 +13,8 @@ async function generateRefMarkdown(sections, slug) { * - important notes regarding implementation */ await Promise.all( - sections.map(async (x, i) => { - if (!x.id) return null - - const pathName = `docs/ref${slug}/${x.id}.mdx` + sections.map(async (section) => { + const pathName = `docs/ref${slug}/${section.id}.mdx` function checkFileExists(x) { if (fs.existsSync(x)) { @@ -37,8 +32,8 @@ async function generateRefMarkdown(sections, slug) { const { data, content } = matter(fileContents) markdownContent.push({ - id: x.id, - title: x.title, + id: section.id, + title: section.title, meta: data, // introPage: introPages.includes(x), content: content diff --git a/apps/docs/lib/mdx/handleRefStaticPaths.tsx b/apps/docs/lib/mdx/handleRefStaticPaths.tsx index c1f13e4a8c4..ae7aeb1e3b4 100644 --- a/apps/docs/lib/mdx/handleRefStaticPaths.tsx +++ b/apps/docs/lib/mdx/handleRefStaticPaths.tsx @@ -1,13 +1,14 @@ -import { getAllDocs } from '../docs' - -async function handleRefGetStaticPaths() { - let docs = getAllDocs() +import { ICommonSection } from '~/components/reference/Reference.types' +async function handleRefGetStaticPaths(sections: ICommonSection[], libraryPath: string) { return { - paths: docs.map(() => { + paths: sections.map((section) => { return { params: { - slug: docs.map((d) => d.slug), + slug: libraryPath + .split('/') + .filter((dir) => !!dir) + .concat(section.slug), }, } }), diff --git a/apps/docs/lib/mdx/handleRefStaticProps.tsx b/apps/docs/lib/mdx/handleRefStaticProps.tsx index c97245387f9..56c6c159ed0 100644 --- a/apps/docs/lib/mdx/handleRefStaticProps.tsx +++ b/apps/docs/lib/mdx/handleRefStaticProps.tsx @@ -1,7 +1,11 @@ +import { ICommonMarkdown, ICommonSection } from '~/components/reference/Reference.types' import generateRefMarkdown from '~/lib/mdx/generateRefMarkdown' -async function handleRefStaticProps(sections, librarypath) { - let markdownContent = await generateRefMarkdown(sections, librarypath) +async function handleRefStaticProps(sections: ICommonSection[], libraryPath: string) { + const markdownSections = sections.filter( + (section): section is ICommonMarkdown => section.type === 'markdown' + ) + const markdownContent = await generateRefMarkdown(markdownSections, libraryPath) return { props: { diff --git a/apps/docs/pages/reference/api/[...slug].tsx b/apps/docs/pages/reference/api/[...slug].tsx index 382c882a190..ca4c7128256 100644 --- a/apps/docs/pages/reference/api/[...slug].tsx +++ b/apps/docs/pages/reference/api/[...slug].tsx @@ -8,17 +8,17 @@ import { gen_v3 } from '~/lib/refGenerator/helpers' // @ts-ignore const generatedSpec = gen_v3(specFile, 'wat', { apiUrl: 'apiv0' }) - const sections = flattenSections(apiCommonSections) +const libraryPath = '/api' export default function Config(props) { return } export async function getStaticProps() { - return handleRefStaticProps(sections, '/api') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/cli/[...slug].tsx b/apps/docs/pages/reference/cli/[...slug].tsx index 5af245300ef..1fe46fa04a9 100644 --- a/apps/docs/pages/reference/cli/[...slug].tsx +++ b/apps/docs/pages/reference/cli/[...slug].tsx @@ -8,15 +8,16 @@ import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths' import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' const sections = flattenSections(cliCommonSections) +const libraryPath = '/cli' export default function CliRef(props) { return } export async function getStaticProps() { - return handleRefStaticProps(sections, '/cli') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/csharp/[...slug].tsx b/apps/docs/pages/reference/csharp/[...slug].tsx index 17b26f498a4..c3ba488e1b1 100644 --- a/apps/docs/pages/reference/csharp/[...slug].tsx +++ b/apps/docs/pages/reference/csharp/[...slug].tsx @@ -6,15 +6,16 @@ import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths' import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/csharp' -export default function JSReference(props) { +export default function CSharpReference(props) { return } export async function getStaticProps() { - return handleRefStaticProps(sections, '/csharp') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/csharp/crawlers/[...slug].tsx b/apps/docs/pages/reference/csharp/crawlers/[...slug].tsx index f94729d7482..fc03fefa015 100644 --- a/apps/docs/pages/reference/csharp/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/csharp/crawlers/[...slug].tsx @@ -9,8 +9,9 @@ import { useRouter } from 'next/router' import RefSEO from '~/components/reference/RefSEO' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/csharp' -export default function JSReference(props) { +export default function CSharpReference(props) { const router = useRouter() const slug = router.query.slug[0] const filteredSection = sections.filter((section) => section.id === slug) @@ -35,9 +36,9 @@ export default function JSReference(props) { } export async function getStaticProps() { - return handleRefStaticProps(sections, '/csharp') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/csharp/v0/[...slug].tsx b/apps/docs/pages/reference/csharp/v0/[...slug].tsx index 92e4d0a5b9c..f8a6e985d1e 100644 --- a/apps/docs/pages/reference/csharp/v0/[...slug].tsx +++ b/apps/docs/pages/reference/csharp/v0/[...slug].tsx @@ -6,15 +6,16 @@ import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths' import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/csharp/v0' -export default function JSReference(props) { +export default function CSharpReference(props) { return } export async function getStaticProps() { - return handleRefStaticProps(sections, '/csharp/v0') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/csharp/v0/crawlers/[...slug].tsx b/apps/docs/pages/reference/csharp/v0/crawlers/[...slug].tsx index d4c26ddf9dd..18ee28ca14f 100644 --- a/apps/docs/pages/reference/csharp/v0/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/csharp/v0/crawlers/[...slug].tsx @@ -9,6 +9,7 @@ import { useRouter } from 'next/router' import RefSEO from '~/components/reference/RefSEO' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/csharp/v0' export default function JSReference(props) { const router = useRouter() @@ -34,9 +35,9 @@ export default function JSReference(props) { } export async function getStaticProps() { - return handleRefStaticProps(sections, '/csharp/v0') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/dart/[...slug].tsx b/apps/docs/pages/reference/dart/[...slug].tsx index 6cd14595a69..b452d04d84f 100644 --- a/apps/docs/pages/reference/dart/[...slug].tsx +++ b/apps/docs/pages/reference/dart/[...slug].tsx @@ -6,15 +6,16 @@ import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths' import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/dart' -export default function JSReference(props) { +export default function DartReference(props) { return } export async function getStaticProps() { - return handleRefStaticProps(sections, '/dart') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/dart/crawlers/[...slug].tsx b/apps/docs/pages/reference/dart/crawlers/[...slug].tsx index 54aef81d9c1..29a9f880840 100644 --- a/apps/docs/pages/reference/dart/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/dart/crawlers/[...slug].tsx @@ -9,8 +9,9 @@ import { useRouter } from 'next/router' import RefSEO from '~/components/reference/RefSEO' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/dart' -export default function JSReference(props) { +export default function DartReference(props) { const router = useRouter() const slug = router.query.slug[0] const filteredSection = sections.filter((section) => section.slug === slug) @@ -35,9 +36,9 @@ export default function JSReference(props) { } export async function getStaticProps() { - return handleRefStaticProps(sections, '/dart') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/dart/v0/[...slug].tsx b/apps/docs/pages/reference/dart/v0/[...slug].tsx index 455b8cdfbe5..b30b791db60 100644 --- a/apps/docs/pages/reference/dart/v0/[...slug].tsx +++ b/apps/docs/pages/reference/dart/v0/[...slug].tsx @@ -6,15 +6,16 @@ import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths' import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/dart/v0' export default function JSReference(props) { return } export async function getStaticProps() { - return handleRefStaticProps(sections, '/dart/v0') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/dart/v0/crawlers/[...slug].tsx b/apps/docs/pages/reference/dart/v0/crawlers/[...slug].tsx index 459912b8b35..1c2949b24a7 100644 --- a/apps/docs/pages/reference/dart/v0/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/dart/v0/crawlers/[...slug].tsx @@ -9,8 +9,9 @@ import { useRouter } from 'next/router' import RefSEO from '~/components/reference/RefSEO' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/dart/v0' -export default function JSReference(props) { +export default function DartReference(props) { const router = useRouter() const slug = router.query.slug[0] const filteredSection = sections.filter((section) => section.slug === slug) @@ -34,9 +35,9 @@ export default function JSReference(props) { } export async function getStaticProps() { - return handleRefStaticProps(sections, '/dart/v0') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/javascript/[...slug].tsx b/apps/docs/pages/reference/javascript/[...slug].tsx index 244fe6c28ae..24b8a0011ed 100644 --- a/apps/docs/pages/reference/javascript/[...slug].tsx +++ b/apps/docs/pages/reference/javascript/[...slug].tsx @@ -1,3 +1,4 @@ +import { inspect } from 'util' import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' import spec from '~/../../spec/supabase_js_v2.yml' assert { type: 'yml' } @@ -7,6 +8,7 @@ import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths' import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/javascript' export default function JSReference(props) { return ( @@ -21,9 +23,9 @@ export default function JSReference(props) { } export async function getStaticProps() { - return handleRefStaticProps(sections, '/javascript') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/javascript/crawlers/[...slug].tsx b/apps/docs/pages/reference/javascript/crawlers/[...slug].tsx index 34c4ee78943..658469669d1 100644 --- a/apps/docs/pages/reference/javascript/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/javascript/crawlers/[...slug].tsx @@ -9,6 +9,7 @@ import { useRouter } from 'next/router' import RefSEO from '~/components/reference/RefSEO' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/javascript' export default function JSReference(props) { const router = useRouter() @@ -35,9 +36,9 @@ export default function JSReference(props) { } export async function getStaticProps() { - return handleRefStaticProps(sections, '/javascript') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/javascript/v1/[...slug].tsx b/apps/docs/pages/reference/javascript/v1/[...slug].tsx index e7a5b4bf8d1..364b3e667ac 100644 --- a/apps/docs/pages/reference/javascript/v1/[...slug].tsx +++ b/apps/docs/pages/reference/javascript/v1/[...slug].tsx @@ -1,3 +1,4 @@ +import { inspect } from 'util' import clientLibsCommonSections from '~/../../spec/common-client-libs-sections.json' import typeSpec from '~/../../spec/enrichments/tsdoc_v1/combined.json' import spec from '~/../../spec/supabase_js_v1.yml' assert { type: 'yml' } @@ -7,6 +8,7 @@ import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths' import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/javascript/v1' export default function JSReference(props) { return ( @@ -21,9 +23,9 @@ export default function JSReference(props) { } export async function getStaticProps() { - return handleRefStaticProps(sections, '/javascript/v1') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/javascript/v1/crawlers/[...slug].tsx b/apps/docs/pages/reference/javascript/v1/crawlers/[...slug].tsx index 64a6816669d..d040ffa7ec5 100644 --- a/apps/docs/pages/reference/javascript/v1/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/javascript/v1/crawlers/[...slug].tsx @@ -7,7 +7,9 @@ import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths' import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' import { useRouter } from 'next/router' import RefSEO from '~/components/reference/RefSEO' + const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/javascript/v1' export default function JSReference(props) { const router = useRouter() @@ -34,9 +36,9 @@ export default function JSReference(props) { } export async function getStaticProps() { - return handleRefStaticProps(sections, '/javascript/v1') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/python/[...slug].tsx b/apps/docs/pages/reference/python/[...slug].tsx index d0b6ae951dd..3da995dd993 100644 --- a/apps/docs/pages/reference/python/[...slug].tsx +++ b/apps/docs/pages/reference/python/[...slug].tsx @@ -7,6 +7,7 @@ import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths' import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/python' export default function PyReference(props) { return ( @@ -21,9 +22,9 @@ export default function PyReference(props) { } export async function getStaticProps() { - return handleRefStaticProps(sections, '/python') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/python/crawlers/[...slug].tsx b/apps/docs/pages/reference/python/crawlers/[...slug].tsx index 0ccb2c18cce..ca70d55716f 100644 --- a/apps/docs/pages/reference/python/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/python/crawlers/[...slug].tsx @@ -9,6 +9,7 @@ import { useRouter } from 'next/router' import RefSEO from '~/components/reference/RefSEO' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/python' export default function PyReference(props) { const router = useRouter() @@ -35,9 +36,9 @@ export default function PyReference(props) { } export async function getStaticProps() { - return handleRefStaticProps(sections, '/python') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/self-hosting-analytics/[...slug].tsx b/apps/docs/pages/reference/self-hosting-analytics/[...slug].tsx index 5f78d5830ff..46827290444 100644 --- a/apps/docs/pages/reference/self-hosting-analytics/[...slug].tsx +++ b/apps/docs/pages/reference/self-hosting-analytics/[...slug].tsx @@ -7,18 +7,19 @@ import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' import { gen_v3 } from '~/lib/refGenerator/helpers' const sections = flattenSections(selfHostingAnalyticsCommonSections) +const libraryPath = '/self-hosting-analytics' // @ts-ignore const spec = gen_v3(analyticsSpec, 'wat', { apiUrl: 'apiv0' }) -export default function JSReference(props) { +export default function SelfHostAnalyticsReference(props) { return } export async function getStaticProps() { - return handleRefStaticProps(sections, '/self-hosting-analytics') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/self-hosting-auth/[...slug].tsx b/apps/docs/pages/reference/self-hosting-auth/[...slug].tsx index c7b2382af16..27e8a909182 100644 --- a/apps/docs/pages/reference/self-hosting-auth/[...slug].tsx +++ b/apps/docs/pages/reference/self-hosting-auth/[...slug].tsx @@ -7,18 +7,19 @@ import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' import { gen_v3 } from '~/lib/refGenerator/helpers' const sections = flattenSections(selfHostingAuthCommonSections) +const libraryPath = '/self-hosting-auth' // @ts-ignore const spec = gen_v3(authSpec, 'wat', { apiUrl: 'apiv0' }) -export default function JSReference(props) { +export default function SelfHostAuthReference(props) { return } export async function getStaticProps() { - return handleRefStaticProps(sections, '/self-hosting-auth') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/self-hosting-functions/[...slug].tsx b/apps/docs/pages/reference/self-hosting-functions/[...slug].tsx index cf4639365fb..5d01436b310 100644 --- a/apps/docs/pages/reference/self-hosting-functions/[...slug].tsx +++ b/apps/docs/pages/reference/self-hosting-functions/[...slug].tsx @@ -7,15 +7,16 @@ import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' import { gen_v3 } from '~/lib/refGenerator/helpers' const sections = flattenSections(selfHostingFunctionsCommonSections) +const libraryPath = '/self-hosting-functions' -export default function JSReference(props) { +export default function SelfHostFunctionsReference(props) { return } export async function getStaticProps() { - return handleRefStaticProps(sections, '/self-hosting-functions') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/self-hosting-realtime/[...slug].tsx b/apps/docs/pages/reference/self-hosting-realtime/[...slug].tsx index 49e91894a06..c5039628929 100644 --- a/apps/docs/pages/reference/self-hosting-realtime/[...slug].tsx +++ b/apps/docs/pages/reference/self-hosting-realtime/[...slug].tsx @@ -4,18 +4,18 @@ import RefSectionHandler from '~/components/reference/RefSectionHandler' import { flattenSections } from '~/lib/helpers' import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths' import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' -import { gen_v3 } from '~/lib/refGenerator/helpers' const sections = flattenSections(selfHostingRealtimeCommonSections) +const libraryPath = '/self-hosting-realtime' -export default function JSReference(props) { +export default function SelfHostRealtimeReference(props) { return } export async function getStaticProps() { - return handleRefStaticProps(sections, '/self-hosting-realtime') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/self-hosting-storage/[...slug].tsx b/apps/docs/pages/reference/self-hosting-storage/[...slug].tsx index 1b4b99fb9c8..7e55171583e 100644 --- a/apps/docs/pages/reference/self-hosting-storage/[...slug].tsx +++ b/apps/docs/pages/reference/self-hosting-storage/[...slug].tsx @@ -7,18 +7,19 @@ import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' import { gen_v3 } from '~/lib/refGenerator/helpers' const sections = flattenSections(selfHostingStorageCommonSections) +const libraryPath = '/self-hosting-storage' // @ts-ignore const spec = gen_v3(storageSpec, 'wat', { apiUrl: 'apiv0' }) -export default function JSReference(props) { +export default function SelfHostStorageReference(props) { return } export async function getStaticProps() { - return handleRefStaticProps(sections, '/self-hosting-storage') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/swift/[...slug].tsx b/apps/docs/pages/reference/swift/[...slug].tsx index dd1ffb3354e..22cb67c6f98 100644 --- a/apps/docs/pages/reference/swift/[...slug].tsx +++ b/apps/docs/pages/reference/swift/[...slug].tsx @@ -6,15 +6,16 @@ import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths' import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/swift' -export default function JSReference(props) { +export default function SwiftReference(props) { return } export async function getStaticProps() { - return handleRefStaticProps(sections, '/swift') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/swift/crawlers/[...slug].tsx b/apps/docs/pages/reference/swift/crawlers/[...slug].tsx index 644925aeac4..f88e25b8997 100644 --- a/apps/docs/pages/reference/swift/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/swift/crawlers/[...slug].tsx @@ -9,8 +9,9 @@ import { useRouter } from 'next/router' import RefSEO from '~/components/reference/RefSEO' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/swift' -export default function JSReference(props) { +export default function SwiftReference(props) { const router = useRouter() const slug = router.query.slug[0] const filteredSection = sections.filter((section) => section.id === slug) @@ -35,9 +36,9 @@ export default function JSReference(props) { } export async function getStaticProps() { - return handleRefStaticProps(sections, '/swift') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/swift/v0/[...slug].tsx b/apps/docs/pages/reference/swift/v0/[...slug].tsx index 3e2e253dc6a..cdf3662f63b 100644 --- a/apps/docs/pages/reference/swift/v0/[...slug].tsx +++ b/apps/docs/pages/reference/swift/v0/[...slug].tsx @@ -6,15 +6,16 @@ import handleRefGetStaticPaths from '~/lib/mdx/handleRefStaticPaths' import handleRefStaticProps from '~/lib/mdx/handleRefStaticProps' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/swift/v0' -export default function JSReference(props) { +export default function SwiftReference(props) { return } export async function getStaticProps() { - return handleRefStaticProps(sections, '/swift/v0') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) } diff --git a/apps/docs/pages/reference/swift/v0/crawlers/[...slug].tsx b/apps/docs/pages/reference/swift/v0/crawlers/[...slug].tsx index 099dfb582a8..bf3bc4bc449 100644 --- a/apps/docs/pages/reference/swift/v0/crawlers/[...slug].tsx +++ b/apps/docs/pages/reference/swift/v0/crawlers/[...slug].tsx @@ -9,8 +9,9 @@ import { useRouter } from 'next/router' import RefSEO from '~/components/reference/RefSEO' const sections = flattenSections(clientLibsCommonSections) +const libraryPath = '/swift/v0' -export default function JSReference(props) { +export default function SwiftReference(props) { const router = useRouter() const slug = router.query.slug[0] const filteredSection = sections.filter((section) => section.id === slug) @@ -34,9 +35,9 @@ export default function JSReference(props) { } export async function getStaticProps() { - return handleRefStaticProps(sections, '/swift/v0') + return handleRefStaticProps(sections, libraryPath) } -export function getStaticPaths() { - return handleRefGetStaticPaths() +export async function getStaticPaths() { + return handleRefGetStaticPaths(sections, libraryPath) }