Front page: set the featured cards' grid by hand, columns and a size per card (migration 073)
Front page editor: Featured Content > Columns (2, 3 or 4 across on a wide screen) and a Size on each card (normal, wide, tall, large). Blank keeps today's layout: 3 across, the first of three or more large. Regions and the Community blog stay automatic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
910aef78b5
commit
31d9f78120
11 changed files with 130 additions and 23 deletions
|
|
@ -25,6 +25,13 @@
|
|||
one, two rows tall, and the next two stack beside it, so it no
|
||||
longer stretches its neighbor.
|
||||
|
||||
The front page sets the shape by hand (073): `columns` is how many
|
||||
across on a wide screen (2, 3 or 4; default 3), and a card's
|
||||
`size` makes it wide (2 columns), tall (2 rows), large (both) or
|
||||
normal. A card with no size is automatic, the rule above, so
|
||||
cards nobody has sized lay out as they always have. Cards stay in
|
||||
their list order; a shape that leaves a hole leaves it.
|
||||
|
||||
Reading mode (readingMode.ts) gets each card as a linked heading
|
||||
and its words, a video card linking to its video. `level` is that
|
||||
heading's level, one under the heading above the cards.
|
||||
|
|
@ -35,7 +42,7 @@ import HomeLink from '../pages/sections/home/HomeLink.tsx'
|
|||
import VideoPlayer from './VideoPlayer.tsx'
|
||||
import { refHref } from '../lib/hrefs.ts'
|
||||
import { mediaUrl } from '../lib/media.ts'
|
||||
import type { FeaturedCard } from '../lib/useFrontPage.ts'
|
||||
import type { FeaturedCard, FeaturedColumns, FeaturedSize } from '../lib/useFrontPage.ts'
|
||||
import { useReadingMode } from '../lib/readingMode.ts'
|
||||
import { useSmallImage } from '../lib/useSmallImage.ts'
|
||||
|
||||
|
|
@ -86,7 +93,30 @@ function VideoPicture({ card }: { card: FeaturedCard }) {
|
|||
|
||||
const RULE = 'border-brand'
|
||||
|
||||
function Card({ card, large, level }: { card: FeaturedCard; large: boolean; level: 3 | 4 | 5 }) {
|
||||
/* Columns across, by setting. Two columns start at sm; three and
|
||||
four take over at lg. Written out whole so Tailwind sees them. */
|
||||
const GRID_COLUMNS: Record<FeaturedColumns, string> = {
|
||||
2: 'sm:grid-cols-2',
|
||||
3: 'sm:grid-cols-2 lg:grid-cols-3',
|
||||
4: 'sm:grid-cols-2 lg:grid-cols-4',
|
||||
}
|
||||
|
||||
/* A card's spans, from the breakpoint its grid reaches its full
|
||||
width: sm for a two column grid, lg otherwise. Below that every
|
||||
card is one cell, so a wide card can't overflow a narrow grid. */
|
||||
const SPANS: Record<'sm' | 'lg', Record<FeaturedSize, string>> = {
|
||||
sm: { normal: '', wide: 'sm:col-span-2', tall: 'sm:row-span-2', large: 'sm:col-span-2 sm:row-span-2' },
|
||||
lg: { normal: '', wide: 'lg:col-span-2', tall: 'lg:row-span-2', large: 'lg:col-span-2 lg:row-span-2' },
|
||||
}
|
||||
|
||||
/* A card's size, or for one with none, the automatic rule: the first
|
||||
of three or more is large. */
|
||||
function sizeOf(card: FeaturedCard, index: number, count: number): FeaturedSize {
|
||||
return card.size ?? (index === 0 && count >= 3 ? 'large' : 'normal')
|
||||
}
|
||||
|
||||
function Card({ card, size, spans, level }: { card: FeaturedCard; size: FeaturedSize; spans: string; level: 3 | 4 | 5 }) {
|
||||
const large = size === 'large'
|
||||
const href = hrefFor(card)
|
||||
const Title = `h${level}` as const
|
||||
|
||||
|
|
@ -119,9 +149,7 @@ function Card({ card, large, level }: { card: FeaturedCard; large: boolean; leve
|
|||
|
||||
return (
|
||||
<li
|
||||
className={`relative flex flex-col overflow-hidden border-r-4 border-b-4 ${RULE} bg-raised transition-colors hover:bg-tint-soft ${
|
||||
large ? 'lg:col-span-2 lg:row-span-2' : ''
|
||||
}`}
|
||||
className={`relative flex flex-col overflow-hidden border-r-4 border-b-4 ${RULE} bg-raised transition-colors hover:bg-tint-soft ${spans}`}
|
||||
>
|
||||
{card.kind === 'video' ? (
|
||||
// Above the stretched link, which a video card doesn't have
|
||||
|
|
@ -138,7 +166,7 @@ function Card({ card, large, level }: { card: FeaturedCard; large: boolean; leve
|
|||
)
|
||||
}
|
||||
|
||||
type FeaturedCardsProps = { cards: FeaturedCard[]; level?: 3 | 4 | 5 }
|
||||
type FeaturedCardsProps = { cards: FeaturedCard[]; level?: 3 | 4 | 5; columns?: FeaturedColumns }
|
||||
|
||||
function ReadingCards({ cards, level = 3 }: FeaturedCardsProps) {
|
||||
const Title = `h${level}` as const
|
||||
|
|
@ -158,21 +186,25 @@ function ReadingCards({ cards, level = 3 }: FeaturedCardsProps) {
|
|||
)
|
||||
}
|
||||
|
||||
export default function FeaturedCards({ cards, level = 3 }: FeaturedCardsProps) {
|
||||
export default function FeaturedCards({ cards, level = 3, columns = 3 }: FeaturedCardsProps) {
|
||||
const reading = useReadingMode()
|
||||
if (reading) return <ReadingCards cards={cards} level={level} />
|
||||
const leadLarge = cards.length >= 3
|
||||
const spans = SPANS[columns === 2 ? 'sm' : 'lg']
|
||||
return (
|
||||
<div className="overflow-hidden shadow-md">
|
||||
<ul className="-mr-[4px] -mb-[4px] grid sm:grid-cols-2 lg:grid-cols-3">
|
||||
{cards.map((card, index) => (
|
||||
<Card
|
||||
key={`${card.kind}-${card.ref?.id ?? card.url}-${index}`}
|
||||
card={card}
|
||||
large={leadLarge && index === 0}
|
||||
level={level}
|
||||
/>
|
||||
))}
|
||||
<ul className={`-mr-[4px] -mb-[4px] grid ${GRID_COLUMNS[columns]}`}>
|
||||
{cards.map((card, index) => {
|
||||
const size = sizeOf(card, index, cards.length)
|
||||
return (
|
||||
<Card
|
||||
key={`${card.kind}-${card.ref?.id ?? card.url}-${index}`}
|
||||
card={card}
|
||||
size={size}
|
||||
spans={spans[size]}
|
||||
level={level}
|
||||
/>
|
||||
)
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -163,6 +163,24 @@ export const frontPage = {
|
|||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Featured Content",
|
||||
note: "The cards themselves are under Featured cards below, each with its own Size.",
|
||||
fields: [
|
||||
{
|
||||
path: "featured_columns",
|
||||
label: "Columns",
|
||||
widget: "select",
|
||||
options: [
|
||||
["2", "2 across"],
|
||||
["3", "3 across"],
|
||||
["4", "4 across"],
|
||||
],
|
||||
blankLabel: "Default: 3 across",
|
||||
help: "On a wide screen. Tablets show 2, phones 1",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
children: [
|
||||
|
|
@ -222,7 +240,25 @@ export const frontPage = {
|
|||
{ path: "note", label: "Note", full: true },
|
||||
],
|
||||
},
|
||||
featuredCardsChild,
|
||||
{
|
||||
...featuredCardsChild,
|
||||
fields: [
|
||||
...featuredCardsChild.fields,
|
||||
{
|
||||
path: "size",
|
||||
label: "Size",
|
||||
widget: "select",
|
||||
options: [
|
||||
["normal", "Normal: one cell"],
|
||||
["wide", "Wide: two columns"],
|
||||
["tall", "Tall: two rows"],
|
||||
["large", "Large: two columns, two rows"],
|
||||
],
|
||||
blankLabel: "Default: automatic (the first of three or more is large)",
|
||||
help: "On a wide screen. Phones show one card per row",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "paths",
|
||||
label: "Connect Nav",
|
||||
|
|
|
|||
|
|
@ -106,8 +106,13 @@ export type FeaturedCard = {
|
|||
blurb?: string | null
|
||||
/** Resolve the file with mediaUrl in media.ts. */
|
||||
image: { file: string; kind: string } | null
|
||||
/** Its shape in the grid; null is automatic (FeaturedCards). */
|
||||
size?: FeaturedSize | null
|
||||
}
|
||||
|
||||
export type FeaturedSize = 'normal' | 'wide' | 'tall' | 'large'
|
||||
export type FeaturedColumns = 2 | 3 | 4
|
||||
|
||||
/** The countdown's event plus what the hero's event card draws. */
|
||||
export type HeroEvent = CountdownEvent & {
|
||||
tagline?: string | null
|
||||
|
|
@ -123,6 +128,8 @@ export type FrontPage = {
|
|||
stats: FrontPageStat[]
|
||||
paths: FrontPagePath[]
|
||||
featured: FeaturedCard[]
|
||||
/** Columns across on a wide screen; null is the grid's default. */
|
||||
featured_columns: FeaturedColumns | null
|
||||
countdown: CountdownEvent | null
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ const BANDS: Record<FrontPageSectionKey, (props: BandProps) => ReactNode> = {
|
|||
<Pathfinder id={id('connect')!} title={title} blurb={section.blurb} paths={page.paths} />
|
||||
),
|
||||
featured: ({ page, section, title }) => (
|
||||
<FeaturedBand id={id('featured')!} title={title} blurb={section.blurb} cards={page.featured} />
|
||||
<FeaturedBand id={id('featured')!} title={title} blurb={section.blurb} cards={page.featured} columns={page.featured_columns} />
|
||||
),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,23 +8,24 @@
|
|||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import FeaturedCards from '../../../components/FeaturedCards.tsx'
|
||||
import type { FeaturedCard } from '../../../lib/useFrontPage.ts'
|
||||
import type { FeaturedCard, FeaturedColumns } from '../../../lib/useFrontPage.ts'
|
||||
|
||||
type FeaturedBandProps = {
|
||||
id: string
|
||||
title: string
|
||||
blurb?: string | null
|
||||
cards: FeaturedCard[]
|
||||
columns?: FeaturedColumns | null
|
||||
}
|
||||
|
||||
export default function FeaturedBand({ id, title, blurb, cards }: FeaturedBandProps) {
|
||||
export default function FeaturedBand({ id, title, blurb, cards, columns }: FeaturedBandProps) {
|
||||
return (
|
||||
<section id={id} className="py-24">
|
||||
<div className="mx-auto max-w-6xl px-6">
|
||||
<h2 className="font-display text-4xl font-bold text-ink md:text-5xl">{title}</h2>
|
||||
{blurb && <p className="mt-4 max-w-2xl text-lg text-muted">{blurb}</p>}
|
||||
<div className="mt-12">
|
||||
<FeaturedCards cards={cards} />
|
||||
<FeaturedCards cards={cards} columns={columns ?? undefined} />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue