Famous people: admin page, own prompt, one photo, public pages
- 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:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user