teqo-backup/src/app/(frontend)/jingles/page.tsx
Francisco Solla 4e292b0b93 feat(S29): link com destino trocável e página de anúncio da atividade
- shareLink ganha modo (direct|announcement), pool de destinos com "Destino no
  ar" por linha e dados do evento; destination escalar sai via migration com
  backfill lossless (legado vira direct com destino no ar)
- página de anúncio pública portada classe-a-classe, header campaign-site
  extraído (CampaignPageHeader) e ativação/troca sem reload por poll da rota
  /api/share-link/<slug>/live (fail-closed, no-store)
- agenda Google (action=TEMPLATE) + .ics por rota sob o slug; compartilhar o
  link curto (kind event); S19 intacto e 404 uniforme preservado

Related #1268
2026-09-23 11:21:49 -03:00

107 lines
3.7 KiB
TypeScript

import { CampaignFooter } from '@/components/CampaignFooter'
import { CampaignPageHeader } from '@/components/CampaignPageHeader'
import { JingleEmptyState } from '@/components/jingles/JingleEmptyState'
import { JingleIntro } from '@/components/jingles/JingleIntro'
import { JinglePlayer } from '@/components/jingles/JinglePlayer'
import type { Media } from '@/payload-types'
import { hasPublishedContentPieces } from '@/utilities/content/contentPieceReads'
import { getCachedDocumentById } from '@/utilities/documentReads'
import { getCachedGlobal } from '@/utilities/globalReads'
import { getPublishedJingleItems } from '@/utilities/jingleReads'
import {
absoluteSitePath,
resolveDeploymentOrigin,
resolveSiteMetadata,
toAbsoluteUrl,
} from '@/utilities/seo'
import type { Metadata } from 'next'
const JINGLES_PATH = '/jingles'
const JINGLES_TITLE = 'Jingles de Jorge Solla'
const JINGLES_DESCRIPTION =
'Ouça aqui mesmo e baixe os jingles oficiais de Jorge Solla 1313. Grátis, sem cadastro e direto no celular.'
/**
* S21 — the public jingles page: the published pieces with cover, in-page
* player and MP3 download. Indexable with its own title/description while
* there is content; zero published renders the honest empty state and hides
* discovery (footer link + header badge), never a 404.
*/
export async function generateMetadata(): Promise<Metadata> {
const [items, globalMetadata] = await Promise.all([
getPublishedJingleItems(),
getCachedGlobal('metadata')(),
])
const { siteUrl, siteName, twitterCreator } = resolveSiteMetadata(globalMetadata)
const canonicalUrl = absoluteSitePath(siteUrl, JINGLES_PATH)
const deploymentOrigin = resolveDeploymentOrigin(siteUrl)
// The media proxy only exists on the deployment origin (the global URL may be
// a canonical domain served elsewhere), same rule as the share-link OG image.
const coverUrl =
items[0] && deploymentOrigin ? toAbsoluteUrl(items[0].coverUrl, deploymentOrigin) : undefined
let fallbackImage: Media | null = null
if (!coverUrl && globalMetadata.image) {
fallbackImage =
typeof globalMetadata.image === 'number'
? await getCachedDocumentById('media', String(globalMetadata.image))()
: globalMetadata.image
}
const imageUrl =
coverUrl ??
(fallbackImage?.url && deploymentOrigin
? toAbsoluteUrl(fallbackImage.url, deploymentOrigin)
: undefined)
const title = `${JINGLES_TITLE} | ${siteName}`
const images = imageUrl ? [{ url: imageUrl, alt: items[0]?.coverAlt ?? JINGLES_TITLE }] : []
return {
title,
description: JINGLES_DESCRIPTION,
...(items.length === 0 ? { robots: { index: false, follow: false } } : {}),
...(canonicalUrl ? { alternates: { canonical: canonicalUrl } } : {}),
openGraph: {
type: 'website',
locale: 'pt-BR',
...(canonicalUrl ? { url: canonicalUrl } : {}),
siteName,
title,
description: JINGLES_DESCRIPTION,
images,
},
twitter: {
card: 'summary_large_image',
title,
description: JINGLES_DESCRIPTION,
creator: twitterCreator,
images: images.map((image) => image.url),
},
}
}
export default async function JinglesPage() {
const [items, showConteudos] = await Promise.all([
getPublishedJingleItems(),
hasPublishedContentPieces(),
])
const hasItems = items.length > 0
return (
<>
<CampaignPageHeader badge={hasItems ? 'Jingles oficiais' : undefined} />
<main className="w-full bg-white">
{hasItems ? (
<>
<JingleIntro />
<JinglePlayer jingles={items} />
</>
) : (
<JingleEmptyState />
)}
</main>
<CampaignFooter showJingles={hasItems} showConteudos={showConteudos} current="jingles" />
</>
)
}