import { ChipLink } from '@sim/emcn' import Image from 'next/image' import Link from 'next/link' import type { ContentMeta } from '@/lib/content/schema' import { Cta } from '@/app/(landing)/components/cta/cta' import { JsonLd } from '@/app/(landing)/components/json-ld' const POSTS_PER_PAGE = 20 const FEATURED_COUNT = 3 interface ContentIndexPageProps { /** Route base path, e.g. `/blog` or `/library`. */ basePath: string heading: string subheading: string /** All published posts for the section, unfiltered and unsorted. */ posts: ContentMeta[] page: number tag?: string collectionJsonLd: Record } /** * Shared index/list layout for a content section (blog or library): section * header, featured-post row, remaining posts list, and pagination. Both * sections render this exact layout, parameterized by `basePath` and copy — * see `.claude/rules/landing-seo-geo.md` for the filtered/paginated noindex * policy this pairs with (`buildIndexMetadata` in `@/lib/content/seo`). */ export function ContentIndexPage({ basePath, heading, subheading, posts, page, tag, collectionJsonLd, }: ContentIndexPageProps) { const filtered = tag ? posts.filter((p) => p.tags.includes(tag)) : posts const dateSorted = [...filtered].sort( (a, b) => new Date(b.date).getTime() - new Date(a.date).getTime() ) // Featured posts render once, in the page-1 featured row, regardless of // where their date would otherwise place them — so they're carved out of // the paginated pool up front rather than re-sorted to the front of page 1 // (which left them still reachable, and duplicated, on a later page). const explicitlyFeatured = dateSorted.filter((p) => p.featured).slice(0, FEATURED_COUNT) const featuredPosts = explicitlyFeatured.length > 0 ? explicitlyFeatured : dateSorted.slice(0, FEATURED_COUNT) const featuredSlugs = new Set(featuredPosts.map((p) => p.slug)) const paginated = dateSorted.filter((p) => !featuredSlugs.has(p.slug)) const totalPages = Math.max(1, Math.ceil(paginated.length / POSTS_PER_PAGE)) const start = (page - 1) * POSTS_PER_PAGE const featured = page === 1 ? featuredPosts : [] const remaining = paginated.slice(start, start + POSTS_PER_PAGE) const pageHref = (targetPage: number) => `${basePath}?page=${targetPage}${tag ? `&tag=${encodeURIComponent(tag)}` : ''}` return ( <>

{heading}

{subheading}

{featured.length > 0 && ( <>
)} {remaining.map((p) => (
{new Date(p.date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', })}
{new Date(p.date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', })}

{p.title}

{p.description}

{p.title}
))} {totalPages > 1 && ( )}
) }