diff --git a/services/frontend/src/app/s/[slug]/kep/[file]/route.tsx b/services/frontend/src/app/s/[slug]/kep/[file]/route.tsx
index d9f67dc..588671c 100644
--- a/services/frontend/src/app/s/[slug]/kep/[file]/route.tsx
+++ b/services/frontend/src/app/s/[slug]/kep/[file]/route.tsx
@@ -1,108 +1,27 @@
-// 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";
-
+// The link preview image of a shared chart (og:image): 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 { SIGNS, signName } from "@/lib/astro";
+import { chartCard } from "@/lib/ogCard";
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(
- (
-
-
- {/* eslint-disable-next-line @next/next/no-img-element */}
-
.toString("base64")}`})
-
-
-
- SZÜLETÉSI KÉPLET · RÖVIDEN
-
-
{title}
- {text &&
{text}
}
-
- {trio.map((t) => (
-
-
- {(SIGNS[t.sign]?.glyph ?? "").replace(/︎/g, "")}
-
-
- {t.label === "Aszcendens" ? "Asc" : t.label} {signName(t.sign)}
-
-
- ))}
-
-
- sorsfonalak
-
-
-
- ),
- {
- 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;
+ return chartCard({
+ chart,
+ timeKnown: chart.time_known,
+ eyebrow: "SZÜLETÉSI KÉPLET · RÖVIDEN",
+ title: share.summary?.title ?? "Születési képlet",
+ text: shorten(plain(share.summary?.summary ?? ""), 280),
+ lines: bigThree(chart).map((t) => ({
+ glyph: SIGNS[t.sign]?.glyph ?? "",
+ label: `${t.label === "Aszcendens" ? "Asc" : t.label} ${signName(t.sign)}`,
+ })),
+ // A day at the edge: a revoked link's image goes away from there too.
+ cacheControl: "public, max-age=3600, s-maxage=86400",
+ });
}
diff --git a/services/frontend/src/app/s/[slug]/page.tsx b/services/frontend/src/app/s/[slug]/page.tsx
index 6b67c74..bb96947 100644
--- a/services/frontend/src/app/s/[slug]/page.tsx
+++ b/services/frontend/src/app/s/[slug]/page.tsx
@@ -5,7 +5,7 @@ import { notFound } from "next/navigation";
import { ChartWheel, WheelLegend } from "@/components/ChartWheel";
import { Rich } from "@/components/Rich";
import { ShareVisit } from "@/components/ShareVisit";
-import { Logo } from "@/components/SiteHeader";
+import { PublicHeader } from "@/components/SiteHeader";
import { SIGNS, signName } from "@/lib/astro";
import { getMe } from "@/lib/server";
import { bigThree, imageVersion, loadShare, plain, shorten, siteUrl } from "@/lib/share";
@@ -48,13 +48,7 @@ export default async function SharedChartPage({ params }: Props) {
<>
{!me && (
-
+
)}
diff --git a/services/frontend/src/components/SiteHeader.tsx b/services/frontend/src/components/SiteHeader.tsx
index e625797..d38423b 100644
--- a/services/frontend/src/components/SiteHeader.tsx
+++ b/services/frontend/src/components/SiteHeader.tsx
@@ -13,6 +13,30 @@ export function Logo() {
);
}
+/**
+ * The header for visitors (not logged in): the home page sections, the
+ * example and the login. `onHome`: the section links stay on the page.
+ */
+export function PublicHeader({ onHome = false, current }: { onHome?: boolean; current?: "pelda" }) {
+ const home = onHome ? "" : "/";
+ return (
+
+ );
+}
+
/** The user's package and what is left of it; leads to the packages page. */
function PackageBadge({ me }: { me: Me }) {
const { natal, synastry } = me.analyses_left;
diff --git a/services/frontend/src/lib/ogCard.tsx b/services/frontend/src/lib/ogCard.tsx
new file mode 100644
index 0000000..6b08eb5
--- /dev/null
+++ b/services/frontend/src/lib/ogCard.tsx
@@ -0,0 +1,109 @@
+// Link preview images (og:image): 1200×630 PNG with a chart wheel on the left
+// and text on the right, in the site's look. Used by the shared charts and
+// the home page.
+import "server-only";
+
+import { readFile } from "node:fs/promises";
+import { join } from "node:path";
+
+import { ImageResponse } from "next/og";
+
+import type { ChartResult } from "./types";
+import { wheelSvg } from "./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.
+ */
+export const printable = (s: string) => s.replace(/[^\p{L}\p{N}\p{P}\p{Zs}+=<>°]/gu, "");
+
+export interface CardLine {
+ /** A zodiac or planet glyph (DejaVu Sans has them all). */
+ glyph: string;
+ label: string;
+}
+
+/** The preview image as a response with the given cache header. */
+export async function chartCard({
+ chart,
+ timeKnown,
+ eyebrow,
+ title,
+ text,
+ lines,
+ cacheControl,
+}: {
+ chart: ChartResult;
+ timeKnown: boolean;
+ eyebrow: string;
+ title: string;
+ text: string;
+ lines: CardLine[];
+ cacheControl: string;
+}): Promise
{
+ const svg = wheelSvg(chart, timeKnown, WHEEL);
+ return new ImageResponse(
+ (
+
+
+ {/* eslint-disable-next-line @next/next/no-img-element */}
+
.toString("base64")}`})
+
+
+
+ {printable(eyebrow)}
+
+
+ {printable(title)}
+
+ {text && (
+
{printable(text)}
+ )}
+
+ {lines.map((l) => (
+
+ {l.glyph.replace(/︎/g, "")}
+ {printable(l.label)}
+
+ ))}
+
+
+ sorsfonalak
+
+
+
+ ),
+ { width: W, height: H, fonts: await loadFonts(), headers: { "Cache-Control": cacheControl } },
+ );
+}