mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
## I have read the [CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) file. YES ## What kind of change does this PR introduce? Feature, bug fix. Part 3 of 6 in a stack that splits the library redesign into reviewable pieces. ## What is the current behavior? An agent can already fetch any guide as Markdown, but has no way to find out what guides exist: the entry point is a rendered React page. The exporter also fails quietly in ways that ship wrong output rather than failing the build: - An unknown component silently unwraps to its children, so a component rename drops its rendered content. - A registry item that cannot be read produces a page with no file listing. - A link to a missing page produces a 404 URL. - An unrecognized install framework produces a plausible command for the wrong CLI. - Only absolute `/library/docs` links are rewritten, so in-page anchors and sibling links break in the export. ## What is the new behavior? `/library` negotiates Markdown the same way the guides do — `Accept: text/markdown`, or an explicit `/library/index.md` — and returns a categorized catalog with every block, its description, its framework variants, and a link to each guide's Markdown. `config/library.ts` is the single catalog description the generator reads, and a test ties it to the content directory in both directions: a guide cannot be added without a catalog entry, or listed without a guide. Each quiet failure above now throws, and links resolve against the page they appear on and are checked against the set of published documents. ```bash curl -H 'Accept: text/markdown' https://supabase.com/library ``` ## Additional context `config/library.ts` also carries the category and preview metadata the redesigned homepage consumes in the last PR of the stack; here it is exercised by the Markdown index and its test. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added a browsable library catalog covering categories, blocks, starter apps, and supported frameworks. - Added Markdown versions of the library homepage and documentation for compatible tools and workflows. - Added framework-aware links and expanded registry information, including dependencies and source details. - Markdown requests now work for the homepage and documentation, while browser requests continue receiving HTML. - **Bug Fixes** - Improved document link handling, metadata validation, slug consistency, and detection of duplicate or missing documentation entries. - **Tests** - Added coverage for catalog routes, Markdown generation, homepage negotiation, document parsing, and framework-specific links. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
93 lines
4.1 KiB
TypeScript
93 lines
4.1 KiB
TypeScript
import { existsSync } from 'node:fs'
|
|
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import { componentPages, mcpBlocks, oauthBlocks, platformBlocks } from '../config/docs'
|
|
import { getLibraryBlockHref, libraryBlocks, libraryCategories } from '../config/library'
|
|
import { collectMdxFiles, getDocSlug } from './library-documents'
|
|
|
|
describe('library catalog', () => {
|
|
it('accounts for every block guide and framework variant in the content directory', () => {
|
|
const contentDirectory = fileURLToPath(new URL('../content/docs', import.meta.url))
|
|
const catalogRoutes = new Set(
|
|
libraryBlocks.flatMap((block) => [
|
|
block.href,
|
|
...(block.supportedFrameworks ?? []).map((framework) =>
|
|
getLibraryBlockHref(block, framework)
|
|
),
|
|
])
|
|
)
|
|
// These guides are reachable directly but intentionally absent from the block catalog.
|
|
const unlistedRoutes = new Set([
|
|
'/docs/getting-started/introduction',
|
|
'/docs/getting-started/quickstart',
|
|
'/docs/getting-started/faq',
|
|
'/docs/nextjs/tanstack-db',
|
|
])
|
|
const documentRoutes = new Set(
|
|
collectMdxFiles(contentDirectory).map(
|
|
(file) => `/docs/${getDocSlug(path.relative(contentDirectory, file))}`
|
|
)
|
|
)
|
|
|
|
for (const route of documentRoutes) {
|
|
expect(
|
|
catalogRoutes.has(route) || unlistedRoutes.has(route),
|
|
`${route} needs a catalog entry`
|
|
).toBe(true)
|
|
}
|
|
for (const route of [...catalogRoutes, ...unlistedRoutes]) {
|
|
expect(documentRoutes.has(route), `${route} must resolve to a guide`).toBe(true)
|
|
}
|
|
for (const block of libraryBlocks) {
|
|
expect(block.title.trim(), `${block.slug} needs a title`).toBeTruthy()
|
|
expect(block.description?.trim(), `${block.slug} needs a description`).toBeTruthy()
|
|
expect(block.preview, `${block.slug} needs a preview`).toBeTruthy()
|
|
expect(libraryCategories.some((category) => category.name === block.category)).toBe(true)
|
|
}
|
|
})
|
|
|
|
it('keeps every existing block discoverable with a valid category and documentation route', () => {
|
|
const existingItems = [
|
|
...componentPages.items,
|
|
...oauthBlocks.items,
|
|
...mcpBlocks.items,
|
|
...platformBlocks.items,
|
|
]
|
|
|
|
for (const item of existingItems) {
|
|
const block = libraryBlocks.find((block) => block.href === item.href)
|
|
if (!block) throw new Error(`${item.title} must remain in the catalog`)
|
|
expect(libraryCategories.some((category) => category.name === block.category)).toBe(true)
|
|
expect(existsSync(new URL(`../content${block.href}.mdx`, import.meta.url))).toBe(true)
|
|
for (const framework of block.supportedFrameworks ?? []) {
|
|
const href = getLibraryBlockHref(block, framework)
|
|
expect(existsSync(new URL(`../content${href}.mdx`, import.meta.url)), href).toBe(true)
|
|
}
|
|
}
|
|
})
|
|
|
|
it('uses a supported framework and falls back to an existing route otherwise', () => {
|
|
const oauth = libraryBlocks.find((block) => block.slug === 'oauth-consent')!
|
|
const monaco = libraryBlocks.find((block) => block.slug === 'realtime-monaco')!
|
|
const infiniteQuery = libraryBlocks.find((block) => block.slug === 'infinite-query')!
|
|
|
|
expect(getLibraryBlockHref(oauth, 'react-router')).toBe('/docs/react-router/oauth-consent')
|
|
expect(getLibraryBlockHref(monaco, 'vue')).toBe('/docs/nextjs/realtime-monaco')
|
|
expect(getLibraryBlockHref(infiniteQuery, 'nextjs')).toBe('/docs/react/infinite-query')
|
|
})
|
|
|
|
it('includes starter apps as blocks with unique slugs and internal documentation routes', () => {
|
|
expect(new Set(libraryBlocks.map((block) => block.slug)).size).toBe(libraryBlocks.length)
|
|
const starters = libraryBlocks.filter((block) => block.category === 'Starter apps')
|
|
expect(starters.length > 0).toBe(true)
|
|
for (const starter of starters) {
|
|
expect(starter.href).toBe(`/docs/starters/${starter.slug}`)
|
|
expect(existsSync(new URL(`../content${starter.href}.mdx`, import.meta.url))).toBe(true)
|
|
expect(starter.external).not.toBe(true)
|
|
expect(getLibraryBlockHref(starter, 'vue')).toBe(starter.href)
|
|
}
|
|
})
|
|
})
|