mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
## What kind of change does this PR introduce? Docs update / follow-up to #48379. ## What is the current behavior? `/guides/resources` and `/guides/getting-started` hand-roll `GlassPanel` grids in MDX. They look like ContentListings cards after the chrome PR, but they do not use the shared data files, so they miss PostHog `docs_content_listing_clicked` telemetry and the CONTRIBUTING contribution path. ## What is the new behavior? Those pages use `<ContentListings id="…" />` backed by `resources.data.ts` and `getting-started.data.ts`, same pattern as storage. - Section-level `$Show` wrappers stay for framework / web / mobile blocks - Nimbus stays a `$Partial` behind `$Show` - New optional per-item `feature` field gates SDK links (e.g. Flutter / Swift / Kotlin) without splitting whole sections - CONTRIBUTING notes when to use `feature` vs a partial-level `$Show` ## To test Compare the following against `master`: - [Resources](https://docs-git-dnywh-docs-content-listings-resources-239158-supabase.vercel.app/docs/guides/resources): overview, migrate, and postgres grids; icons in light/dark - [Getting started](https://docs-git-dnywh-docs-content-listings-resources-239158-supabase.vercel.app/docs/guides/getting-started): overview, use cases, framework quickstarts, web demos, mobile tutorials; nimbus partial when enabled - Click a card and confirm `docs_content_listing_clicked` fires with the expected `listingId` Everything should look and feel the same. It’s just that we’re using `ContentListings` instead of `GlassPanel` grids. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added centralized Getting Started and Resources content listings, including quickstarts, demos, tutorials, migration guides, and Postgres resources. - Added feature-based visibility controls for individual content listing items. - **Improvements** - Disabled content is now automatically hidden from documentation pages and generated Markdown. - Pages and sections with no available content are omitted entirely. - External documentation links are more secure. - Updated contribution guidance with instructions and examples for feature flags. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
137 lines
4.7 KiB
TypeScript
137 lines
4.7 KiB
TypeScript
'use client'
|
|
|
|
import type { ContentListingGroup, ContentListingItem } from '~/lib/content-listings.schema'
|
|
import {
|
|
filterContentListingItems,
|
|
getContentListingById,
|
|
getContentListingGroupLabel,
|
|
isExternalContentListingHref,
|
|
} from '~/lib/content-listings.utils'
|
|
import { useSendTelemetryEvent } from '~/lib/telemetry'
|
|
import Link from 'next/link'
|
|
import { useCallback, useMemo } from 'react'
|
|
import { Badge } from 'ui'
|
|
import { GlassPanel } from 'ui-patterns/GlassPanel'
|
|
import { Heading } from 'ui/src/components/CustomHTMLElements'
|
|
|
|
import { resolveContentListingIcon } from './iconChip'
|
|
|
|
const GRID_ITEM_CLASS = {
|
|
// Stay 2-up until xl (~1280px) so cards aren't cramped beside the docs sidebar.
|
|
2: 'col-span-12 md:col-span-6',
|
|
3: 'col-span-12 md:col-span-6 xl:col-span-4',
|
|
4: 'col-span-12 md:col-span-6 xl:col-span-3',
|
|
} as const
|
|
|
|
function useContentListingClickHandler(group: ContentListingGroup) {
|
|
const sendTelemetryEvent = useSendTelemetryEvent()
|
|
const groupLabel = getContentListingGroupLabel(group)
|
|
|
|
const trackClick = useCallback(
|
|
(item: ContentListingItem) => {
|
|
sendTelemetryEvent({
|
|
action: 'docs_content_listing_clicked',
|
|
properties: {
|
|
targetPath: item.href,
|
|
linkTitle: item.title,
|
|
...(groupLabel ? { groupTitle: groupLabel } : {}),
|
|
listingId: group.id,
|
|
},
|
|
})
|
|
},
|
|
[sendTelemetryEvent, group.id, groupLabel]
|
|
)
|
|
|
|
return { trackClick }
|
|
}
|
|
|
|
function ContentListingGroupHeading({ group }: { group: ContentListingGroup }) {
|
|
if (!group.heading) return null
|
|
|
|
return <Heading tag={group.headingLevel ?? 'h2'}>{group.heading}</Heading>
|
|
}
|
|
|
|
function ContentListingsGroup({ group }: { group: ContentListingGroup }) {
|
|
const { trackClick } = useContentListingClickHandler(group)
|
|
const items = useMemo(() => filterContentListingItems(group.items), [group.items])
|
|
const isGrid = group.type === 'grid'
|
|
const listClassName = isGrid ? 'grid md:grid-cols-12 gap-4' : 'list-disc pl-6 space-y-2'
|
|
const gridItemClassName = isGrid ? GRID_ITEM_CLASS[group.columns ?? 3] : undefined
|
|
|
|
if (!items.length) return null
|
|
|
|
// Heading stays outside `not-prose` so it inherits the surrounding MDX prose
|
|
// typography. The list itself opts out so its explicit Tailwind layout wins.
|
|
return (
|
|
<section className="space-y-4">
|
|
<ContentListingGroupHeading group={group} />
|
|
<div className="not-prose space-y-4">
|
|
{group.description && <p className="text-foreground-light">{group.description}</p>}
|
|
<ul className={listClassName}>
|
|
{items.map((item) => {
|
|
const external = isExternalContentListingHref(item.href)
|
|
const key = `${group.id}-${item.href}`
|
|
|
|
if (isGrid) {
|
|
return (
|
|
<li key={key} className={gridItemClassName}>
|
|
<Link
|
|
href={item.href}
|
|
passHref
|
|
className="block h-full"
|
|
onClick={() => trackClick(item)}
|
|
target={external ? '_blank' : undefined}
|
|
rel={external ? 'noopener noreferrer' : undefined}
|
|
>
|
|
<GlassPanel
|
|
title={item.title}
|
|
icon={resolveContentListingIcon(item.icon)}
|
|
hasLightIcon={item.hasLightIcon ?? typeof item.icon === 'string'}
|
|
badge={
|
|
item.badge && item.badgePosition !== 'below' ? (
|
|
<Badge variant="success">{item.badge}</Badge>
|
|
) : undefined
|
|
}
|
|
>
|
|
{item.badge && item.badgePosition === 'below' && (
|
|
<Badge variant="success" className="mb-3 block w-fit">
|
|
{item.badge}
|
|
</Badge>
|
|
)}
|
|
{item.description}
|
|
</GlassPanel>
|
|
</Link>
|
|
</li>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<li key={key}>
|
|
<Link
|
|
href={item.href}
|
|
onClick={() => trackClick(item)}
|
|
target={external ? '_blank' : undefined}
|
|
rel={external ? 'noopener noreferrer' : undefined}
|
|
>
|
|
<strong>{item.title}</strong>: {item.description}
|
|
</Link>
|
|
</li>
|
|
)
|
|
})}
|
|
</ul>
|
|
</div>
|
|
</section>
|
|
)
|
|
}
|
|
|
|
export function ContentListings({ id }: { id: string }) {
|
|
const group = getContentListingById(id)
|
|
if (!group || !filterContentListingItems(group.items).length) return null
|
|
|
|
return (
|
|
<div className="my-10 space-y-10">
|
|
<ContentListingsGroup group={group} />
|
|
</div>
|
|
)
|
|
}
|