mirror of
https://github.com/supabase/supabase.git
synced 2026-09-07 02:20:52 +08:00
## Summary - `[email protected]` is unmaintained and drags in a heavy, stale dependency graph (esbuild pinned to 0.17–0.20, mdx-bundler, old `@opentelemetry/core`) that was the recurring source of vuln bumps. - Migrates all three apps that used it — `design-system`, `ui-library`, `learn` — to [Velite](https://velite.js.org), preserving the generated typed `allDocs`/`Doc` collection and the `body.code` + `useMDXComponent` runtime via a small shared local hook. - Same MDX pipeline (remark-gfm, remark-code-import, rehype-slug, rehype-pretty-code w/ Shiki compat + local theme, rehype-autolink-headings, custom `__rawString__`/`__src__`/`__event__`/`__style__` visitors) ported 1:1 into each app's `velite.config.js`. - `learn`'s extra frontmatter fields (`chapterNumber`, `explore`, `courseHero`) are now backed by real Velite/Zod schema types, so the `(doc as any)` casts in `get-next-page.ts` / `get-current-chapter.ts` / the doc page could be dropped. - `next.config.mjs` no longer wraps with `withContentlayer`; since Velite has no Next.js webpack-plugin equivalent, each app's `dev` script now runs `velite dev` and `next dev` in parallel via `npm-run-all`. Ref: [FE-3861](https://linear.app/supabase/issue/FE-3861/migrate-off-contentlayer2-learn-ui-library-design-system-to-shed) ## Test plan - [x] `pnpm build:content` (Velite build) succeeds for all three apps - [x] `pnpm typecheck` passes for all three apps - [ ] Manual smoke test of `pnpm dev` for each app in a browser (docs pages render, TOC, copy-button, code highlighting) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * Improved content generation across documentation, learning materials, and the UI library for more consistent pages. * Preserved MDX rendering, navigation, table of contents, course metadata, source previews, and component examples. * Improved consistency when displaying documentation and interactive examples. * Improved application loading by optimizing how interface components are delivered. * **Chores** * Streamlined content compilation and development workflows across the design system, learning area, and UI library. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
153 lines
4.7 KiB
JavaScript
153 lines
4.7 KiB
JavaScript
import path from 'path'
|
|
import { getHighlighter, loadTheme } from '@shikijs/compat'
|
|
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
|
|
import rehypePrettyCode from 'rehype-pretty-code'
|
|
import rehypeSlug from 'rehype-slug'
|
|
import { codeImport } from 'remark-code-import'
|
|
import remarkGfm from 'remark-gfm'
|
|
import { visit } from 'unist-util-visit'
|
|
import { defineConfig, s } from 'velite'
|
|
|
|
const LinksProperties = s.object({
|
|
doc: s.string().optional(),
|
|
api: s.string().optional(),
|
|
})
|
|
|
|
const NestedProperties = s.object({
|
|
radix: s.boolean().optional(),
|
|
shadcn: s.boolean().optional(),
|
|
vaul: s.boolean().optional(),
|
|
inputOtp: s.boolean().optional(),
|
|
reactAccessibleTreeview: s.boolean().optional(),
|
|
})
|
|
|
|
const docs = s
|
|
.object({
|
|
title: s.string(),
|
|
description: s.string(),
|
|
published: s.boolean().default(true),
|
|
links: LinksProperties.optional(),
|
|
featured: s.boolean().default(false),
|
|
component: s.boolean().default(false),
|
|
fragment: s.boolean().default(false),
|
|
toc: s.boolean().default(true),
|
|
source: NestedProperties.optional(),
|
|
// mirrors contentlayer2's `_raw.flattenedPath`: file path relative to the
|
|
// content dir, extension stripped, trailing `/index` dropped.
|
|
path: s.path(),
|
|
raw: s.raw(),
|
|
// internal doc cross-links (e.g. `[Button](components/button)`) aren't
|
|
// real files on disk — disable Velite's default asset-copying behavior,
|
|
// which otherwise treats every relative link as a local file to copy.
|
|
code: s.mdx({ copyLinkedFiles: false }),
|
|
})
|
|
.transform(({ path: flattenedPath, ...data }) => ({
|
|
...data,
|
|
slug: `/${flattenedPath}`,
|
|
slugAsParams: flattenedPath.split('/').slice(1).join('/'),
|
|
}))
|
|
|
|
export default defineConfig({
|
|
root: './content',
|
|
output: {
|
|
clean: true,
|
|
},
|
|
collections: {
|
|
allDocs: {
|
|
name: 'Doc',
|
|
pattern: 'docs/**/*.mdx',
|
|
schema: docs,
|
|
},
|
|
},
|
|
mdx: {
|
|
remarkPlugins: [remarkGfm, codeImport],
|
|
rehypePlugins: [
|
|
rehypeSlug,
|
|
() => (tree) => {
|
|
visit(tree, (node) => {
|
|
if (node?.type === 'element' && node?.tagName === 'pre') {
|
|
const [codeEl] = node.children
|
|
if (codeEl.tagName !== 'code') {
|
|
return
|
|
}
|
|
|
|
if (codeEl.data?.meta) {
|
|
// Extract event from meta and pass it down the tree.
|
|
const regex = /event="([^"]*)"/
|
|
const match = codeEl.data?.meta.match(regex)
|
|
if (match) {
|
|
node.__event__ = match ? match[1] : null
|
|
codeEl.data.meta = codeEl.data.meta.replace(regex, '')
|
|
}
|
|
}
|
|
|
|
node.__rawString__ = codeEl.children?.[0].value
|
|
node.__src__ = node.properties?.__src__
|
|
node.__style__ = node.properties?.__style__
|
|
}
|
|
})
|
|
},
|
|
[
|
|
rehypePrettyCode,
|
|
{
|
|
getHighlighter: async () => {
|
|
const theme = await loadTheme(path.join(process.cwd(), '/lib/themes/supabase-2.json'))
|
|
return await getHighlighter({ theme })
|
|
},
|
|
onVisitLine(node) {
|
|
// Prevent lines from collapsing in `display: grid` mode, and allow empty
|
|
// lines to be copy/pasted
|
|
if (node.children.length === 0) {
|
|
node.children = [{ type: 'text', value: ' ' }]
|
|
}
|
|
},
|
|
onVisitHighlightedLine(node) {
|
|
node.properties.className.push('line--highlighted')
|
|
},
|
|
onVisitHighlightedWord(node) {
|
|
node.properties.className = ['word--highlighted']
|
|
},
|
|
},
|
|
],
|
|
() => (tree) => {
|
|
visit(tree, (node) => {
|
|
if (node?.type === 'element' && node?.tagName === 'div') {
|
|
if (!('data-rehype-pretty-code-fragment' in node.properties)) {
|
|
return
|
|
}
|
|
|
|
const preElement = node.children.at(-1)
|
|
if (preElement.tagName !== 'pre') {
|
|
return
|
|
}
|
|
|
|
preElement.properties['__withMeta__'] = node.children.at(0).tagName === 'div'
|
|
preElement.properties['__rawString__'] = node.__rawString__
|
|
|
|
if (node.__src__) {
|
|
preElement.properties['__src__'] = node.__src__
|
|
}
|
|
|
|
if (node.__event__) {
|
|
preElement.properties['__event__'] = node.__event__
|
|
}
|
|
|
|
if (node.__style__) {
|
|
preElement.properties['__style__'] = node.__style__
|
|
}
|
|
}
|
|
})
|
|
},
|
|
[
|
|
rehypeAutolinkHeadings,
|
|
{
|
|
properties: {
|
|
className: ['subheading-anchor'],
|
|
ariaLabel: 'Link to section',
|
|
},
|
|
},
|
|
],
|
|
],
|
|
},
|
|
})
|