Famous people: admin page, own prompt, one photo, public pages
CI / test (push) Successful in 2m21s
CI / build (push) Skipped
CI / deploy (push) Skipped

- Admin "Híres emberek": birth data, one photo (S3: DigitalOcean Spaces in
  production, RustFS in development), a face point that every crop keeps
  in view, publishing, and a detailed portrait written with its own
  `celebrity` prompt (third person, by name, from the chart alone).
- The photo is stored once (upright JPEG, at most 2000 px, no metadata);
  next/image makes the sizes from it, so Cloudflare can cache those.
- Public list and pages (/hires-emberek), in the sitemap, with a share
  image showing the face and the chart.
- Share images: the wheel's glyphs and numbers are drawn with the card's
  fonts (inside the SVG image they came out as boxes, on every card).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-22 16:08:35 +00:00
co-authored by Claude Opus 5.5
parent 13e22a9c7d
commit 37cb0abf4b
47 changed files with 3008 additions and 77 deletions
+62
View File
@@ -0,0 +1,62 @@
// Famous people's public pages (`/hires-emberek`): loading them from the
// backend, with a short cache that the admin's changes clear.
import "server-only";
import { cookies } from "next/headers";
import { cache } from "react";
import { BACKEND_URL, SESSION_COOKIE } from "./server";
import { countryName } from "./astro";
import { MONTHS } from "./birth";
import type { CelebrityListItem, PublicBirth, PublicCelebrity } from "./types";
/** Cache tag of the public pages; any admin change clears it (see the /api/v1 proxy). */
export const CELEBRITIES_TAG = "celebrities";
const SLUG = /^[a-z0-9]+(-[a-z0-9]+)*$/;
/**
* A published famous person, or `null`. A draft is loaded for admins only,
* with their session and without caching.
*/
export const loadCelebrity = cache(async (slug: string): Promise<PublicCelebrity | null> => {
if (!SLUG.test(slug) || slug.length > 80) return null;
const res = await fetch(`${BACKEND_URL}/v1/public/celebrities/${slug}`, {
next: { revalidate: 300, tags: [CELEBRITIES_TAG] },
});
if (res.ok) return (await res.json()) as PublicCelebrity;
if (res.status !== 404) throw new Error(`celebrity ${slug}: HTTP ${res.status}`);
const token = (await cookies()).get(SESSION_COOKIE)?.value;
if (!token) return null;
const draft = await fetch(`${BACKEND_URL}/v1/public/celebrities/${slug}`, {
headers: { authorization: `Bearer ${token}` },
cache: "no-store",
});
return draft.ok ? ((await draft.json()) as PublicCelebrity) : null;
});
/** The published famous people, newest first. */
export const loadCelebrities = cache(async (): Promise<CelebrityListItem[]> => {
const res = await fetch(`${BACKEND_URL}/v1/public/celebrities`, {
next: { revalidate: 300, tags: [CELEBRITIES_TAG] },
});
if (!res.ok) throw new Error(`celebrities: HTTP ${res.status}`);
return ((await res.json()) as { celebrities: CelebrityListItem[] }).celebrities;
});
/** Changes whenever the page changes (photo, face point, analysis), so link previews fetch the new image. */
export function celebrityImageVersion(c: PublicCelebrity): string {
const stamp = [c.updated_at, c.analysis?.completed_at ?? ""].map((t) => (t ? Date.parse(t).toString(36) : "0"));
return `${c.id.replace(/-/g, "").slice(-6)}${stamp.join("")}`;
}
/** "1926. június 1., 9:30, Los Angeles (Egyesült Államok)"; a Hungarian place without the country. */
export function birthLine(birth: PublicBirth): string {
const [y, m, d] = birth.date.split("-").map(Number);
const date = y && m && d ? `${y}. ${MONTHS[m - 1]} ${d}.` : birth.date;
const time = birth.time ? `, ${Number(birth.time.slice(0, 2))}:${birth.time.slice(3, 5)}` : "";
const country =
birth.country_code && birth.country_code !== "HU" ? ` (${countryName(birth.country_code, birth.country ?? undefined)})` : "";
const place = birth.place ? `, ${birth.place}${country}` : "";
return `${date}${time}${place}`;
}
@@ -0,0 +1,36 @@
// A famous person's photo: one stored version, served by the backend through
// the /api/v1 proxy; next/image makes the sized versions from it (and
// Cloudflare caches those), so no sizes are stored.
import type { CelebrityPhoto } from "./types";
/** The stored photo's address on this site (also the source of next/image). */
export function photoSrc(photo: Pick<CelebrityPhoto, "key">): string {
return `/api/v1/public/photos/${photo.key.split("/").map(encodeURIComponent).join("/")}`;
}
/** CSS `object-position` that keeps the face point in view when the photo is cropped. */
export function objectPosition(photo: Pick<CelebrityPhoto, "focus_x" | "focus_y">): string {
return `${(photo.focus_x * 100).toFixed(1)}% ${(photo.focus_y * 100).toFixed(1)}%`;
}
/**
* Where a `width`×`height` photo goes in a `boxW`×`boxH` frame so that it
* covers it with the face point as near the middle as the edges allow (for
* the preview image, whose renderer has no object-position).
*/
export function coverBox(
photo: Pick<CelebrityPhoto, "width" | "height" | "focus_x" | "focus_y">,
boxW: number,
boxH: number,
): { width: number; height: number; left: number; top: number } {
const scale = Math.max(boxW / photo.width, boxH / photo.height);
const width = Math.ceil(photo.width * scale);
const height = Math.ceil(photo.height * scale);
const clamp = (v: number, min: number) => Math.round(Math.min(0, Math.max(min, v)));
return {
width,
height,
left: clamp(boxW / 2 - photo.focus_x * width, boxW - width),
top: clamp(boxH / 2 - photo.focus_y * height, boxH - height),
};
}
+131 -9
View File
@@ -8,8 +8,9 @@ import { join } from "node:path";
import { ImageResponse } from "next/og";
import { coverBox } from "./celebrityPhoto";
import type { ChartResult } from "./types";
import { wheelSvg } from "./wheelSvg";
import { LABEL_STYLE, WHEEL_UNITS, wheelSvg } from "./wheelSvg";
const W = 1200;
const H = 630;
@@ -43,6 +44,53 @@ function loadFonts() {
*/
export const printable = (s: string) => s.replace(/[^\p{L}\p{N}\p{P}\p{Zs}+=<>°]/gu, "");
/**
* The chart wheel, `size` pixels: the SVG image without its labels, and the
* labels drawn on top with the card's fonts (inside an SVG image the renderer
* has no fonts, so glyphs and numbers would come out as boxes).
*/
function Wheel({ chart, timeKnown, size }: { chart: ChartResult; timeKnown: boolean; size: number }) {
const { svg, labels } = wheelSvg(chart, timeKnown, size);
const k = size / WHEEL_UNITS;
return (
<div style={{ display: "flex", position: "relative", width: size, height: size }}>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img src={`data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`} width={size} height={size} alt="" />
{labels.map((l, i) => {
const style = l.className.split(" ").map((c) => LABEL_STYLE[c]).find(Boolean);
if (!style) return null;
const fontSize = style.size * k;
const w = fontSize * 6;
const h = fontSize * 1.4;
return (
<div
key={i}
style={{
display: "flex",
position: "absolute",
left: l.x * k - w / 2,
top: l.y * k - h / 2,
width: w,
height: h,
alignItems: "center",
justifyContent: "center",
fontFamily: style.font,
fontWeight: style.weight,
fontSize,
lineHeight: 1,
color: style.color,
// No undefined values: the renderer stumbles on them.
...(style.halo ? { textShadow: "0 0 3px #111729" } : {}),
}}
>
{style.font === "DejaVu Sans" ? l.text : printable(l.text)}
</div>
);
})}
</div>
);
}
export interface CardLine {
/** A zodiac or planet glyph (DejaVu Sans has them all). */
glyph: string;
@@ -67,18 +115,11 @@ export async function chartCard({
lines: CardLine[];
cacheControl: string;
}): Promise<Response> {
const svg = wheelSvg(chart, timeKnown, WHEEL);
return 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=""
/>
<Wheel chart={chart} timeKnown={timeKnown} size={WHEEL} />
</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" }}>
@@ -107,3 +148,84 @@ export async function chartCard({
{ width: W, height: H, fonts: await loadFonts(), headers: { "Cache-Control": cacheControl } },
);
}
/**
* A famous person's preview image: the photo on the left (cropped around the
* face point), the name, the Sun, Moon and Ascendant and the chart wheel on
* the right. `photo`: the stored JPEG as bytes, with its size and face point.
*/
export async function celebrityCard({
chart,
timeKnown,
name,
subtitle,
lines,
photo,
cacheControl,
}: {
chart: ChartResult;
timeKnown: boolean;
name: string;
subtitle: string | null;
lines: CardLine[];
photo: { data: ArrayBuffer; width: number; height: number; focus_x: number; focus_y: number } | null;
cacheControl: string;
}): Promise<Response> {
const PHOTO_W = 440;
const RING = 400;
const box = photo && coverBox(photo, PHOTO_W, H);
return new ImageResponse(
(
<div style={{ display: "flex", width: W, height: H, background: "#0d1220", color: "#ece6d8", fontFamily: "Inter" }}>
{photo && box && (
<div style={{ display: "flex", position: "relative", width: PHOTO_W, height: H, overflow: "hidden" }}>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={`data:image/jpeg;base64,${Buffer.from(photo.data).toString("base64")}`}
width={box.width}
height={box.height}
style={{ position: "absolute", left: box.left, top: box.top }}
alt=""
/>
<div
style={{
position: "absolute",
right: 0,
top: 0,
width: 90,
height: H,
background: "linear-gradient(90deg, rgba(13,18,32,0) 0%, #0d1220 100%)",
}}
/>
</div>
)}
<div style={{ display: "flex", flexDirection: "column", flex: 1, padding: "44px 48px 36px 36px" }}>
<div style={{ display: "flex", fontSize: 17, fontWeight: 600, letterSpacing: 2.5, color: "#d9b46a" }}>
HÍRES EMBEREK HOROSZKÓPJA
</div>
<div style={{ display: "flex", fontFamily: "Cormorant Garamond", fontSize: 58, lineHeight: 1.05, marginTop: 12 }}>
{printable(name)}
</div>
{subtitle && (
<div style={{ display: "flex", fontSize: 22, color: "#c9cfdc", marginTop: 6 }}>{printable(subtitle)}</div>
)}
<div style={{ display: "flex", flex: 1, alignItems: "center", gap: 28, marginTop: 8 }}>
<Wheel chart={chart} timeKnown={timeKnown} size={RING} />
<div style={{ display: "flex", flexDirection: "column", gap: 14, fontSize: 24, color: "#c9cfdc" }}>
{lines.map((l) => (
<div key={l.label} style={{ display: "flex", alignItems: "center", gap: 10 }}>
<span style={{ fontFamily: "DejaVu Sans", color: "#d9b46a" }}>{l.glyph.replace(/︎/g, "")}</span>
<span>{printable(l.label)}</span>
</div>
))}
<div style={{ display: "flex", fontFamily: "Cormorant Garamond", fontSize: 32, color: "#ece6d8", marginTop: 18 }}>
sors<span style={{ color: "#d9b46a" }}>fonalak</span>
</div>
</div>
</div>
</div>
</div>
),
{ width: W, height: H, fonts: await loadFonts(), headers: { "Cache-Control": cacheControl } },
);
}
+71 -3
View File
@@ -252,7 +252,7 @@ export interface SynastryListItem {
export interface Analysis {
id: string;
kind: "natal" | "synastry" | "summary" | "forecast";
kind: "natal" | "synastry" | "summary" | "forecast" | "celebrity";
status: "pending" | "running" | "done" | "failed";
model: string;
language: string;
@@ -295,7 +295,7 @@ export interface AdminUser {
analyses_left: UnitBalance;
}
export type PromptKind = "summary" | "natal" | "synastry" | "forecast" | "question";
export type PromptKind = "summary" | "natal" | "synastry" | "forecast" | "question" | "celebrity";
/** Admin: the model of one function (all analyses and forecasts, answers, the short summary). */
export interface ModelFunction {
@@ -319,7 +319,7 @@ export interface ModelFunction {
export interface AdminJob {
id: string;
type: "analysis" | "question";
kind: "summary" | "natal" | "synastry" | "forecast" | "question";
kind: "summary" | "natal" | "synastry" | "forecast" | "question" | "celebrity";
status: "pending" | "running";
/** The model of the current attempt. */
model: string;
@@ -388,6 +388,74 @@ export interface PromptPreview {
seconds: number | null;
}
export type ChartHighlights = Chart["highlights"];
/** A famous person's photo: a key in the object storage, its size and the face point (0..1). */
export interface CelebrityPhoto {
key: string;
width: number;
height: number;
focus_x: number;
focus_y: number;
}
/** Birth date, time and place as the public pages show them. */
export interface PublicBirth {
date: string;
time: string | null;
place: string | null;
region: string | null;
country: string | null;
country_code: string | null;
}
interface CelebrityBase {
id: string;
name: string;
subtitle: string | null;
slug: string;
published: boolean;
published_at: string | null;
photo: CelebrityPhoto | null;
created_at: string;
updated_at: string;
}
/** `GET /v1/public/celebrities`: one item of the public list. */
export interface CelebrityListItem extends CelebrityBase {
birth: PublicBirth;
highlights: ChartHighlights;
}
/** `GET /v1/public/celebrities/{slug}`: the public page. */
export interface PublicCelebrity extends CelebrityBase {
chart: ChartResult & { time_known: boolean; birth: PublicBirth };
analysis: { id: string; language: string; content: AnalysisContent; completed_at: string | null } | null;
}
/** Admin: a famous person with the birth data for the edit form. */
export interface AdminCelebrity extends CelebrityBase {
birth_data: BirthData;
birth: PublicBirth;
highlights: ChartHighlights;
chart: ChartResult;
analysis: Analysis | null;
}
/** Admin: one row of the list. */
export interface AdminCelebrityRow {
id: string;
chart_id: string;
name: string;
subtitle: string | null;
slug: string;
published: boolean;
has_photo: boolean;
birth: PublicBirth;
highlights: ChartHighlights;
analysis_status: Analysis["status"] | null;
}
export interface AnalysisContent {
title?: string;
summary?: string;
+52 -12
View File
@@ -1,6 +1,10 @@
// The chart wheel as a standalone SVG document, for the share preview image.
// It reuses the page's <ChartWheel> and turns its element tree into markup
// with the colours inlined (no page CSS there).
//
// The renderer of the preview images draws an SVG image without fonts, so the
// labels (glyphs, degrees, house numbers) are taken out of the SVG and given
// back with their places: the card draws them on top with its own fonts.
import { Fragment, isValidElement, type ReactElement, type ReactNode } from "react";
import { ChartWheel, SIZE } from "@/components/ChartWheel";
@@ -46,29 +50,65 @@ function attribute(name: string): string {
return name.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
}
function markup(node: ReactNode): string {
/** A label of the wheel: its centre in wheel units (0..SIZE), its text and class. */
export interface WheelLabel {
x: number;
y: number;
text: string;
className: string;
}
/** The visible text of a node (without <title>). */
function textOf(node: ReactNode): string {
if (node === null || node === undefined || typeof node === "boolean") return "";
if (typeof node === "string" || typeof node === "number") return escape(String(node));
if (Array.isArray(node)) return node.map(markup).join("");
if (typeof node === "string" || typeof node === "number") return String(node);
if (Array.isArray(node)) return node.map(textOf).join("");
if (!isValidElement(node)) return "";
const { type, props } = node as ReactElement<Record<string, unknown>>;
if (type === Fragment) return markup(props.children as ReactNode);
if (typeof type === "function") return markup((type as (p: unknown) => ReactNode)(props));
if (type === "title" || type === "desc") return "";
return textOf(props.children as ReactNode);
}
function markup(node: ReactNode, labels: WheelLabel[]): string {
if (node === null || node === undefined || typeof node === "boolean") return "";
if (typeof node === "string" || typeof node === "number") return escape(String(node));
if (Array.isArray(node)) return node.map((n) => markup(n, labels)).join("");
if (!isValidElement(node)) return "";
const { type, props } = node as ReactElement<Record<string, unknown>>;
if (type === Fragment) return markup(props.children as ReactNode, labels);
if (typeof type === "function") return markup((type as (p: unknown) => ReactNode)(props), labels);
if (typeof type !== "string" || type === "title" || type === "desc") return "";
if (type === "text") {
const text = textOf(props.children as ReactNode).replace(/\uFE0E/g, "");
if (text) labels.push({ x: Number(props.x), y: Number(props.y), text, className: String(props.className ?? "") });
return "";
}
const attrs = Object.entries(props)
.filter(([k, v]) => !SKIP.has(k) && !k.startsWith("aria-") && v !== undefined && v !== null && v !== false)
.map(([k, v]) => ` ${attribute(k)}="${escape(String(v))}"`)
.join("");
return `<${type}${attrs}>${markup(props.children as ReactNode)}</${type}>`;
return `<${type}${attrs}>${markup(props.children as ReactNode, labels)}</${type}>`;
}
/** The wheel as an SVG document of `size` pixels. */
export function wheelSvg(chart: ChartResult, timeKnown: boolean, size = SIZE): string {
const body = markup(ChartWheel({ chart, timeKnown }))
/** The wheel as an SVG document of `size` pixels, without its labels, and the labels. */
export function wheelSvg(chart: ChartResult, timeKnown: boolean, size = SIZE): { svg: string; labels: WheelLabel[] } {
const labels: WheelLabel[] = [];
const body = markup(ChartWheel({ chart, timeKnown }), labels)
.replace(/^<svg[^>]*>/, "")
.replace(/<\/svg>$/, "");
return (
const svg =
`<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 ${SIZE} ${SIZE}">` +
`<style>${STYLE}</style>${body}</svg>`
);
`<style>${STYLE}</style>${body}</svg>`;
return { svg, labels };
}
/** How each kind of label looks (the page's wheel rules), in wheel units. */
export const LABEL_STYLE: Record<string, { font: string; size: number; weight: 400 | 600; color: string; halo: boolean }> = {
"w-sign-glyph": { font: "DejaVu Sans", size: 22, weight: 400, color: "#d9b46a", halo: false },
"w-point-glyph": { font: "DejaVu Sans", size: 22, weight: 400, color: "#ece6d8", halo: true },
"w-axis-label": { font: "Inter", size: 14, weight: 600, color: "#d9b46a", halo: true },
"w-house-num": { font: "Inter", size: 12, weight: 400, color: "#a3abc0", halo: true },
"w-point-deg": { font: "Inter", size: 10.5, weight: 400, color: "#a3abc0", halo: true },
};
export { SIZE as WHEEL_UNITS };