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:
@@ -695,3 +695,14 @@ a.pair-row:hover strong { color: var(--gold); }
|
||||
.site-header { gap: 8px 12px; }
|
||||
.logo { font-size: 25px; }
|
||||
}
|
||||
|
||||
/* Sharing a chart (summary card) and the public share page */
|
||||
.share { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
|
||||
.share-open { align-items: stretch; padding: 14px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel-2); }
|
||||
.share-link { display: flex; gap: 8px; }
|
||||
.share-link .inp { min-height: 36px; font-size: 14px; }
|
||||
.share-trio { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--ink-2); font-size: 14px; }
|
||||
.share-trio .sym { color: var(--gold); }
|
||||
.share-cta { gap: 12px; }
|
||||
.share-cta h2 { font-size: 24px; }
|
||||
.share-cta .btn { align-self: flex-start; }
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
// The link preview image of a shared chart (og:image): 1200×630 PNG with the
|
||||
// wheel, the title and the text of the short summary. The file name carries
|
||||
// a version (see `imageVersion`), so a rewritten summary gets a new address
|
||||
// and Facebook and co. fetch it again.
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { ImageResponse } from "next/og";
|
||||
|
||||
import { SIGNS, signName } from "@/lib/astro";
|
||||
import { bigThree, loadShare, plain, shorten } from "@/lib/share";
|
||||
import { wheelSvg } from "@/lib/wheelSvg";
|
||||
|
||||
const W = 1200;
|
||||
const H = 630;
|
||||
const WHEEL = 590;
|
||||
|
||||
const FONTS = join(process.cwd(), "src/assets/og");
|
||||
let fonts: Promise<{ name: string; data: Buffer; weight: 400 | 600; style: "normal" }[]> | null = null;
|
||||
|
||||
function loadFonts() {
|
||||
fonts ??= Promise.all(
|
||||
(
|
||||
[
|
||||
["Cormorant Garamond", "CormorantGaramond-SemiBold.ttf", 600],
|
||||
["Inter", "Inter-Regular.ttf", 400],
|
||||
["Inter", "Inter-SemiBold.ttf", 600],
|
||||
["DejaVu Sans", "DejaVuSans.ttf", 400],
|
||||
] as const
|
||||
).map(async ([name, file, weight]) => ({
|
||||
name,
|
||||
data: await readFile(join(FONTS, file)),
|
||||
weight,
|
||||
style: "normal" as const,
|
||||
})),
|
||||
);
|
||||
return fonts;
|
||||
}
|
||||
|
||||
// Letters, digits, punctuation and spaces only: a character missing from the
|
||||
// fonts would make the renderer download a font from the internet.
|
||||
const printable = (s: string) => s.replace(/[^\p{L}\p{N}\p{P}\p{Zs}+=<>°]/gu, "");
|
||||
|
||||
export async function GET(_req: Request, { params }: { params: Promise<{ slug: string; file: string }> }) {
|
||||
const { slug } = await params;
|
||||
const share = await loadShare(slug);
|
||||
const chart = share?.chart?.chart;
|
||||
if (!share || !chart) return new Response("Not found", { status: 404 });
|
||||
|
||||
const title = printable(share.summary?.title ?? "Születési képlet");
|
||||
const text = printable(shorten(plain(share.summary?.summary ?? ""), 280));
|
||||
const svg = wheelSvg(chart, chart.time_known, WHEEL);
|
||||
const trio = bigThree(chart);
|
||||
|
||||
const image = new ImageResponse(
|
||||
(
|
||||
<div style={{ display: "flex", width: W, height: H, background: "#0d1220", color: "#ece6d8", fontFamily: "Inter" }}>
|
||||
<div style={{ display: "flex", width: WHEEL + 40, height: H, alignItems: "center", justifyContent: "center" }}>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={`data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`}
|
||||
width={WHEEL}
|
||||
height={WHEEL}
|
||||
alt=""
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
flex: 1,
|
||||
padding: "56px 56px 44px 8px",
|
||||
gap: 18,
|
||||
}}
|
||||
>
|
||||
<div style={{ display: "flex", fontSize: 17, fontWeight: 600, letterSpacing: 2.5, color: "#d9b46a" }}>
|
||||
SZÜLETÉSI KÉPLET · RÖVIDEN
|
||||
</div>
|
||||
<div style={{ display: "flex", fontFamily: "Cormorant Garamond", fontSize: 56, lineHeight: 1.05 }}>{title}</div>
|
||||
{text && <div style={{ display: "flex", fontSize: 23, lineHeight: 1.45, color: "#c9cfdc" }}>{text}</div>}
|
||||
<div style={{ display: "flex", marginTop: "auto", gap: 22, fontSize: 21, color: "#c9cfdc" }}>
|
||||
{trio.map((t) => (
|
||||
<div key={t.label} style={{ display: "flex", alignItems: "center", gap: 8 }}>
|
||||
<span style={{ fontFamily: "DejaVu Sans", color: "#d9b46a" }}>
|
||||
{(SIGNS[t.sign]?.glyph ?? "").replace(/︎/g, "")}
|
||||
</span>
|
||||
<span>
|
||||
{t.label === "Aszcendens" ? "Asc" : t.label} {signName(t.sign)}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div style={{ display: "flex", fontFamily: "Cormorant Garamond", fontSize: 30, color: "#ece6d8" }}>
|
||||
sors<span style={{ color: "#d9b46a" }}>fonalak</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
{
|
||||
width: W,
|
||||
height: H,
|
||||
fonts: await loadFonts(),
|
||||
// A day at the edge: a revoked link's image goes away from there too.
|
||||
headers: { "Cache-Control": "public, max-age=3600, s-maxage=86400" },
|
||||
},
|
||||
);
|
||||
return image;
|
||||
}
|
||||
@@ -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