teqo-backup/src/lib/contentShare.ts
Francisco Solla b8051bb7e0 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:48:12 -03:00

52 lines
1.9 KiB
TypeScript

import { buildWhatsAppTextShareUrl } from '@/lib/phone'
/**
* Content source of a home content card — drives the share message template.
* S29 adds `event`: the public announcement page shares its own short link.
*/
export type ContentShareKind = 'article' | 'video' | 'instagram' | 'event'
/**
* Message opener per source (S4 acceptance, decision B): article shares "isso",
* YouTube "esse vídeo", Instagram "esse post"; S29 event invites ("Participe").
* The rest of the message is always "{title} — {link}".
*/
export const CONTENT_SHARE_PREFIXES: Record<ContentShareKind, string> = {
article: 'Olha isso do Solla: ',
video: 'Olha esse vídeo do Solla: ',
instagram: 'Olha esse post do Solla: ',
event: 'Participe: ',
}
/** Pre-configured share message: opener + title + absolute link. */
export const buildContentShareMessage = (
kind: ContentShareKind,
title: string,
link: string,
): string => `${CONTENT_SHARE_PREFIXES[kind]}${title} — ${link}`
/**
* Resolve the shared link to an absolute URL against the visitor's origin.
* Article paths are relative (`/noticia/saude/<slug>`); YouTube/Instagram
* hrefs are already absolute and pass through unchanged. Fail-soft on a
* malformed href (a bad feed permalink must degrade the share link, never
* crash the whole home section).
*/
export const buildContentShareLink = (href: string, origin: string): string => {
try {
return new URL(href, origin).toString()
} catch {
return href
}
}
/**
* `wa.me` URL with the pre-filled message — the sender's own WhatsApp, no
* recipient phone (reuses the `phone.ts` text-share builder). Callers must
* open it in a new tab with `noopener noreferrer`.
*/
export const buildContentShareWhatsAppUrl = (
kind: ContentShareKind,
title: string,
link: string,
): string => buildWhatsAppTextShareUrl(buildContentShareMessage(kind, title, link))