Sharing a chart with its short summary, with link previews
The summary card gets a share button: a public link (/s/<slug>) with the wheel and the newest short summary, no name or birth data. The page carries og:/twitter: tags, and /s/<slug>/kep/<version>.png renders a 1200x630 preview (wheel, title, text, big three) with next/og and bundled fonts. The version changes with the summary, so Facebook fetches a rewritten one again. Backend: a shared chart comes with its newest finished summary, and sharing the same thing again returns the open link. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { ChartWheel, WheelLegend } from "@/components/ChartWheel";
|
||||
import { Rich } from "@/components/Rich";
|
||||
import { Logo } from "@/components/SiteHeader";
|
||||
import { SIGNS, signName } from "@/lib/astro";
|
||||
import { getMe } from "@/lib/server";
|
||||
import { bigThree, imageVersion, loadShare, plain, shorten, siteUrl } from "@/lib/share";
|
||||
|
||||
type Props = { params: Promise<{ slug: string }> };
|
||||
|
||||
/** Title, description and preview image for Facebook, Messenger, WhatsApp and co. */
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const share = await loadShare(slug);
|
||||
if (!share?.chart) return { title: "A link nem érhető el", robots: { index: false } };
|
||||
const base = await siteUrl();
|
||||
const title = share.summary?.title ?? "Születési képlet";
|
||||
const description = share.summary?.summary
|
||||
? shorten(plain(share.summary.summary), 200)
|
||||
: "Egy születési képlet a Sorsfonalakon.";
|
||||
const url = `${base}/s/${slug}`;
|
||||
const image = { url: `${base}/s/${slug}/kep/${imageVersion(share)}.png`, width: 1200, height: 630, alt: title };
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
// Personal content: shown when shared, not listed in search engines.
|
||||
robots: { index: false, follow: false },
|
||||
alternates: { canonical: url },
|
||||
openGraph: { type: "website", siteName: "Sorsfonalak", locale: "hu_HU", url, title, description, images: [image] },
|
||||
twitter: { card: "summary_large_image", title, description, images: [image.url] },
|
||||
};
|
||||
}
|
||||
|
||||
/** A shared chart: the wheel and its short summary, open to anyone with the link. */
|
||||
export default async function SharedChartPage({ params }: Props) {
|
||||
const { slug } = await params;
|
||||
const [share, me] = await Promise.all([loadShare(slug), getMe()]);
|
||||
const chart = share?.chart?.chart;
|
||||
if (!share || !chart) notFound();
|
||||
const summary = share.summary;
|
||||
const trio = bigThree(chart);
|
||||
|
||||
return (
|
||||
<>
|
||||
{!me && (
|
||||
<header className="site-header">
|
||||
<Logo />
|
||||
<span style={{ flex: 1 }} />
|
||||
<Link href="/belepes" className="btn btn-sm">
|
||||
Belépés
|
||||
</Link>
|
||||
</header>
|
||||
)}
|
||||
<main className="page" style={{ maxWidth: 1180 }}>
|
||||
<div className="page-head">
|
||||
<span className="eyebrow">Megosztott születési képlet</span>
|
||||
<h1>{summary?.title ?? "Születési képlet"}</h1>
|
||||
</div>
|
||||
|
||||
<section className="chart-layout" aria-label="A megosztott képlet">
|
||||
<div className="card chart-wheel-card">
|
||||
<ChartWheel chart={chart} timeKnown={chart.time_known} />
|
||||
<WheelLegend />
|
||||
</div>
|
||||
<div className="field chart-side">
|
||||
<section className="card summary-card" aria-label="Röviden">
|
||||
<span className="eyebrow">Röviden</span>
|
||||
{summary?.summary ? (
|
||||
<p className="summary-text" lang={summary.language}>
|
||||
<Rich text={summary.summary} />
|
||||
</p>
|
||||
) : (
|
||||
<p className="muted">Ehhez a képlethez még nincs rövid összefoglaló.</p>
|
||||
)}
|
||||
{trio.length > 0 && (
|
||||
<p className="share-trio">
|
||||
{trio.map((t) => (
|
||||
<span key={t.label}>
|
||||
<span className="sym" aria-hidden="true">
|
||||
{SIGNS[t.sign]?.glyph}
|
||||
</span>{" "}
|
||||
{t.label} {signName(t.sign)}
|
||||
</span>
|
||||
))}
|
||||
</p>
|
||||
)}
|
||||
{!chart.time_known && (
|
||||
<p className="hint">A születési idő nem ismert, ezért a képleten nincsenek házak és Aszcendens.</p>
|
||||
)}
|
||||
</section>
|
||||
<section className="card share-cta">
|
||||
<h2>És a te képleted mit mutat?</h2>
|
||||
<p className="muted">
|
||||
Add meg a születési adataidat, és megkapod a saját képletedet a rövid összefoglalóval együtt, ingyen.
|
||||
</p>
|
||||
<Link href={me ? "/keplet" : "/belepes"} className="btn btn-primary">
|
||||
{me ? "A saját képletem" : "Elkészítem a sajátomat"}
|
||||
</Link>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
<p className="hint">
|
||||
Ezt a képletet a tulajdonosa osztotta meg, név és születési adatok nélkül. A szöveget mesterséges intelligencia
|
||||
írta a képlet alapján.
|
||||
</p>
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user