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:
@@ -8,6 +8,15 @@ const config: NextConfig = {
|
||||
outputFileTracingIncludes: {
|
||||
"/s/[slug]/kep/[file]": ["./src/assets/og/*.ttf"],
|
||||
"/kep/fooldal.png": ["./src/assets/og/*.ttf"],
|
||||
"/hires-emberek/[slug]/kep/[file]": ["./src/assets/og/*.ttf"],
|
||||
},
|
||||
images: {
|
||||
// Only the famous people's photos (served by the backend through the
|
||||
// /api/v1 proxy, one stored version each) go through the optimizer.
|
||||
localPatterns: [{ pathname: "/api/v1/public/photos/**", search: "" }],
|
||||
formats: ["image/webp"],
|
||||
// The photo's address changes with every upload: the sized versions may be kept long.
|
||||
minimumCacheTTL: 2678400,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ const KINDS: Record<string, string> = {
|
||||
natal: "képletelemzés",
|
||||
synastry: "kapcsolati",
|
||||
forecast: "előrejelzés",
|
||||
celebrity: "híres ember",
|
||||
question: "válasz",
|
||||
};
|
||||
const OUTCOMES: Record<GenerationError["outcome"], { label: string; tone: string }> = {
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import { BirthForm } from "@/app/profil/BirthForm";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { signName } from "@/lib/astro";
|
||||
import type { AdminCelebrity, AdminCelebrityRow } from "@/lib/types";
|
||||
|
||||
export const ANALYSIS_STATUS: Record<string, string> = {
|
||||
pending: "sorban áll",
|
||||
running: "készül",
|
||||
done: "kész",
|
||||
failed: "sikertelen",
|
||||
};
|
||||
|
||||
/** The famous people (drafts too) and the form for a new one. */
|
||||
export function AdminCelebrities() {
|
||||
const router = useRouter();
|
||||
const [rows, setRows] = useState<AdminCelebrityRow[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [adding, setAdding] = useState(false);
|
||||
const [subtitle, setSubtitle] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
api<{ celebrities: AdminCelebrityRow[] }>("/admin/celebrities")
|
||||
.then((r) => setRows(r.celebrities))
|
||||
.catch((e) => setError(errorText(e)));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<section className="field" style={{ gap: 18 }}>
|
||||
{adding ? (
|
||||
<div className="card field" style={{ gap: 16 }}>
|
||||
<h2>Új híres ember</h2>
|
||||
<BirthForm
|
||||
initial={null}
|
||||
person={{}}
|
||||
save={(name, birth) =>
|
||||
api<AdminCelebrity>("/admin/celebrities", { body: { name, subtitle: subtitle.trim() || null, birth } })
|
||||
}
|
||||
onCancel={() => setAdding(false)}
|
||||
onSaved={(id) => router.push(`/admin/hires-emberek/${id}`)}
|
||||
>
|
||||
<SubtitleField value={subtitle} onChange={setSubtitle} />
|
||||
</BirthForm>
|
||||
<p className="hint">
|
||||
Mentés után kiszámolja a képletet, és elindítja a részletes portré írását. Utána tölthetsz fel fotót.
|
||||
</p>
|
||||
</div>
|
||||
) : (
|
||||
<div className="form-actions">
|
||||
<button type="button" className="btn btn-primary" onClick={() => setAdding(true)}>
|
||||
Új híres ember
|
||||
</button>
|
||||
<Link href="/hires-emberek" className="btn btn-ghost">
|
||||
Nyilvános lista
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{rows === null ? (
|
||||
!error && <p className="muted">Betöltés…</p>
|
||||
) : rows.length === 0 ? (
|
||||
<p className="muted">Még nincs híres ember.</p>
|
||||
) : (
|
||||
<div className="table-wrap">
|
||||
<table className="promo-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Név</th>
|
||||
<th>Született</th>
|
||||
<th>Nap · Hold · Asc</th>
|
||||
<th>Portré</th>
|
||||
<th>Fotó</th>
|
||||
<th>Állapot</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((c) => (
|
||||
<tr key={c.id}>
|
||||
<td>
|
||||
<Link href={`/admin/hires-emberek/${c.id}`}>{c.name}</Link>
|
||||
{c.subtitle && <span className="hint">{c.subtitle}</span>}
|
||||
</td>
|
||||
<td className="num">
|
||||
{c.birth.date}
|
||||
{c.birth.time ? ` ${c.birth.time}` : ""}
|
||||
{c.birth.place && <span className="hint">{c.birth.place}</span>}
|
||||
</td>
|
||||
<td>
|
||||
{[c.highlights.sun, c.highlights.moon, c.highlights.time_known ? c.highlights.ascendant : null]
|
||||
.map((s) => (s ? signName(s) : "–"))
|
||||
.join(" · ")}
|
||||
</td>
|
||||
<td>{c.analysis_status ? ANALYSIS_STATUS[c.analysis_status] : <span className="muted">–</span>}</td>
|
||||
<td>{c.has_photo ? "van" : <span className="muted">nincs</span>}</td>
|
||||
<td>
|
||||
{c.published ? (
|
||||
<Link href={`/hires-emberek/${c.slug}`} className="promo-open">
|
||||
közzétéve
|
||||
</Link>
|
||||
) : (
|
||||
<span className="muted">vázlat</span>
|
||||
)}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
/** The line under the name, e.g. "színésznő, énekesnő". */
|
||||
export function SubtitleField({ value, onChange }: { value: string; onChange: (v: string) => void }) {
|
||||
return (
|
||||
<div className="field" style={{ maxWidth: 420 }}>
|
||||
<label htmlFor="celeb-subtitle">Egy sor a név alatt (nem kötelező)</label>
|
||||
<input
|
||||
id="celeb-subtitle"
|
||||
className="inp"
|
||||
value={value}
|
||||
maxLength={160}
|
||||
placeholder="pl. színésznő, énekesnő"
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,399 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
|
||||
import { BirthForm } from "@/app/profil/BirthForm";
|
||||
import { AnalysisView } from "@/components/AnalysisView";
|
||||
import { RegenerateButton } from "@/components/RegenerateButton";
|
||||
import { ApiError, api, errorText } from "@/lib/api";
|
||||
import { signName } from "@/lib/astro";
|
||||
import { objectPosition, photoSrc } from "@/lib/celebrityPhoto";
|
||||
import type { AdminCelebrity, Analysis } from "@/lib/types";
|
||||
|
||||
import { ANALYSIS_STATUS, SubtitleField } from "../AdminCelebrities";
|
||||
|
||||
const POLL_MS = 10_000;
|
||||
|
||||
/** Everything about one famous person: photo and face point, texts, publishing, portrait, birth data. */
|
||||
export function CelebrityEditor({ id }: { id: string }) {
|
||||
const router = useRouter();
|
||||
const [c, setC] = useState<AdminCelebrity | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const url = `/admin/celebrities/${id}`;
|
||||
|
||||
const load = useCallback(async () => {
|
||||
try {
|
||||
setC(await api<AdminCelebrity>(url));
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
}
|
||||
}, [url]);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
// A portrait being written: look again now and then.
|
||||
const writing = c?.analysis?.status === "pending" || c?.analysis?.status === "running";
|
||||
useEffect(() => {
|
||||
if (!writing) return;
|
||||
const t = setInterval(load, POLL_MS);
|
||||
return () => clearInterval(t);
|
||||
}, [writing, load]);
|
||||
|
||||
if (!c) {
|
||||
return error ? (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
) : (
|
||||
<p className="muted">Betöltés…</p>
|
||||
);
|
||||
}
|
||||
|
||||
async function patch(body: object) {
|
||||
setError(null);
|
||||
try {
|
||||
setC(await api<AdminCelebrity>(url, { method: "PATCH", body }));
|
||||
return true;
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function remove() {
|
||||
if (!c || !window.confirm(`Biztosan törlöd: ${c.name}? A képlet, a portré és a fotó is törlődik.`)) return;
|
||||
try {
|
||||
await api(url, { method: "DELETE" });
|
||||
router.push("/admin/hires-emberek");
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="field" style={{ gap: 20 }}>
|
||||
<div className="page-head">
|
||||
<span className="eyebrow">
|
||||
<Link href="/admin/hires-emberek">Híres emberek</Link>
|
||||
</span>
|
||||
<h1>{c.name}</h1>
|
||||
<p className="muted">
|
||||
{c.birth.date}
|
||||
{c.birth.time ? ` ${c.birth.time}` : " (idő nélkül)"}
|
||||
{c.birth.place ? `, ${c.birth.place}` : ""} ·{" "}
|
||||
{[c.highlights.sun, c.highlights.moon, c.highlights.time_known ? c.highlights.ascendant : null]
|
||||
.filter(Boolean)
|
||||
.map((s) => signName(s as string))
|
||||
.join(" · ")}
|
||||
</p>
|
||||
<div className="form-actions">
|
||||
<button type="button" className="btn btn-primary" onClick={() => patch({ published: !c.published })}>
|
||||
{c.published ? "Visszavonás vázlatba" : "Közzététel"}
|
||||
</button>
|
||||
<Link href={`/hires-emberek/${c.slug}`} className="btn btn-ghost" target="_blank">
|
||||
{c.published ? "Nyilvános oldal" : "Előnézet"}
|
||||
</Link>
|
||||
<span className={c.published ? "promo-open" : "muted"}>{c.published ? "közzétéve" : "vázlat"}</span>
|
||||
</div>
|
||||
</div>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<PhotoSection c={c} url={url} onChange={setC} onFocus={(x, y) => patch({ focus_x: x, focus_y: y })} />
|
||||
<TextsSection key={c.updated_at} c={c} onSave={patch} />
|
||||
<AnalysisSection c={c} url={url} onChange={setC} onAnalysis={(a) => setC({ ...c, analysis: a })} />
|
||||
|
||||
<section className="card field" style={{ gap: 14 }}>
|
||||
<h2>Születési adatok</h2>
|
||||
<p className="hint">
|
||||
Ha a javítás után más lesz a képlet, a portré törlődik, és újra elkészül az új képletből.
|
||||
</p>
|
||||
<BirthForm
|
||||
key={JSON.stringify(c.birth_data)}
|
||||
initial={{ ...c.birth_data, placeName: c.birth.place, region: c.birth.region }}
|
||||
person={{ chartId: c.id, name: c.name }}
|
||||
save={async (name, birth) => {
|
||||
const next = await api<AdminCelebrity>(url, { method: "PATCH", body: birth ? { name, birth } : { name } });
|
||||
setC(next);
|
||||
return next;
|
||||
}}
|
||||
onSaved={() => undefined}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section className="card field" style={{ gap: 10 }}>
|
||||
<h2>Törlés</h2>
|
||||
<p className="hint">A képlet, a portré és a fotó is törlődik; a nyilvános oldal megszűnik.</p>
|
||||
<div className="form-actions">
|
||||
<button type="button" className="btn btn-ghost" onClick={remove}>
|
||||
{c.name} törlése
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Upload, the face point (a click on the photo) and how the crops will look. */
|
||||
function PhotoSection({
|
||||
c,
|
||||
url,
|
||||
onChange,
|
||||
onFocus,
|
||||
}: {
|
||||
c: AdminCelebrity;
|
||||
url: string;
|
||||
onChange: (c: AdminCelebrity) => void;
|
||||
onFocus: (x: number, y: number) => void;
|
||||
}) {
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const input = useRef<HTMLInputElement>(null);
|
||||
const photo = c.photo;
|
||||
|
||||
async function upload(file: File) {
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
// The image itself is the body (the backend makes the stored JPEG).
|
||||
const res = await fetch(`/api/v1${url}/photo`, {
|
||||
method: "PUT",
|
||||
headers: { "content-type": file.type || "application/octet-stream" },
|
||||
body: file,
|
||||
credentials: "same-origin",
|
||||
});
|
||||
const data = await res.json().catch(() => null);
|
||||
if (!res.ok) {
|
||||
const err = data?.error ?? {};
|
||||
throw new ApiError(res.status, err.code ?? "error", err.message ?? `HTTP ${res.status}`);
|
||||
}
|
||||
onChange(data as AdminCelebrity);
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
if (input.current) input.current.value = "";
|
||||
}
|
||||
}
|
||||
|
||||
async function removePhoto() {
|
||||
if (!window.confirm("Törlöd a fotót?")) return;
|
||||
try {
|
||||
onChange(await api<AdminCelebrity>(`${url}/photo`, { method: "DELETE" }));
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
}
|
||||
}
|
||||
|
||||
function pick(e: React.MouseEvent<HTMLButtonElement>) {
|
||||
const r = e.currentTarget.getBoundingClientRect();
|
||||
const x = Math.min(1, Math.max(0, (e.clientX - r.left) / r.width));
|
||||
const y = Math.min(1, Math.max(0, (e.clientY - r.top) / r.height));
|
||||
onFocus(Math.round(x * 1000) / 1000, Math.round(y * 1000) / 1000);
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="card field" style={{ gap: 14 }}>
|
||||
<h2>Fotó</h2>
|
||||
<p className="hint">
|
||||
Egy fotó kell (JPEG, PNG vagy WebP, legfeljebb 15 MB). Feltöltés után kattints az arcra: minden kivágás
|
||||
(megosztási kép, oldal, lista) e pont köré igazodik.
|
||||
</p>
|
||||
{photo && (
|
||||
<div className="celeb-editor-photo">
|
||||
<button type="button" className="celeb-focus" onClick={pick} aria-label="Az arc helye: kattints az arcra">
|
||||
{/* The stored original, for clicking: no optimizer needed here. */}
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={photoSrc(photo)} alt={c.name} width={photo.width} height={photo.height} />
|
||||
<span
|
||||
className="celeb-focus-mark"
|
||||
style={{ left: `${photo.focus_x * 100}%`, top: `${photo.focus_y * 100}%` }}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</button>
|
||||
<div className="celeb-crops" aria-label="Kivágások">
|
||||
<figure>
|
||||
<span className="celeb-crop" style={{ aspectRatio: "440 / 630" }}>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={photoSrc(photo)} alt="" style={{ objectPosition: objectPosition(photo) }} />
|
||||
</span>
|
||||
<figcaption className="hint">Megosztási kép</figcaption>
|
||||
</figure>
|
||||
<figure>
|
||||
<span className="celeb-crop" style={{ aspectRatio: "4 / 5" }}>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={photoSrc(photo)} alt="" style={{ objectPosition: objectPosition(photo) }} />
|
||||
</span>
|
||||
<figcaption className="hint">Oldal</figcaption>
|
||||
</figure>
|
||||
<figure>
|
||||
<span className="celeb-crop" style={{ aspectRatio: "1 / 1" }}>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={photoSrc(photo)} alt="" style={{ objectPosition: objectPosition(photo) }} />
|
||||
</span>
|
||||
<figcaption className="hint">Lista</figcaption>
|
||||
</figure>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<div className="form-actions">
|
||||
<input
|
||||
ref={input}
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
className="sr-only"
|
||||
id="celeb-photo-input"
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) upload(file);
|
||||
}}
|
||||
/>
|
||||
<label htmlFor="celeb-photo-input" className="btn" aria-disabled={busy}>
|
||||
{busy ? "Feltöltés…" : photo ? "Másik fotó" : "Fotó feltöltése"}
|
||||
</label>
|
||||
{photo && (
|
||||
<button type="button" className="btn btn-ghost" onClick={removePhoto} disabled={busy}>
|
||||
Fotó törlése
|
||||
</button>
|
||||
)}
|
||||
<Link href={`/hires-emberek/${c.slug}/kep/elonezet.png`} target="_blank" className="btn btn-ghost">
|
||||
Megosztási kép megnyitása
|
||||
</Link>
|
||||
</div>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
/** Name, the line under it and the address of the page. */
|
||||
function TextsSection({ c, onSave }: { c: AdminCelebrity; onSave: (body: object) => Promise<boolean> }) {
|
||||
const [name, setName] = useState(c.name);
|
||||
const [subtitle, setSubtitle] = useState(c.subtitle ?? "");
|
||||
const [slug, setSlug] = useState(c.slug);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [saved, setSaved] = useState(false);
|
||||
const changed = name.trim() !== c.name || subtitle.trim() !== (c.subtitle ?? "") || slug.trim() !== c.slug;
|
||||
|
||||
async function save(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
setBusy(true);
|
||||
setSaved(await onSave({ name: name.trim(), subtitle: subtitle.trim() || null, slug: slug.trim() }));
|
||||
setBusy(false);
|
||||
}
|
||||
|
||||
return (
|
||||
<form className="card field" style={{ gap: 14 }} onSubmit={save}>
|
||||
<h2>Név és cím</h2>
|
||||
<div className="grid-2">
|
||||
<div className="field">
|
||||
<label htmlFor="celeb-name">Név</label>
|
||||
<input id="celeb-name" className="inp" value={name} maxLength={100} required onChange={(e) => setName(e.target.value)} />
|
||||
</div>
|
||||
<SubtitleField value={subtitle} onChange={setSubtitle} />
|
||||
</div>
|
||||
<div className="field" style={{ maxWidth: 520 }}>
|
||||
<label htmlFor="celeb-slug">Az oldal címe</label>
|
||||
<input
|
||||
id="celeb-slug"
|
||||
className="inp"
|
||||
value={slug}
|
||||
maxLength={80}
|
||||
pattern="[a-z0-9]+(-[a-z0-9]+)*"
|
||||
title="Csak kisbetű, szám és kötőjel (pl. marilyn-monroe)."
|
||||
onChange={(e) => setSlug(e.target.value)}
|
||||
/>
|
||||
<span className="hint">sorsfonalak.hu/hires-emberek/{slug || "…"}</span>
|
||||
</div>
|
||||
<p className="hint">
|
||||
A név a portré szövegében is szerepel: ha jelentősen javítod, a portrét érdemes újragenerálni.
|
||||
</p>
|
||||
<div className="form-actions">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || !changed}>
|
||||
{busy ? "Mentés…" : "Mentés"}
|
||||
</button>
|
||||
{saved && !changed && <span className="msg msg-ok">Elmentve.</span>}
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
/** The portrait: its state, the text, writing it again. */
|
||||
function AnalysisSection({
|
||||
c,
|
||||
url,
|
||||
onChange,
|
||||
onAnalysis,
|
||||
}: {
|
||||
c: AdminCelebrity;
|
||||
url: string;
|
||||
onChange: (c: AdminCelebrity) => void;
|
||||
onAnalysis: (a: Analysis) => void;
|
||||
}) {
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [open, setOpen] = useState(false);
|
||||
const a = c.analysis;
|
||||
|
||||
async function start() {
|
||||
setError(null);
|
||||
try {
|
||||
onChange(await api<AdminCelebrity>(`${url}/analysis`, { method: "POST" }));
|
||||
} catch (e) {
|
||||
setError(errorText(e));
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="card field" style={{ gap: 14 }}>
|
||||
<h2>Részletes portré</h2>
|
||||
<p className="hint">
|
||||
Saját prompttal készül (Promptok → <Link href="/admin/promptok">Híres ember</Link>), harmadik személyben, csak a
|
||||
képletből; elemzést nem használ fel.
|
||||
</p>
|
||||
{!a ? (
|
||||
<p className="muted">Még nincs portré.</p>
|
||||
) : (
|
||||
<p>
|
||||
Állapot: <strong>{ANALYSIS_STATUS[a.status] ?? a.status}</strong>
|
||||
{a.status === "failed" && a.error && <span className="hint"> ({a.error})</span>}
|
||||
{(a.status === "pending" || a.status === "running") && (a.attempts ?? 0) > 1 && (
|
||||
<span className="hint"> · {a.attempts}. próbálkozás</span>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
<div className="form-actions">
|
||||
{(!a || a.status === "failed") && (
|
||||
<button type="button" className="btn btn-primary" onClick={start}>
|
||||
Portré írása
|
||||
</button>
|
||||
)}
|
||||
{a?.status === "done" && (
|
||||
<>
|
||||
<button type="button" className="btn btn-ghost" onClick={() => setOpen((o) => !o)}>
|
||||
{open ? "Szöveg elrejtése" : "Szöveg megnézése"}
|
||||
</button>
|
||||
<RegenerateButton<Analysis> url={`/admin/analyses/${a.id}/regenerate`} onStarted={onAnalysis} />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
{error && (
|
||||
<p className="msg msg-error" role="alert">
|
||||
{error}
|
||||
</p>
|
||||
)}
|
||||
{open && a?.status === "done" && a.content && (
|
||||
<AnalysisView content={a.content} kind="celebrity" language={a.language} />
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { AdminNav } from "@/components/AdminNav";
|
||||
import { requireMe } from "@/lib/server";
|
||||
|
||||
import { CelebrityEditor } from "./CelebrityEditor";
|
||||
|
||||
export const metadata: Metadata = { title: "Híres ember" };
|
||||
|
||||
type Props = { params: Promise<{ id: string }> };
|
||||
|
||||
export default async function AdminCelebrityPage({ params }: Props) {
|
||||
const { id } = await params;
|
||||
const me = await requireMe(`/admin/hires-emberek/${id}`);
|
||||
if (!me.user.roles.includes("admin")) notFound();
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 1180 }}>
|
||||
<AdminNav current="/admin/hires-emberek" />
|
||||
<CelebrityEditor id={id} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { AdminNav } from "@/components/AdminNav";
|
||||
import { requireMe } from "@/lib/server";
|
||||
|
||||
import { AdminCelebrities } from "./AdminCelebrities";
|
||||
|
||||
export const metadata: Metadata = { title: "Híres emberek" };
|
||||
|
||||
export default async function AdminCelebritiesPage() {
|
||||
const me = await requireMe("/admin/hires-emberek");
|
||||
if (!me.user.roles.includes("admin")) notFound();
|
||||
return (
|
||||
<main className="page" style={{ maxWidth: 1180 }}>
|
||||
<AdminNav current="/admin/hires-emberek" />
|
||||
<div className="page-head">
|
||||
<h1>Híres emberek</h1>
|
||||
<p className="muted">
|
||||
Születési adat, egy fotó és egy részletes portré (saját prompt: Promptok → Híres ember). Közzététel után a
|
||||
nyilvános oldalon (sorsfonalak.hu/hires-emberek) és a keresőkben is megjelenik; megosztáskor az előnézeti
|
||||
képen az arc és a képlet látszik.
|
||||
</p>
|
||||
</div>
|
||||
<AdminCelebrities />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ const KINDS: Record<AdminJob["kind"], string> = {
|
||||
natal: "Képletelemzés",
|
||||
synastry: "Kapcsolati elemzés",
|
||||
forecast: "Éves előrejelzés",
|
||||
celebrity: "Híres ember",
|
||||
question: "Kérdés-válasz",
|
||||
};
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { useEffect, useState } from "react";
|
||||
import { Tabs } from "@/components/Tabs";
|
||||
import { api, errorText } from "@/lib/api";
|
||||
import { formatDate } from "@/lib/astro";
|
||||
import type { AdminPrompt, ChartListItem, PromptKind } from "@/lib/types";
|
||||
import type { AdminCelebrityRow, AdminPrompt, ChartListItem, PromptKind } from "@/lib/types";
|
||||
|
||||
import { PromptTrial } from "./PromptTrial";
|
||||
|
||||
@@ -35,6 +35,13 @@ const KINDS: { kind: PromptKind; id: string; label: string; about: string }[] =
|
||||
about:
|
||||
"Fizetős elemzés egy születésnaptól a következőig: szolár, lassú tranzitok, progresszió, profekció, fogyatkozások. Öt fejezet, lehetőségek, kihívások és útravaló. Kérésre készül.",
|
||||
},
|
||||
{
|
||||
kind: "celebrity",
|
||||
id: "hires-ember",
|
||||
label: "Híres ember",
|
||||
about:
|
||||
"A híres emberek nyilvános oldalának részletes portréja: ugyanaz a hat fejezet, mint a részletes elemzésé, de harmadik személyben, a nevén nevezve, csak a képletből (az életrajzát nem használja). A modell a nevet és a képlet adatait kapja. Az admin oldalon készül (Híres emberek).",
|
||||
},
|
||||
{
|
||||
kind: "question",
|
||||
id: "kerdesek",
|
||||
@@ -49,6 +56,8 @@ const LANGUAGES: Record<string, string> = { hu: "Magyar", en: "Angol" };
|
||||
export function AdminPrompts() {
|
||||
const [prompts, setPrompts] = useState<AdminPrompt[] | null>(null);
|
||||
const [charts, setCharts] = useState<ChartListItem[]>([]);
|
||||
// The famous people's charts, for trying their prompt.
|
||||
const [famous, setFamous] = useState<ChartListItem[]>([]);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -58,6 +67,22 @@ export function AdminPrompts() {
|
||||
api<{ charts: ChartListItem[] }>("/charts")
|
||||
.then((d) => setCharts(d.charts))
|
||||
.catch(() => setCharts([]));
|
||||
api<{ celebrities: AdminCelebrityRow[] }>("/admin/celebrities")
|
||||
.then((d) =>
|
||||
setFamous(
|
||||
d.celebrities.map((c) => ({
|
||||
id: c.chart_id,
|
||||
label: c.name,
|
||||
is_primary: false,
|
||||
kind: "person",
|
||||
editable_until: null,
|
||||
birth: { date: c.birth.date, time: c.birth.time, place: c.birth.place },
|
||||
highlights: c.highlights,
|
||||
created_at: "",
|
||||
})),
|
||||
),
|
||||
)
|
||||
.catch(() => setFamous([]));
|
||||
}, []);
|
||||
|
||||
if (error) {
|
||||
@@ -83,7 +108,7 @@ export function AdminPrompts() {
|
||||
<KindPrompts
|
||||
about={k.about}
|
||||
prompts={prompts.filter((p) => p.kind === k.kind)}
|
||||
charts={charts}
|
||||
charts={k.kind === "celebrity" ? famous : charts}
|
||||
onSaved={replace}
|
||||
/>
|
||||
),
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { revalidateTag } from "next/cache";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
import { CELEBRITIES_TAG } from "@/lib/celebrities";
|
||||
import { BACKEND_URL } from "@/lib/server";
|
||||
import { SHARES_TAG } from "@/lib/share";
|
||||
|
||||
@@ -53,6 +54,10 @@ async function forward(req: NextRequest, ctx: { params: Promise<{ path: string[]
|
||||
for (const cookie of res.headers.getSetCookie()) out.append("set-cookie", cookie);
|
||||
// A revoked link must disappear at once from the cached share pages.
|
||||
if (req.method === "DELETE" && path[0] === "shares" && res.ok) revalidateTag(SHARES_TAG, { expire: 0 });
|
||||
// An admin's change to a famous person shows on the public pages at once.
|
||||
if (req.method !== "GET" && path[0] === "admin" && path[1] === "celebrities" && res.ok) {
|
||||
revalidateTag(CELEBRITIES_TAG, { expire: 0 });
|
||||
}
|
||||
return new Response(res.body, { status: res.status, headers: out });
|
||||
}
|
||||
|
||||
|
||||
@@ -1221,3 +1221,31 @@ span.tarot-fan-card { cursor: default; }
|
||||
.calc-links li { font-size: 15px; }
|
||||
.calc-save { display: flex; flex-direction: column; gap: 10px; }
|
||||
.calc-save .btn { align-self: flex-start; }
|
||||
|
||||
/* Famous people: the public list and page, and the admin editor. */
|
||||
.msg-warn { color: var(--gold); border: 1px solid rgba(217, 180, 106, 0.45); border-radius: 10px; padding: 10px 14px; }
|
||||
.celeb-subtitle { margin: -6px 0 0; font-size: 18px; color: var(--ink-2); }
|
||||
.celeb-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: 16px; }
|
||||
.celeb-tile { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--ink); height: 100%; padding: 14px; }
|
||||
.celeb-tile:hover { border-color: #5a6790; color: var(--ink); }
|
||||
.celeb-tile strong { font-family: var(--font-display); font-size: 24px; font-weight: 600; line-height: 1.15; margin-top: 6px; }
|
||||
.celeb-tile-photo { position: relative; display: flex; align-items: center; justify-content: center; aspect-ratio: 1 / 1; border-radius: 10px; overflow: hidden; background: #141b2e; }
|
||||
.celeb-tile-glyph { font-size: 64px; color: var(--gold); }
|
||||
.celeb-portrait { gap: 14px; }
|
||||
.celeb-photo { position: relative; aspect-ratio: 4 / 5; width: 100%; border-radius: 10px; overflow: hidden; background: #141b2e; }
|
||||
.celeb-editor-photo { display: grid; grid-template-columns: minmax(0, 380px) minmax(0, 1fr); gap: 20px; align-items: start; }
|
||||
.celeb-focus { position: relative; display: block; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; cursor: crosshair; background: none; line-height: 0; }
|
||||
.celeb-focus img { width: 100%; height: auto; display: block; }
|
||||
.celeb-focus-mark { position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px; border: 2px solid var(--gold); border-radius: 50%; box-shadow: 0 0 0 2px rgba(13, 18, 32, 0.7); pointer-events: none; }
|
||||
.celeb-crops { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: end; }
|
||||
.celeb-crops figure { margin: 0; display: flex; flex-direction: column; gap: 6px; }
|
||||
.celeb-crop { position: relative; display: block; width: 100%; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
|
||||
.celeb-crop img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
|
||||
@media (max-width: 760px) {
|
||||
.celeb-editor-photo { grid-template-columns: 1fr; }
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
.celeb-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
|
||||
.celeb-tile { padding: 10px; }
|
||||
.celeb-tile strong { font-size: 19px; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// The link preview image of a famous person (og:image): the photo with the
|
||||
// face in view, the name and the chart. The file name carries a version (see
|
||||
// `celebrityImageVersion`), so a new photo or face point gets a new address.
|
||||
import { SIGNS, signName } from "@/lib/astro";
|
||||
import { loadCelebrity } from "@/lib/celebrities";
|
||||
import { celebrityCard } from "@/lib/ogCard";
|
||||
import { BACKEND_URL } from "@/lib/server";
|
||||
import { bigThree } from "@/lib/share";
|
||||
|
||||
export async function GET(_req: Request, { params }: { params: Promise<{ slug: string; file: string }> }) {
|
||||
const { slug } = await params;
|
||||
const c = await loadCelebrity(slug);
|
||||
if (!c) return new Response("Not found", { status: 404 });
|
||||
let photo = null;
|
||||
if (c.photo) {
|
||||
const res = await fetch(`${BACKEND_URL}/v1/public/photos/${c.photo.key}`, { cache: "no-store" });
|
||||
if (res.ok) photo = { ...c.photo, data: await res.arrayBuffer() };
|
||||
}
|
||||
return celebrityCard({
|
||||
chart: c.chart,
|
||||
timeKnown: c.chart.time_known,
|
||||
name: c.name,
|
||||
subtitle: c.subtitle,
|
||||
lines: bigThree(c.chart).map((t) => ({ glyph: SIGNS[t.sign]?.glyph ?? "", label: `${t.label} ${signName(t.sign)}` })),
|
||||
photo,
|
||||
// A draft's image is not kept anywhere.
|
||||
cacheControl: c.published ? "public, max-age=3600, s-maxage=86400" : "private, no-store",
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
import type { Metadata } from "next";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
import { AnalysisView } from "@/components/AnalysisView";
|
||||
import { ChartWheel, WheelLegend } from "@/components/ChartWheel";
|
||||
import { JsonLd, PublicFooter } from "@/components/PublicFooter";
|
||||
import { PublicHeader } from "@/components/SiteHeader";
|
||||
import { SIGNS, signName } from "@/lib/astro";
|
||||
import { birthLine, celebrityImageVersion, loadCelebrity } from "@/lib/celebrities";
|
||||
import { objectPosition, photoSrc } from "@/lib/celebrityPhoto";
|
||||
import { getMe } from "@/lib/server";
|
||||
import { bigThree, plain, shorten, siteUrl } from "@/lib/share";
|
||||
|
||||
type Props = { params: Promise<{ slug: string }> };
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const c = await loadCelebrity(slug);
|
||||
if (!c) return { title: "Nem található", robots: { index: false } };
|
||||
const base = await siteUrl();
|
||||
const title = `${c.name} horoszkópja`;
|
||||
const summary = c.analysis?.content.summary;
|
||||
const description = summary
|
||||
? shorten(plain(summary), 200)
|
||||
: `${c.name} születési képlete: ${birthLine(c.chart.birth)}.`;
|
||||
const url = `${base}/hires-emberek/${c.slug}`;
|
||||
const image = { url: `${url}/kep/${celebrityImageVersion(c)}.png`, width: 1200, height: 630, alt: title };
|
||||
return {
|
||||
title,
|
||||
description,
|
||||
// A draft (only admins see it) stays out of search engines.
|
||||
robots: c.published ? undefined : { index: false, follow: false },
|
||||
alternates: { canonical: url },
|
||||
openGraph: { type: "article", siteName: "Sorsfonalak", locale: "hu_HU", url, title, description, images: [image] },
|
||||
twitter: { card: "summary_large_image", title, description, images: [image.url] },
|
||||
};
|
||||
}
|
||||
|
||||
/** A famous person: photo, birth data, chart and the detailed portrait. */
|
||||
export default async function CelebrityPage({ params }: Props) {
|
||||
const { slug } = await params;
|
||||
const [c, me] = await Promise.all([loadCelebrity(slug), getMe()]);
|
||||
if (!c) notFound();
|
||||
const chart = c.chart;
|
||||
const trio = bigThree(chart);
|
||||
const base = await siteUrl();
|
||||
|
||||
return (
|
||||
<>
|
||||
<JsonLd
|
||||
data={{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Person",
|
||||
name: c.name,
|
||||
birthDate: chart.birth.date,
|
||||
...(chart.birth.place ? { birthPlace: { "@type": "Place", name: chart.birth.place } } : {}),
|
||||
...(c.photo ? { image: `${base}${photoSrc(c.photo)}` } : {}),
|
||||
url: `${base}/hires-emberek/${c.slug}`,
|
||||
}}
|
||||
/>
|
||||
{!me && <PublicHeader />}
|
||||
<main className="page" style={{ maxWidth: 1180 }}>
|
||||
{!c.published && (
|
||||
<p className="msg msg-warn" role="status">
|
||||
Vázlat: csak az adminok látják. <Link href={`/admin/hires-emberek/${c.id}`}>Szerkesztés</Link>
|
||||
</p>
|
||||
)}
|
||||
<div className="page-head">
|
||||
<span className="eyebrow">
|
||||
<Link href="/hires-emberek">Híres emberek</Link>
|
||||
</span>
|
||||
<h1>{c.name} horoszkópja</h1>
|
||||
{c.subtitle && <p className="celeb-subtitle">{c.subtitle}</p>}
|
||||
<p className="muted">Született: {birthLine(chart.birth)}</p>
|
||||
</div>
|
||||
|
||||
<section className="chart-layout" aria-label={`${c.name} képlete`}>
|
||||
<div className="card chart-wheel-card">
|
||||
<ChartWheel chart={chart} timeKnown={chart.time_known} />
|
||||
<WheelLegend />
|
||||
</div>
|
||||
<div className="field chart-side">
|
||||
<section className="card celeb-portrait" aria-label={c.name}>
|
||||
{c.photo && (
|
||||
<div className="celeb-photo">
|
||||
<Image
|
||||
src={photoSrc(c.photo)}
|
||||
alt={c.name}
|
||||
fill
|
||||
priority
|
||||
sizes="(max-width: 900px) 100vw, 420px"
|
||||
style={{ objectFit: "cover", objectPosition: objectPosition(c.photo) }}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{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" : "/szuletesi-horoszkop"} className="btn btn-primary">
|
||||
{me ? "A saját képletem" : "Ingyenes születési horoszkóp"}
|
||||
</Link>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{c.analysis ? (
|
||||
<section className="card analysis-card" aria-label={`${c.name} részletes portréja`}>
|
||||
<span className="eyebrow">Asztrológiai portré</span>
|
||||
<AnalysisView content={c.analysis.content} kind="celebrity" language={c.analysis.language} />
|
||||
</section>
|
||||
) : (
|
||||
<p className="muted">A részletes portré hamarosan elkészül.</p>
|
||||
)}
|
||||
<p className="hint">
|
||||
A portrét mesterséges intelligencia írta, kizárólag a születési képlet alapján, nem az életrajz ismeretében.
|
||||
</p>
|
||||
</main>
|
||||
<PublicFooter />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import type { Metadata } from "next";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
|
||||
import { PublicFooter } from "@/components/PublicFooter";
|
||||
import { PublicHeader } from "@/components/SiteHeader";
|
||||
import { SIGNS, signName } from "@/lib/astro";
|
||||
import { loadCelebrities } from "@/lib/celebrities";
|
||||
import { objectPosition, photoSrc } from "@/lib/celebrityPhoto";
|
||||
import { getMe } from "@/lib/server";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Híres emberek horoszkópja",
|
||||
description:
|
||||
"Híres emberek születési képlete és részletes asztrológiai portréja: Nap, Hold, Aszcendens és a képlet teljes értelmezése.",
|
||||
alternates: { canonical: "/hires-emberek" },
|
||||
};
|
||||
|
||||
/** The published famous people. */
|
||||
export default async function CelebritiesPage() {
|
||||
const [people, me] = await Promise.all([loadCelebrities(), getMe()]);
|
||||
return (
|
||||
<>
|
||||
{!me && <PublicHeader />}
|
||||
<main className="page" style={{ maxWidth: 1080 }}>
|
||||
<div className="page-head">
|
||||
<span className="eyebrow">Híres emberek</span>
|
||||
<h1>Híres emberek horoszkópja</h1>
|
||||
<p className="muted">
|
||||
Ismert emberek születési képlete és részletes portréja. A szöveg csak a képletből dolgozik, nem az
|
||||
életrajzukból: azt mutatja meg, mit árul el róluk a születésük pillanatának égboltja.
|
||||
</p>
|
||||
</div>
|
||||
{people.length === 0 ? (
|
||||
<p className="muted">Hamarosan.</p>
|
||||
) : (
|
||||
<ul className="celeb-grid">
|
||||
{people.map((p) => (
|
||||
<li key={p.id}>
|
||||
<Link href={`/hires-emberek/${p.slug}`} className="card celeb-tile">
|
||||
<span className="celeb-tile-photo">
|
||||
{p.photo ? (
|
||||
<Image
|
||||
src={photoSrc(p.photo)}
|
||||
alt={p.name}
|
||||
fill
|
||||
sizes="(max-width: 640px) 50vw, 240px"
|
||||
style={{ objectFit: "cover", objectPosition: objectPosition(p.photo) }}
|
||||
/>
|
||||
) : (
|
||||
<span className="celeb-tile-glyph" aria-hidden="true">
|
||||
{p.highlights.sun ? SIGNS[p.highlights.sun]?.glyph : "✶"}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<strong>{p.name}</strong>
|
||||
{p.subtitle && <span className="hint">{p.subtitle}</span>}
|
||||
<span className="hint">
|
||||
{[
|
||||
p.highlights.sun && `Nap ${signName(p.highlights.sun)}`,
|
||||
p.highlights.moon && `Hold ${signName(p.highlights.moon)}`,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" · ")}
|
||||
</span>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<div className="card sign-cta" style={{ marginTop: 32 }}>
|
||||
<p style={{ margin: 0 }}>
|
||||
Kíváncsi vagy a saját képletedre? Az ingyenes születési horoszkóp a születési adataidból kiszámolja, belépés
|
||||
nélkül.
|
||||
</p>
|
||||
<div className="form-actions">
|
||||
<Link href="/szuletesi-horoszkop" className="btn btn-primary">
|
||||
Ingyenes születési horoszkóp
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<PublicFooter />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -20,15 +20,33 @@ const ERRORS: Record<string, string> = {
|
||||
/** Someone else's chart: added with a name, or (with `chartId`) corrected. */
|
||||
export type PersonTarget = { chartId?: string; name?: string };
|
||||
|
||||
/** The birth data the form sends (as `POST /v1/charts` takes it). */
|
||||
export type BirthInput = {
|
||||
date: string;
|
||||
time?: string;
|
||||
country: string;
|
||||
geonames_id: number;
|
||||
ambiguous_time?: Ambiguity;
|
||||
};
|
||||
|
||||
export function BirthForm({
|
||||
initial,
|
||||
person,
|
||||
save,
|
||||
children,
|
||||
onCancel,
|
||||
onSaved,
|
||||
}: {
|
||||
initial: Initial;
|
||||
/** Not given: the user's own birth data. */
|
||||
person?: PersonTarget;
|
||||
/**
|
||||
* Saves somewhere else than the user's charts (e.g. a famous person); gets
|
||||
* the birth data only when it changed. Its errors show in the form.
|
||||
*/
|
||||
save?: (name: string, birth: BirthInput | null) => Promise<{ id: string }>;
|
||||
/** More fields, after the name. */
|
||||
children?: React.ReactNode;
|
||||
onCancel?: () => void;
|
||||
onSaved: (chartId: string) => void;
|
||||
}) {
|
||||
@@ -105,7 +123,7 @@ export function BirthForm({
|
||||
if (!place) return setError("Válaszd ki a születési helyet a listából.");
|
||||
setBusy(true);
|
||||
try {
|
||||
const birth = {
|
||||
const birth: BirthInput = {
|
||||
date,
|
||||
...(timeUnknown ? {} : { time }),
|
||||
country,
|
||||
@@ -121,7 +139,9 @@ export function BirthForm({
|
||||
(timeUnknown ? null : time) !== (initial.time?.slice(0, 5) ?? null) ||
|
||||
country !== (initial.country ?? "HU") ||
|
||||
place.geonames_id !== initial.geonames_id;
|
||||
const saved = person?.chartId
|
||||
const saved = save
|
||||
? await save(name.trim(), birthChanged ? birth : null)
|
||||
: person?.chartId
|
||||
? await api<{ id: string }>(`/charts/${person.chartId}`, {
|
||||
method: "PATCH",
|
||||
body: birthChanged ? { label: name.trim(), birth } : { label: name.trim() },
|
||||
@@ -172,6 +192,7 @@ export function BirthForm({
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{children}
|
||||
<div className="grid-2">
|
||||
<fieldset className="field birth-fields">
|
||||
<legend className="label">Születési dátum</legend>
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import type { MetadataRoute } from "next";
|
||||
|
||||
import { ZODIAC } from "@/content/zodiac";
|
||||
import { loadCelebrities } from "@/lib/celebrities";
|
||||
import { siteUrl } from "@/lib/share";
|
||||
|
||||
/** The public pages for search engines; everything else needs a login. */
|
||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
const base = await siteUrl();
|
||||
const privacy = { languages: { hu: `${base}/adatvedelem`, en: `${base}/privacy` } };
|
||||
// The sitemap still works when the backend does not answer.
|
||||
const people = await loadCelebrities().catch(() => []);
|
||||
return [
|
||||
{ url: `${base}/`, changeFrequency: "weekly", priority: 1 },
|
||||
{ url: `${base}/pelda`, changeFrequency: "monthly", priority: 0.8 },
|
||||
@@ -14,6 +17,13 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
{ url: `${base}/szuletesi-horoszkop`, changeFrequency: "monthly", priority: 0.9 },
|
||||
{ url: `${base}/csillagjegyek`, changeFrequency: "monthly", priority: 0.8 },
|
||||
...ZODIAC.map((z) => ({ url: `${base}/csillagjegyek/${z.slug}`, changeFrequency: "monthly" as const, priority: 0.7 })),
|
||||
{ url: `${base}/hires-emberek`, changeFrequency: "weekly", priority: 0.7 },
|
||||
...people.map((p) => ({
|
||||
url: `${base}/hires-emberek/${p.slug}`,
|
||||
lastModified: p.updated_at,
|
||||
changeFrequency: "monthly" as const,
|
||||
priority: 0.6,
|
||||
})),
|
||||
{ url: `${base}/aszf`, changeFrequency: "yearly", priority: 0.2 },
|
||||
{ url: `${base}/adatvedelem`, changeFrequency: "yearly", priority: 0.2, alternates: privacy },
|
||||
{ url: `${base}/privacy`, changeFrequency: "yearly", priority: 0.2, alternates: privacy },
|
||||
|
||||
@@ -4,6 +4,7 @@ const PAGES = [
|
||||
{ href: "/admin", label: "Felhasználók" },
|
||||
{ href: "/admin/meghivok", label: "Meghívók" },
|
||||
{ href: "/admin/promokodok", label: "Promókódok" },
|
||||
{ href: "/admin/hires-emberek", label: "Híres emberek" },
|
||||
{ href: "/admin/promptok", label: "Promptok" },
|
||||
{ href: "/admin/modellek", label: "Modellek" },
|
||||
{ href: "/admin/hibak", label: "Hibanapló" },
|
||||
|
||||
@@ -5,16 +5,16 @@ import { Paragraphs, Rich } from "./Rich";
|
||||
const NATAL_ORDER = ["personality", "emotions", "mind", "love", "work", "growth"];
|
||||
const SYNASTRY_ORDER = ["attraction", "communication", "emotional_bond", "friction", "long_term"];
|
||||
const FORECAST_ORDER = ["theme", "love", "work", "growth", "timeline"];
|
||||
const ORDER = { natal: NATAL_ORDER, synastry: SYNASTRY_ORDER, forecast: FORECAST_ORDER };
|
||||
const ORDER = { natal: NATAL_ORDER, synastry: SYNASTRY_ORDER, forecast: FORECAST_ORDER, celebrity: NATAL_ORDER };
|
||||
|
||||
/** A finished detailed analysis (natal, synastry or yearly forecast). */
|
||||
/** A finished detailed analysis (natal, synastry, yearly forecast or a famous person's portrait). */
|
||||
export function AnalysisView({
|
||||
content,
|
||||
kind = "natal",
|
||||
language,
|
||||
}: {
|
||||
content: AnalysisContent;
|
||||
kind?: "natal" | "synastry" | "forecast";
|
||||
kind?: "natal" | "synastry" | "forecast" | "celebrity";
|
||||
/** The language of the text, for hyphenation. */
|
||||
language?: string;
|
||||
}) {
|
||||
@@ -64,7 +64,7 @@ export function AnalysisView({
|
||||
</div>
|
||||
{content.advice && (
|
||||
<section className="analysis-section analysis-advice">
|
||||
<h3>Útravaló</h3>
|
||||
<h3>{kind === "celebrity" ? "Összegzés" : "Útravaló"}</h3>
|
||||
<Paragraphs text={content.advice} />
|
||||
</section>
|
||||
)}
|
||||
|
||||
@@ -11,6 +11,7 @@ export function PublicFooter() {
|
||||
<nav aria-label="Lábléc" className="lp-footer-nav">
|
||||
<Link href="/szuletesi-horoszkop">Születési horoszkóp</Link>
|
||||
<Link href="/csillagjegyek">Csillagjegyek</Link>
|
||||
<Link href="/hires-emberek">Híres emberek</Link>
|
||||
<Link href="/pelda">Példaelemzés</Link>
|
||||
<Link href="/kartyajoslas/pelda">Példajóslás</Link>
|
||||
<Link href="/aszf">ÁSZF</Link>
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
}
|
||||
@@ -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 } },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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