import { CampaignContentCard, type CampaignContentCardData } from '@/components/CampaignContentCard' import { PUBLIC_FOCUS, PUBLIC_PATHS, PUBLIC_SOCIAL_LINKS } from '@/lib/publicSite' import { cn } from '@/lib/utils' import type { Post } from '@/payload-types' import { formatRelativePostDate, getCategoryName, getPostCanonicalPath, getVisiblePosts, } from '@/utilities/posts' import type { InstagramPost } from '@/utilities/socialFeed/instagramFeed' import { getInstagramFeed } from '@/utilities/socialFeed/instagramFeedView' import { formatYouTubeViews, getYouTubeFeed, type YouTubeVideo, } from '@/utilities/socialFeed/youtubeFeed' import Link from 'next/link' const CONTENT_SECTION_LIMIT = 4 const sectionHeaderLinkClassName = 'rounded-sm text-sm font-bold text-(--pt-red) underline decoration-(--pt-red) underline-offset-[5px] hover:text-(--pt-red-dark)' type DatedCard = { card: CampaignContentCardData date: number } /** 0 sentinel: a missing date sinks the item to the bottom of the recency merge. */ const dateTimeOf = (value?: string | null): number => { const time = new Date(value ?? '').getTime() return Number.isNaN(time) ? 0 : time } const byRecencyDesc = (a: DatedCard, b: DatedCard): number => b.date - a.date const toArticleCardData = (post: Post): DatedCard | null => { const href = getPostCanonicalPath(post) if (!href) return null const cover = typeof post.coverImage === 'object' && post.coverImage !== null ? post.coverImage : null const categoryName = getCategoryName(post) return { card: { id: post.id, href, title: post.title, shareKind: 'article' as const, meta: [formatRelativePostDate(post.publishedDate), categoryName].filter(Boolean).join(' · '), ...(cover?.url ? { coverUrl: cover.url, coverAlt: cover.alt ?? undefined } : {}), ...(post.subtitle ? { subtitle: post.subtitle } : {}), }, date: dateTimeOf(post.publishedDate), } } const toVideoCardData = (video: YouTubeVideo): DatedCard => ({ card: { id: `yt:${video.id}`, href: `https://www.youtube.com/watch?v=${video.id}`, title: video.title, shareKind: 'video' as const, meta: [ formatRelativePostDate(video.publishedAt), video.viewCount != null ? `${formatYouTubeViews(video.viewCount)} visualizações` : null, ] .filter(Boolean) .join(' · '), ...(video.thumbnailUrl ? { coverUrl: video.thumbnailUrl, coverAlt: video.title } : {}), external: true, }, date: dateTimeOf(video.publishedAt), }) const toInstagramCardData = (post: InstagramPost): DatedCard => ({ card: { id: `ig:${post.id}`, href: post.permalink, title: post.caption ?? 'Publicação no Instagram', shareKind: 'instagram' as const, meta: formatRelativePostDate(post.timestamp) ?? '', ...(post.thumbnailUrl ? { coverUrl: post.thumbnailUrl, coverAlt: post.caption ?? 'Publicação no Instagram' } : {}), external: true, }, date: dateTimeOf(post.timestamp), }) const youtubeHref = PUBLIC_SOCIAL_LINKS.youtube.href const instagramHref = PUBLIC_SOCIAL_LINKS.instagram.href const BoardLinks = () => ( <> Todos os artigos YouTube Instagram ) /** * S47 — the editorial home board (design scene 01/02): the 4 most recent items * across the visible posts (S1), the eligible YouTube feed (S2) and the * eligible Instagram feed (S3), newest first, as 1 featured story + 3 compact * rows. The previous mobile carousel is gone — the side column simply stacks. * With nothing visible the section renders the approved empty state instead of * leaving a silent hole (`isPostVisible` fail-closed — hidden electoral tags * never leak), and a feed outage degrades to the articles-only board. */ export const CampaignContentSection = async () => { const [visiblePosts, youtubeFeed, instagramFeed] = await Promise.all([ getVisiblePosts(), getYouTubeFeed(), getInstagramFeed(), ]) const articleCards = visiblePosts .map(toArticleCardData) .filter((entry): entry is DatedCard => entry !== null) const videoCards = (youtubeFeed?.videos ?? []).map(toVideoCardData) const instagramCards = (instagramFeed?.posts ?? []).map(toInstagramCardData) const cards = [...articleCards, ...videoCards, ...instagramCards] .sort(byRecencyDesc) .slice(0, CONTENT_SECTION_LIMIT) .map(({ card }) => card) const [featured, ...rest] = cards return (

Acompanhe de perto

O mandato, onde a Bahia acontece

Notícias, vídeos e registros do trabalho em Brasília e nos municípios.

{featured ? (
{rest.map((card) => (
))}
) : (

Ainda não há publicações

As notícias do mandato aparecerão aqui assim que forem publicadas.

)} {featured ? (
) : null}
) }