diff --git a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideList.tsx b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideList.tsx index 024d71988be..2ba4c5790f7 100644 --- a/apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideList.tsx +++ b/apps/docs/components/Navigation/NavigationMenu/NavigationMenuGuideList.tsx @@ -43,8 +43,8 @@ const NavigationMenuGuideList = ({ currentLevel, setLevel, id }) => {
{/*
*/} @@ -66,7 +66,7 @@ const NavigationMenuGuideList = ({ currentLevel, setLevel, id }) => { {menu.items.map((x, index) => { // console.log('1st type of link?', x.items && x.items.length > 0) - console.log() + // console.log() return (
{x.items && x.items.length > 0 ? ( diff --git a/apps/docs/layouts/ref/RefSubLayout.tsx b/apps/docs/layouts/ref/RefSubLayout.tsx index 598799ee767..af31c8061d1 100644 --- a/apps/docs/layouts/ref/RefSubLayout.tsx +++ b/apps/docs/layouts/ref/RefSubLayout.tsx @@ -33,7 +33,6 @@ const RefSubLayout: FC & RefSubLayoutSubComponents = (props) = } const Section: FC = (props) => { - console.log({ props }) return (
diff --git a/apps/docs/package.json b/apps/docs/package.json index e5b93c4dfb8..70fea8a13d7 100644 --- a/apps/docs/package.json +++ b/apps/docs/package.json @@ -50,6 +50,7 @@ "dotenv": "^16.0.3", "graphql": "^16.5.0", "gray-matter": "^4.0.3", + "isbot": "^3.6.5", "jsrsasign": "^10.5.26", "lodash": "^4.17.21", "markdown-toc": "^1.2.0", diff --git a/apps/docs/pages/_middleware.ts b/apps/docs/pages/_middleware.ts index 7b7ed1f968b..733d4538a8f 100644 --- a/apps/docs/pages/_middleware.ts +++ b/apps/docs/pages/_middleware.ts @@ -1,15 +1,20 @@ import { NextResponse } from 'next/server' import type { NextRequest } from 'next/server' +import isbot from 'isbot' // This function can be marked `async` if using `await` inside export function middleware(request: NextRequest) { - const headers = new Headers(request.headers) - console.log('middleware?') - console.log({ headers }) - //return NextResponse.redirect(new URL('/about-2', request.url)) -} + if (!isbot(request.headers.get('user-agent'))) return -// See "Matching Paths" below to learn more -export const config = { - //matcher: '/about/:path*', + const clientLibs = ['javascript', 'dart'] + + for (const lib of clientLibs) { + if (request.url.includes(`reference/${lib}`)) { + const requestSlug = request.url.split('/').pop() + + return NextResponse.rewrite( + new URL(`/docs/reference/${lib}/crawlers/${requestSlug}`, request.url).toString() + ) + } + } } diff --git a/apps/docs/pages/reference/javascript/[...slug].tsx b/apps/docs/pages/reference/javascript/[...slug].tsx index 5c5a335ec97..8117b0bcba6 100644 --- a/apps/docs/pages/reference/javascript/[...slug].tsx +++ b/apps/docs/pages/reference/javascript/[...slug].tsx @@ -60,7 +60,6 @@ export default function JSReference(props) { return ( {jsSpec.functions.map((item, itemIndex) => { - console.log({ item }) const hasTsRef = item['$ref'] || null const tsDefinition = hasTsRef && extractTsDocNode(hasTsRef, jsTypeSpec) const parameters = hasTsRef ? generateParameters(tsDefinition) : '' diff --git a/apps/docs/pages/reference/javascript/crawlers/[...slug].tsx b/apps/docs/pages/reference/javascript/crawlers/[...slug].tsx new file mode 100644 index 00000000000..5cf27276b80 --- /dev/null +++ b/apps/docs/pages/reference/javascript/crawlers/[...slug].tsx @@ -0,0 +1,330 @@ +import { useEffect } from 'react' +import fs from 'fs' +import toc from 'markdown-toc' + +import matter from 'gray-matter' +import { MDXRemote } from 'next-mdx-remote' +import { serialize } from 'next-mdx-remote/serialize' +import components from '~/components/index' +import { getAllDocs, getDocsBySlug } from '~/lib/docs' + +import ReactMarkdown from 'react-markdown' + +// @ts-ignore +import jsTypeSpec from '~/../../spec/enrichments/tsdoc_v2/combined.json' +// @ts-ignore +import examples from '~/../../spec/examples/examples.yml' assert { type: 'yml' } +// @ts-expect-error +import jsSpec from '~/../../spec/supabase_js_v2_temp_new_shape.yml' assert { type: 'yml' } +// @ts-expect-error +import commonLibSpec from '~/../../spec/common-client-libs.yml' assert { type: 'yml' } + +import { IconDatabase, Tabs } from 'ui' +import CodeBlock from '~/components/CodeBlock/CodeBlock' + +import { useRouter } from 'next/router' +import { extractTsDocNode, generateParameters } from '~/lib/refGenerator/helpers' +import { ComesFrom } from '~/components/ComesFrom' +import Param from '~/components/Params' +import Options from '~/components/Options' +import RefSubLayout from '~/layouts/ref/RefSubLayout' + +import OldLayout from '~/layouts/Default' + +export default function JSReference(props) { + const router = useRouter() + + // will be something like: auth-signout + const slug = router.query.slug[0] + + // look in the common-libs file for that slug, return its id + const commonId = commonLibSpec.functions.find((fn) => fn.slug === slug).id + + const requestedFunction = jsSpec.functions.find((fn) => fn.id === commonId) + + /* + * handle old ref pages + */ + if (process.env.NEXT_PUBLIC_NEW_DOCS === 'false') { + return ( + // @ts-ignore + + + + ) + } + + const hasTsRef = requestedFunction['$ref'] || null + const tsDefinition = hasTsRef && extractTsDocNode(hasTsRef, jsTypeSpec) + const parameters = hasTsRef ? generateParameters(tsDefinition) : '' + + //const functionMarkdownContent = props?.docs[itemIndex]?.content + const shortText = hasTsRef ? tsDefinition.signatures[0].comment.shortText : '' + + return ( + + <> + fn.id === requestedFunction.id)?.title ?? + examples.functions.find((fn) => fn.id === requestedFunction.id)?.id ?? + requestedFunction.name ?? + requestedFunction.id + } + id={requestedFunction.id} + slug={ + commonLibSpec.functions.find((commonItem) => commonItem.id === requestedFunction.id) + .slug + } + > + + <> +
+ {shortText && ( + <> +

+ + )} +
+ + {requestedFunction.description && ( +
+

{requestedFunction.description}

+
+ )} + {/* {functionMarkdownContent && ( +
+ +
+ )} */} + {requestedFunction.notes && ( +
+ {requestedFunction.notes} +
+ )} + {/* // parameters */} + {parameters && ( +
+
Parameters
+
    + {parameters.map((param) => { + // grab override params from yaml file + const overrideParams = requestedFunction.overrideParams + + // params from the yaml file can override the params from parameters if it matches the name + const overide = overrideParams?.filter((x) => { + return param.name === x.name + }) + + const paramItem = overide?.length > 0 ? overide[0] : param + + return ( + + {paramItem.subContent && ( +
    + + {param.subContent.map((param) => { + return + })} + +
    + )} + + ) + })} +
+
+ )} + +
+ + {requestedFunction.examples && ( + <> + {' '} + + + {requestedFunction.examples && + requestedFunction.examples.map((example, exampleIndex) => { + const exampleString = ` + import { createClient } from '@supabase/supabase-js' + + // Create a single supabase client for interacting with your database + const supabase = createClient('https://xyzcompany.supabase.co', 'public-anon-key') + ` + const currentExampleId = example.id + const staticExample = requestedFunction.examples[exampleIndex] + + const response = staticExample.response + const sql = staticExample?.data?.sql + const tables = staticExample?.data?.tables + + return ( + + {tables && + tables.length > 0 && + tables.map((table) => { + return ( +
+
+
+
+ +
+
{table.name}
+
+
+
+ ) + })} + {sql && ( + + {sql} + + )} + + {exampleString + + (example.code && + example.code + .replace('```', '') + .replace('js', '') + .replace('```', ''))} + + {response && ( + <> + + + {response} + + + )} +
+ ) + })} +
+ + )} +
+
+ +
+ ) +} + +export async function getStaticProps({ params }: { params: { slug: string[] } }) { + const pages = jsSpec.functions.map((x) => x.id) + + /** + * Read all the markdown files that might have + * - custom text + * - call outs + * - important notes regarding implementation + */ + const allMarkdownDocs = await Promise.all( + pages.map(async (x, i) => { + const pathName = `docs/ref/js/${x}.mdx` + + function checkFileExists(x) { + // console.log('checking this ', x) + if (fs.existsSync(x)) { + return true + } else { + return false + } + } + + const markdownExists = checkFileExists(pathName) + + const fileContents = markdownExists ? fs.readFileSync(pathName, 'utf8') : '' + const { data, content } = matter(fileContents) + + return { + id: x, + title: x, + // ...content, + meta: data, + content: content ? await serialize(content || '') : null, + } + }) + ) + + /* + * old content generation + * this is for grabbing to old markdown files + */ + + let slug + if (params.slug.length > 1) { + slug = `docs/reference/javascript/${params.slug.join('/')}` + } else { + slug = `docs/reference/javascript/${params.slug[0]}` + } + + let doc = getDocsBySlug(slug) + const content = await serialize(doc.content || '') + + /* + * handle old ref pages + */ + if (process.env.NEXT_PUBLIC_NEW_DOCS === 'false') { + return { + props: { + /* + * old reference docs are below + */ + ...doc, + content, + toc: toc(doc.content, { maxdepth: 1, firsth1: false }), + }, + } + } else { + return { + props: { + docs: allMarkdownDocs, + }, + } + } +} + +export function getStaticPaths() { + let docs = getAllDocs() + + return { + paths: docs.map(() => { + return { + params: { + slug: docs.map((d) => d.slug), + }, + } + }), + fallback: 'blocking', + } +} diff --git a/package-lock.json b/package-lock.json index aa43ea6420d..93857f5ac45 100644 --- a/package-lock.json +++ b/package-lock.json @@ -57,6 +57,7 @@ "dotenv": "^16.0.3", "graphql": "^16.5.0", "gray-matter": "^4.0.3", + "isbot": "^3.6.5", "jsrsasign": "^10.5.26", "lodash": "^4.17.21", "markdown-toc": "^1.2.0", @@ -20428,6 +20429,14 @@ "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", "dev": true }, + "node_modules/isbot": { + "version": "3.6.5", + "resolved": "https://registry.npmjs.org/isbot/-/isbot-3.6.5.tgz", + "integrity": "sha512-BchONELXt6yMad++BwGpa0oQxo/uD0keL7N15cYVf0A1oMIoNQ79OqeYdPMFWDrNhCqCbRuw9Y9F3QBjvAxZ5g==", + "engines": { + "node": ">=12" + } + }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -49429,6 +49438,7 @@ "globby": "^12.0.2", "graphql": "^16.5.0", "gray-matter": "^4.0.3", + "isbot": "*", "jsrsasign": "^10.5.26", "lodash": "^4.17.21", "markdown-toc": "^1.2.0", @@ -53296,6 +53306,11 @@ "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", "dev": true }, + "isbot": { + "version": "3.6.5", + "resolved": "https://registry.npmjs.org/isbot/-/isbot-3.6.5.tgz", + "integrity": "sha512-BchONELXt6yMad++BwGpa0oQxo/uD0keL7N15cYVf0A1oMIoNQ79OqeYdPMFWDrNhCqCbRuw9Y9F3QBjvAxZ5g==" + }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",