mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +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>
114 lines
3.4 KiB
TypeScript
114 lines
3.4 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import { breadcrumbListSchema, techArticleSchema } from './json-ld'
|
|
|
|
describe('breadcrumbListSchema', () => {
|
|
let warn: ReturnType<typeof vi.spyOn>
|
|
|
|
beforeEach(() => {
|
|
warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
})
|
|
|
|
afterEach(() => {
|
|
warn.mockRestore()
|
|
})
|
|
|
|
it('emits item and name on every position when all chain items have urls', () => {
|
|
const result = breadcrumbListSchema({
|
|
pathname: '/guides/auth/jwts',
|
|
chain: [
|
|
{ name: 'Authentication', url: '/guides/auth' },
|
|
{ name: 'JWTs', url: '/guides/auth/jwts' },
|
|
],
|
|
})
|
|
|
|
expect(result).not.toBeNull()
|
|
expect(result!.itemListElement).toHaveLength(3)
|
|
for (const entry of result!.itemListElement) {
|
|
expect(typeof entry.item).toBe('string')
|
|
expect(entry.item).toMatch(/^https?:\/\//)
|
|
expect(typeof entry.name).toBe('string')
|
|
}
|
|
})
|
|
|
|
it('uses pathname for the leaf url even when chain leaf url differs', () => {
|
|
const result = breadcrumbListSchema({
|
|
pathname: '/guides/database/postgres-js',
|
|
chain: [{ name: 'Postgres.js', url: '/guides/database/postgres-js-old' }],
|
|
})
|
|
|
|
expect(result).not.toBeNull()
|
|
const leaf = result!.itemListElement.at(-1)
|
|
expect(leaf?.item).toMatch(/\/guides\/database\/postgres-js$/)
|
|
})
|
|
|
|
it('returns null when every chain item is url-less', () => {
|
|
const result = breadcrumbListSchema({
|
|
pathname: '/guides/some-broken-route',
|
|
chain: [{ name: 'Category A' }, { name: 'Category B' }],
|
|
})
|
|
|
|
expect(result).toBeNull()
|
|
})
|
|
|
|
it('returns null on an empty chain', () => {
|
|
const result = breadcrumbListSchema({ pathname: '/guides', chain: [] })
|
|
|
|
expect(result).toBeNull()
|
|
})
|
|
})
|
|
|
|
describe('techArticleSchema', () => {
|
|
const url = 'https://supabase.com/docs/guides/auth/jwts'
|
|
|
|
it('describes the guide as a TechArticle on its own URL', () => {
|
|
const schema = techArticleSchema({
|
|
url,
|
|
headline: 'JWTs',
|
|
description: 'How JSON Web Tokens work.',
|
|
})
|
|
|
|
expect(schema['@context']).toBe('https://schema.org')
|
|
expect(schema['@type']).toBe('TechArticle')
|
|
expect(schema['@id']).toBe(`${url}#page`)
|
|
expect(schema.mainEntityOfPage).toEqual({ '@type': 'WebPage', '@id': url })
|
|
expect(schema.url).toBe(url)
|
|
expect(schema.headline).toBe('JWTs')
|
|
expect(schema.description).toBe('How JSON Web Tokens work.')
|
|
expect(schema.inLanguage).toBe('en')
|
|
})
|
|
|
|
it('omits description when none is given', () => {
|
|
const schema = techArticleSchema({ url, headline: 'JWTs' })
|
|
|
|
expect(schema.description).toBeUndefined()
|
|
})
|
|
|
|
it('omits date fields when no date is given', () => {
|
|
const schema = techArticleSchema({ url, headline: 'JWTs' })
|
|
|
|
expect(schema).not.toHaveProperty('datePublished')
|
|
expect(JSON.parse(JSON.stringify(schema))).not.toHaveProperty('dateModified')
|
|
})
|
|
|
|
it('emits dateModified when given', () => {
|
|
const schema = techArticleSchema({
|
|
url,
|
|
headline: 'JWTs',
|
|
dateModified: '2026-10-01T12:00:00+00:00',
|
|
})
|
|
|
|
expect(schema.dateModified).toBe('2026-10-01T12:00:00+00:00')
|
|
})
|
|
|
|
it('publishes under an inline Supabase organization', () => {
|
|
const schema = techArticleSchema({ url, headline: 'JWTs' })
|
|
|
|
expect(schema.publisher).toMatchObject({
|
|
'@type': 'Organization',
|
|
name: 'Supabase',
|
|
url: 'https://supabase.com',
|
|
})
|
|
})
|
|
})
|