Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

feat: Add ai/python federated content and data (#48043)

Jeremias Menichelli7ce1291bb727
diff --git a/apps/docs/.gitignore b/apps/docs/.gitignore
index fd14b1c048b..59e71b63a89 100644
--- a/apps/docs/.gitignore
+++ b/apps/docs/.gitignore
@@ -47,6 +47,7 @@ public/docs/
/content/guides/deployment/terraform.mdx
/content/guides/deployment/terraform/tutorial.mdx
/content/guides/deployment/ci/
+/content/guides/ai/python/
# Downloaded TypeDoc dumps under spec/reference/<lib>/<ver>/. Regenerated by
# `cd apps/docs/spec && make download.tsdoc.v2`. Hand-authored files in the
diff --git a/apps/docs/app/guides/ai/python/[[...slug]]/page.tsx b/apps/docs/app/guides/ai/python/[[...slug]]/page.tsx
new file mode 100644
index 00000000000..6c0b8fbbb29
--- /dev/null
+++ b/apps/docs/app/guides/ai/python/[[...slug]]/page.tsx
@@ -0,0 +1,26 @@
+import { GuideTemplate } from '~/features/docs/GuidesMdx.template'
+import {
+ genGuideMeta,
+ genGuidesStaticParams,
+ getGuidesMarkdown,
+} from '~/features/docs/GuidesMdx.utils'
+import { getEmptyArray } from '~/features/helpers.fn'
+import { IS_DEV } from '~/lib/constants'
+
+type Params = { slug?: string[] }
+
+const PythonClientDocs = async (props: { params: Promise<Params> }) => {
+ const params = await props.params
+ const slug = ['ai', 'python', ...(params.slug ?? [])]
+ const data = await getGuidesMarkdown(slug)
+
+ return <GuideTemplate {...data!} />
+}
+
+const generateStaticParams = !IS_DEV ? genGuidesStaticParams('ai/python') : getEmptyArray
+const generateMetadata = genGuideMeta((params: { slug?: string[] }) =>
+ getGuidesMarkdown(['ai', 'python', ...(params.slug ?? [])])
+)
+
+export default PythonClientDocs
+export { generateStaticParams, generateMetadata }
diff --git a/apps/docs/app/guides/ai/python/[slug]/page.tsx b/apps/docs/app/guides/ai/python/[slug]/page.tsx
deleted file mode 100644
index e31bc6b1595..00000000000
--- a/apps/docs/app/guides/ai/python/[slug]/page.tsx
+++ /dev/null
@@ -1,135 +0,0 @@
-import { notFound } from 'next/navigation'
-import { relative } from 'path'
-import rehypeSlug from 'rehype-slug'
-
-import { GuideTemplate, newEditLink } from '~/features/docs/GuidesMdx.template'
-import { genGuideMeta, removeRedundantH1 } from '~/features/docs/GuidesMdx.utils'
-import { getGitHubFileContents } from '~/lib/octokit'
-import { UrlTransformFunction, linkTransform } from '~/lib/mdx/plugins/rehypeLinkTransform'
-import remarkMkDocsAdmonition from '~/lib/mdx/plugins/remarkAdmonition'
-import { removeTitle } from '~/lib/mdx/plugins/remarkRemoveTitle'
-import { SerializeOptions } from '~/types/next-mdx-remote-serialize'
-
-export const dynamicParams = false
-
-// We fetch these docs at build time from an external repo
-const org = 'supabase'
-const repo = 'vecs'
-const branch = 'main'
-const docsDir = 'docs'
-const externalSite = 'https://supabase.github.io/vecs'
-
-// Each external docs page is mapped to a local page
-const pageMap = [
- {
- slug: 'api',
- meta: {
- title: 'API',
- },
- remoteFile: 'api.md',
- },
- {
- slug: 'collections',
- meta: {
- title: 'Collections',
- },
- remoteFile: 'concepts_collections.md',
- },
- {
- slug: 'indexes',
- meta: {
- title: 'Indexes',
- },
- remoteFile: 'concepts_indexes.md',
- },
- {
- slug: 'metadata',
- meta: {
- title: 'Metadata',
- },
- remoteFile: 'concepts_metadata.md',
- },
-]
-
-interface Params {
- slug: string
-}
-
-const PythonClientDocs = async (props: { params: Promise<Params> }) => {
- const params = await props.params
- const { meta, ...data } = await getContent(params)
-
- const options = {
- mdxOptions: {
- remarkPlugins: [remarkMkDocsAdmonition, [removeTitle, meta.title]],
- rehypePlugins: [[linkTransform, urlTransform], rehypeSlug],
- },
- } as SerializeOptions
-
- return <GuideTemplate mdxOptions={options} meta={meta} {...data} />
-}
-
-/**
- * Fetch markdown from external repo
- */
-const getContent = async ({ slug }: Params) => {
- const page = pageMap.find(({ slug: validSlug }) => validSlug && validSlug === slug)
-
- if (!page) {
- notFound()
- }
-
- const { remoteFile, meta } = page
-
- const editLink = newEditLink(`${org}/${repo}/blob/${branch}/${docsDir}/${remoteFile}`)
-
- const content = removeRedundantH1(
- await getGitHubFileContents({ org, repo, path: `${docsDir}/${remoteFile}`, branch })
- )
-
- return {
- pathname: `/guides/ai/python/${slug}` satisfies `/${string}`,
- meta,
- content,
- editLink,
- }
-}
-
-const urlTransform: UrlTransformFunction = (url) => {
- try {
- const externalSiteUrl = new URL(externalSite)
-
- const placeholderHostname = 'placeholder'
- const { hostname, pathname, hash } = new URL(url, `http://${placeholderHostname}`)
-
- // Don't modify a url with a FQDN or a url that's only a hash
- if (hostname !== placeholderHostname || pathname === '/') {
- return url
- }
-
- const relativePage = (
- pathname.endsWith('.md')
- ? pathname.replace(/\.md$/, '')
- : relative(externalSiteUrl.pathname, pathname)
- ).replace(/^\//, '')
-
- const page = pageMap.find(({ remoteFile }) => `${relativePage}.md` === remoteFile)
-
- // If we have a mapping for this page, use the mapped path
- if (page) {
- return page.slug + hash
- }
-
- // If we don't have this page in our docs, link to original docs
- return `${externalSite}/${relativePage}${hash}`
- } catch (err) {
- console.error('Error transforming markdown URL', err)
- return url
- }
-}
-
-const generateStaticParams = () => pageMap.map(({ slug }) => ({ slug }))
-const generateMetadata = genGuideMeta(getContent)
-
-export default PythonClientDocs
-export { generateMetadata, generateStaticParams }
diff --git a/apps/docs/scripts/federated-content/sources/python.ts b/apps/docs/scripts/federated-content/sources/python.ts
new file mode 100644
index 00000000000..d117cc31987
--- /dev/null
+++ b/apps/docs/scripts/federated-content/sources/python.ts
@@ -0,0 +1,43 @@
+import type { FederatedContentSource } from '../types'
+
+// We fetch these docs at build time from an external repo
+const python: FederatedContentSource = {
+ section: 'ai/python',
+ org: 'supabase',
+ repo: 'vecs',
+ branch: 'main',
+ docsDir: 'docs',
+ externalSite: 'https://supabase.github.io/vecs',
+ pageMap: [
+ {
+ slug: 'api',
+ meta: {
+ title: 'API',
+ },
+ remoteFile: 'api.md',
+ },
+ {
+ slug: 'collections',
+ meta: {
+ title: 'Collections',
+ },
+ remoteFile: 'concepts_collections.md',
+ },
+ {
+ slug: 'indexes',
+ meta: {
+ title: 'Indexes',
+ },
+ remoteFile: 'concepts_indexes.md',
+ },
+ {
+ slug: 'metadata',
+ meta: {
+ title: 'Metadata',
+ },
+ remoteFile: 'concepts_metadata.md',
+ },
+ ],
+}
+
+export default python