mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Per #52168, dates are a really important signal for LLMs. We should be surfacing this more proactively across our docs, pulling from the lastModified date. ## Solution Looks like this information is already stored in a Supabase table, so we can grab the date values and then render on associated pages. To this end, this PR: - Grabs the last-updated date with a script (with tests on the script). Gets all the dates to form a map, and then have all the pages read from that map to save roundtrips. Still ~20+ lookups b/c of how the site is built (by multiple workers). - Adds that date into the Guides template and associated JSON-LD / opengraph structured data. The goal of these dates -- to answer the various CodeRabbit comments -- are to be an **approximation** of age. It's okay if they're not 100% accurate based on changed titles, frontmatter, deleted heading sections, etc. Reading this via JS instead of a SQL lookup to save us a DB migration, as that's the fastest way to get this change up (and I have very little familiarity with db migrations, so partially just lack of knowledge here). This does add some additional latency to builds, approximately ~20 seconds from some build benchmarking: - https://vercel.com/supabase/docs/7UcfoR3Jjb8SYuUNkRo14W3DZqBL#L1221-L1241 - https://vercel.com/supabase/docs/23RH6uPtR92K8EggPPiTEQvY23bk#L1062-L1085 ## Preview links | state | preview | | -------|------| | after | <img width="891" height="438" alt="image" src="https://github.com/user-attachments/assets/38476245-be80-4b65-99a7-4501e60560fc" /> | - [Queues overview](https://docs-git-kody-devrel-751-docs-last-updated-date-supabase.vercel.app/docs/guides/queues) -- rendered date of Oct 19th matches [git last modified](https://github.com/supabase/supabase/commits/master/apps/docs/content/guides/queues.mdx) - [Cron overview](https://docs-git-kody-devrel-751-docs-last-updated-date-supabase.vercel.app/docs/guides/cron) -- rendered date of Feb 23rd slight diff from git last modified... but matches last [content change](https://github.com/supabase/supabase/commits/master/apps/docs/content/guides/cron.mdx) - [Auth overview](https://docs-git-kody-devrel-751-docs-last-updated-date-supabase.vercel.app/docs/guides/auth) -- rendered date of Oct 22nd matches [git last modified](https://github.com/supabase/supabase/commits/master/apps/docs/content/guides/auth.mdx) ## Gaps / open review questions - **testing** - Least familiar with the tests in `apps/docs/lib/last-changed.test.ts` + these are entirely claude generated. Unsure if they hit what they should. - **build latency** - Is ~20 sec / build acceptable latency here? If we wanted to move forward with SQL instead of JS to try and reduce it, could make sense... but I'd definitely need help on the associated db migration here. - **build fragility** - AI review flagged the cooldown / potential hanging requests without a timeout. Seems like this is now addressed, but obviously could use a sanity check. --------- Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com> Co-authored-by: anthony lio <lionnet.ant@gmail.com>
108 lines
2.6 KiB
TypeScript
108 lines
2.6 KiB
TypeScript
import type { BreadcrumbItem } from '~/lib/breadcrumbs'
|
|
import { PROD_URL } from '~/lib/constants'
|
|
|
|
type JsonLdSchema = Record<string, unknown> | Record<string, unknown>[]
|
|
|
|
export function serializeJsonLd(schema: JsonLdSchema): string {
|
|
return JSON.stringify(schema)
|
|
.replace(/</g, '\\u003c')
|
|
.replace(/>/g, '\\u003e')
|
|
.replace(/&/g, '\\u0026')
|
|
}
|
|
|
|
type ValidCrumb = BreadcrumbItem & { url: string }
|
|
|
|
const DOCS_ROOT: ValidCrumb = { name: 'Docs', url: '' }
|
|
|
|
interface BreadcrumbListSchemaInput {
|
|
pathname: string
|
|
chain: BreadcrumbItem[]
|
|
}
|
|
|
|
const warnedPaths = new Set<string>()
|
|
|
|
function isValidCrumb(crumb: BreadcrumbItem): crumb is ValidCrumb {
|
|
return crumb.url !== undefined && Boolean(crumb.title ?? crumb.name)
|
|
}
|
|
|
|
export function breadcrumbListSchema({ pathname, chain }: BreadcrumbListSchemaInput) {
|
|
const filteredChain = chain.filter(isValidCrumb)
|
|
|
|
if (
|
|
process.env.NODE_ENV !== 'production' &&
|
|
filteredChain.length !== chain.length &&
|
|
!warnedPaths.has(pathname)
|
|
) {
|
|
warnedPaths.add(pathname)
|
|
const dropped = chain
|
|
.filter((crumb) => !isValidCrumb(crumb))
|
|
.map((crumb) => crumb.title ?? crumb.name ?? '<unnamed>')
|
|
console.warn(
|
|
`[json-ld] Dropping breadcrumb items missing url or name from ${pathname}: ${dropped.join(', ')}`
|
|
)
|
|
}
|
|
|
|
if (filteredChain.length === 0) return null
|
|
|
|
const fullChain: ValidCrumb[] = [DOCS_ROOT, ...filteredChain]
|
|
|
|
const itemListElement = fullChain.map((crumb, index) => {
|
|
const isLeaf = index === fullChain.length - 1
|
|
const path = isLeaf ? pathname : crumb.url
|
|
const itemUrl = path === '' ? PROD_URL : `${PROD_URL}${path}`
|
|
|
|
return {
|
|
'@type': 'ListItem',
|
|
position: index + 1,
|
|
name: crumb.title ?? crumb.name,
|
|
item: itemUrl,
|
|
}
|
|
})
|
|
|
|
return {
|
|
'@context': 'https://schema.org',
|
|
'@type': 'BreadcrumbList',
|
|
itemListElement,
|
|
}
|
|
}
|
|
|
|
const PUBLISHER = {
|
|
'@type': 'Organization',
|
|
name: 'Supabase',
|
|
url: 'https://supabase.com',
|
|
logo: {
|
|
'@type': 'ImageObject',
|
|
url: 'https://supabase.com/images/og/supabase-og.png',
|
|
},
|
|
}
|
|
|
|
interface TechArticleSchemaInput {
|
|
url: string
|
|
headline: string
|
|
description?: string
|
|
dateModified?: string
|
|
}
|
|
|
|
export function techArticleSchema({
|
|
url,
|
|
headline,
|
|
description,
|
|
dateModified,
|
|
}: TechArticleSchemaInput) {
|
|
return {
|
|
'@context': 'https://schema.org',
|
|
'@type': 'TechArticle',
|
|
'@id': `${url}#page`,
|
|
mainEntityOfPage: {
|
|
'@type': 'WebPage',
|
|
'@id': url,
|
|
},
|
|
url,
|
|
headline,
|
|
description,
|
|
dateModified,
|
|
inLanguage: 'en',
|
|
publisher: PUBLISHER,
|
|
}
|
|
}
|