Main #21

Merged
sagifer merged 2 commits from main into prod 2026-11-19 12:54:17 +01:00
11 changed files with 210 additions and 145 deletions
+4 -1
View File
@@ -5,7 +5,10 @@ const config: NextConfig = {
output: "standalone",
poweredByHeader: false,
// The fonts of the share preview images are read from disk at run time.
outputFileTracingIncludes: { "/s/[slug]/kep/[file]": ["./src/assets/og/*.ttf"] },
outputFileTracingIncludes: {
"/s/[slug]/kep/[file]": ["./src/assets/og/*.ttf"],
"/kep/fooldal.png": ["./src/assets/og/*.ttf"],
},
};
export default config;
+2 -13
View File
@@ -2,7 +2,7 @@ import Link from "next/link";
import { ChartWheel } from "@/components/ChartWheel";
import { Rich } from "@/components/Rich";
import { Logo } from "@/components/SiteHeader";
import { Logo, PublicHeader } from "@/components/SiteHeader";
import { Waitlist } from "@/components/Waitlist";
import example from "@/content/pelda.json";
import type { AnalysisContent, ChartResult } from "@/lib/types";
@@ -60,18 +60,7 @@ export function Landing({ inviteOnly }: { inviteOnly: boolean }) {
return (
<div className="lp">
<header className="site-header lp-header">
<Logo />
<nav className="nav lp-nav" aria-label="Fő navigáció">
<a href="#elemzes">Elemzés</a>
<a href="#elorejelzes">Előrejelzés</a>
<a href="#osszevetes">Összevetés</a>
<Link href="/pelda">Példa</Link>
</nav>
<Link href="/belepes" className="btn btn-sm">
Belépés
</Link>
</header>
<PublicHeader onHome />
<section className="lp-hero">
<svg className="lp-stars" aria-hidden="true" viewBox="0 0 1000 600" preserveAspectRatio="xMidYMid slice">
@@ -1,7 +1,7 @@
import type { Metadata } from "next";
import Link from "next/link";
import { Logo } from "@/components/SiteHeader";
import { PublicHeader } from "@/components/SiteHeader";
import { OPERATOR, PRIVACY_UPDATED } from "@/lib/legal";
import { getMe } from "@/lib/server";
@@ -16,9 +16,7 @@ export default async function PrivacyPage() {
return (
<>
{!me && (
<header className="site-header">
<Logo />
</header>
<PublicHeader />
)}
<main className="page legal">
<div className="page-head">
@@ -0,0 +1,22 @@
// The link preview image of the home page (og:image), drawn from the example
// chart. The page links it with a version (?v=…), so a new design is fetched
// again; until then it is kept long.
import example from "@/content/pelda.json";
import { chartCard } from "@/lib/ogCard";
import type { ChartResult } from "@/lib/types";
export async function GET() {
return chartCard({
chart: example.chart as unknown as ChartResult,
timeKnown: true,
eyebrow: "KÉPLET · ELŐREJELZÉS · KAPCSOLAT",
title: "Ahol a csillagok összekötnek.",
text: "Percre pontos születési képlet és személyre szóló elemzés. Mit hoz az éved, és mennyire illetek össze azzal, akit szeretsz?",
lines: [
{ glyph: "☉", label: "Képletelemzés" },
{ glyph: "♃", label: "Éves előrejelzés" },
{ glyph: "♀", label: "Kapcsolati összevetés" },
],
cacheControl: "public, max-age=86400, s-maxage=604800",
});
}
@@ -2,7 +2,7 @@ import type { Metadata } from "next";
import Link from "next/link";
import { GoogleLogin } from "@/app/belepes/GoogleLogin";
import { Logo } from "@/components/SiteHeader";
import { PublicHeader } from "@/components/SiteHeader";
import { formatDate } from "@/lib/astro";
import { BACKEND_URL, getMe } from "@/lib/server";
import type { PersonInviteLanding, PublicConfig } from "@/lib/types";
@@ -65,9 +65,7 @@ export default async function PersonInvitePage({ params }: { params: Promise<{ t
return (
<>
{!me && (
<header className="site-header">
<Logo />
</header>
<PublicHeader />
)}
<main className="page" style={{ maxWidth: 720 }}>
<div className="page-head">
+23 -12
View File
@@ -2,22 +2,33 @@ import type { Metadata } from "next";
import { redirect } from "next/navigation";
import { BACKEND_URL, getMe } from "@/lib/server";
import { siteUrl } from "@/lib/share";
import type { PublicConfig } from "@/lib/types";
import { Landing } from "./Landing";
export const metadata: Metadata = {
title: { absolute: "Sorsfonalak – születési képlet, éves előrejelzés, kapcsolati összevetés" },
description:
"Percre pontos születési képlet és személyre szóló elemzés, éves előrejelzés és kapcsolati összevetés: mennyire illetek össze?",
openGraph: {
type: "website",
siteName: "Sorsfonalak",
locale: "hu_HU",
title: "Sorsfonalak – ahol a csillagok összekötnek",
description: "Születési képlet, részletes elemzés, éves előrejelzés és kapcsolati összevetés.",
},
};
/** Bumped when the preview image changes, so Facebook and co. fetch it again. */
const PREVIEW_VERSION = 1;
export async function generateMetadata(): Promise<Metadata> {
const base = await siteUrl();
const title = "Sorsfonalak – ahol a csillagok összekötnek";
const description = "Születési képlet, részletes elemzés, éves előrejelzés és kapcsolati összevetés.";
const image = {
url: `${base}/kep/fooldal.png?v=${PREVIEW_VERSION}`,
width: 1200,
height: 630,
alt: "Egy példa születési képlet a Sorsfonalakon",
};
return {
title: { absolute: "Sorsfonalak – születési képlet, éves előrejelzés, kapcsolati összevetés" },
description:
"Percre pontos születési képlet és személyre szóló elemzés, éves előrejelzés és kapcsolati összevetés: mennyire illetek össze?",
alternates: { canonical: `${base}/` },
openGraph: { type: "website", siteName: "Sorsfonalak", locale: "hu_HU", url: `${base}/`, title, description, images: [image] },
twitter: { card: "summary_large_image", title, description, images: [image.url] },
};
}
async function signupMode(): Promise<PublicConfig["signup_mode"]> {
try {
+2 -4
View File
@@ -4,7 +4,7 @@ import Link from "next/link";
import { AnalysisView } from "@/components/AnalysisView";
import { ChartWheel, WheelLegend } from "@/components/ChartWheel";
import { Rich } from "@/components/Rich";
import { Logo } from "@/components/SiteHeader";
import { PublicHeader } from "@/components/SiteHeader";
import example from "@/content/pelda.json";
import { getMe } from "@/lib/server";
import type { AnalysisContent, ChartResult } from "@/lib/types";
@@ -21,9 +21,7 @@ export default async function ExamplePage() {
return (
<>
{!me && (
<header className="site-header">
<Logo />
</header>
<PublicHeader current="pelda" />
)}
<main className="page" style={{ maxWidth: 1180 }}>
<div className="page-head">
@@ -1,108 +1,27 @@
// The link preview image of a shared chart (og:image): 1200×630 PNG with the
// wheel, the title and the text of the short summary. The file name carries
// a version (see `imageVersion`), so a rewritten summary gets a new address
// and Facebook and co. fetch it again.
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { ImageResponse } from "next/og";
// The link preview image of a shared chart (og:image): the wheel, the title
// and the text of the short summary. The file name carries a version (see
// `imageVersion`), so a rewritten summary gets a new address and Facebook and
// co. fetch it again.
import { SIGNS, signName } from "@/lib/astro";
import { chartCard } from "@/lib/ogCard";
import { bigThree, loadShare, plain, shorten } from "@/lib/share";
import { wheelSvg } from "@/lib/wheelSvg";
const W = 1200;
const H = 630;
const WHEEL = 590;
const FONTS = join(process.cwd(), "src/assets/og");
let fonts: Promise<{ name: string; data: Buffer; weight: 400 | 600; style: "normal" }[]> | null = null;
function loadFonts() {
fonts ??= Promise.all(
(
[
["Cormorant Garamond", "CormorantGaramond-SemiBold.ttf", 600],
["Inter", "Inter-Regular.ttf", 400],
["Inter", "Inter-SemiBold.ttf", 600],
["DejaVu Sans", "DejaVuSans.ttf", 400],
] as const
).map(async ([name, file, weight]) => ({
name,
data: await readFile(join(FONTS, file)),
weight,
style: "normal" as const,
})),
);
return fonts;
}
// Letters, digits, punctuation and spaces only: a character missing from the
// fonts would make the renderer download a font from the internet.
const printable = (s: string) => s.replace(/[^\p{L}\p{N}\p{P}\p{Zs}+=<>°]/gu, "");
export async function GET(_req: Request, { params }: { params: Promise<{ slug: string; file: string }> }) {
const { slug } = await params;
const share = await loadShare(slug);
const chart = share?.chart?.chart;
if (!share || !chart) return new Response("Not found", { status: 404 });
const title = printable(share.summary?.title ?? "Születési képlet");
const text = printable(shorten(plain(share.summary?.summary ?? ""), 280));
const svg = wheelSvg(chart, chart.time_known, WHEEL);
const trio = bigThree(chart);
const image = new ImageResponse(
(
<div style={{ display: "flex", width: W, height: H, background: "#0d1220", color: "#ece6d8", fontFamily: "Inter" }}>
<div style={{ display: "flex", width: WHEEL + 40, height: H, alignItems: "center", justifyContent: "center" }}>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={`data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`}
width={WHEEL}
height={WHEEL}
alt=""
/>
</div>
<div
style={{
display: "flex",
flexDirection: "column",
flex: 1,
padding: "56px 56px 44px 8px",
gap: 18,
}}
>
<div style={{ display: "flex", fontSize: 17, fontWeight: 600, letterSpacing: 2.5, color: "#d9b46a" }}>
SZÜLETÉSI KÉPLET · RÖVIDEN
</div>
<div style={{ display: "flex", fontFamily: "Cormorant Garamond", fontSize: 56, lineHeight: 1.05 }}>{title}</div>
{text && <div style={{ display: "flex", fontSize: 23, lineHeight: 1.45, color: "#c9cfdc" }}>{text}</div>}
<div style={{ display: "flex", marginTop: "auto", gap: 22, fontSize: 21, color: "#c9cfdc" }}>
{trio.map((t) => (
<div key={t.label} style={{ display: "flex", alignItems: "center", gap: 8 }}>
<span style={{ fontFamily: "DejaVu Sans", color: "#d9b46a" }}>
{(SIGNS[t.sign]?.glyph ?? "").replace(/︎/g, "")}
</span>
<span>
{t.label === "Aszcendens" ? "Asc" : t.label} {signName(t.sign)}
</span>
</div>
))}
</div>
<div style={{ display: "flex", fontFamily: "Cormorant Garamond", fontSize: 30, color: "#ece6d8" }}>
sors<span style={{ color: "#d9b46a" }}>fonalak</span>
</div>
</div>
</div>
),
{
width: W,
height: H,
fonts: await loadFonts(),
// A day at the edge: a revoked link's image goes away from there too.
headers: { "Cache-Control": "public, max-age=3600, s-maxage=86400" },
},
);
return image;
return chartCard({
chart,
timeKnown: chart.time_known,
eyebrow: "SZÜLETÉSI KÉPLET · RÖVIDEN",
title: share.summary?.title ?? "Születési képlet",
text: shorten(plain(share.summary?.summary ?? ""), 280),
lines: bigThree(chart).map((t) => ({
glyph: SIGNS[t.sign]?.glyph ?? "",
label: `${t.label === "Aszcendens" ? "Asc" : t.label} ${signName(t.sign)}`,
})),
// A day at the edge: a revoked link's image goes away from there too.
cacheControl: "public, max-age=3600, s-maxage=86400",
});
}
+2 -8
View File
@@ -5,7 +5,7 @@ import { notFound } from "next/navigation";
import { ChartWheel, WheelLegend } from "@/components/ChartWheel";
import { Rich } from "@/components/Rich";
import { ShareVisit } from "@/components/ShareVisit";
import { Logo } from "@/components/SiteHeader";
import { PublicHeader } from "@/components/SiteHeader";
import { SIGNS, signName } from "@/lib/astro";
import { getMe } from "@/lib/server";
import { bigThree, imageVersion, loadShare, plain, shorten, siteUrl } from "@/lib/share";
@@ -48,13 +48,7 @@ export default async function SharedChartPage({ params }: Props) {
<>
<ShareVisit slug={slug} />
{!me && (
<header className="site-header">
<Logo />
<span style={{ flex: 1 }} />
<Link href="/belepes" className="btn btn-sm">
Belépés
</Link>
</header>
<PublicHeader />
)}
<main className="page" style={{ maxWidth: 1180 }}>
<div className="page-head">
@@ -13,6 +13,30 @@ export function Logo() {
);
}
/**
* The header for visitors (not logged in): the home page sections, the
* example and the login. `onHome`: the section links stay on the page.
*/
export function PublicHeader({ onHome = false, current }: { onHome?: boolean; current?: "pelda" }) {
const home = onHome ? "" : "/";
return (
<header className="site-header lp-header">
<Logo />
<nav className="nav lp-nav" aria-label="Fő navigáció">
<a href={`${home}#elemzes`}>Elemzés</a>
<a href={`${home}#elorejelzes`}>Előrejelzés</a>
<a href={`${home}#osszevetes`}>Összevetés</a>
<Link href="/pelda" aria-current={current === "pelda" ? "page" : undefined}>
Példa
</Link>
</nav>
<Link href="/belepes" className="btn btn-sm">
Belépés
</Link>
</header>
);
}
/** The user's package and what is left of it; leads to the packages page. */
function PackageBadge({ me }: { me: Me }) {
const { natal, synastry } = me.analyses_left;
+109
View File
@@ -0,0 +1,109 @@
// Link preview images (og:image): 1200×630 PNG with a chart wheel on the left
// and text on the right, in the site's look. Used by the shared charts and
// the home page.
import "server-only";
import { readFile } from "node:fs/promises";
import { join } from "node:path";
import { ImageResponse } from "next/og";
import type { ChartResult } from "./types";
import { wheelSvg } from "./wheelSvg";
const W = 1200;
const H = 630;
const WHEEL = 590;
const FONTS = join(process.cwd(), "src/assets/og");
let fonts: Promise<{ name: string; data: Buffer; weight: 400 | 600; style: "normal" }[]> | null = null;
function loadFonts() {
fonts ??= Promise.all(
(
[
["Cormorant Garamond", "CormorantGaramond-SemiBold.ttf", 600],
["Inter", "Inter-Regular.ttf", 400],
["Inter", "Inter-SemiBold.ttf", 600],
["DejaVu Sans", "DejaVuSans.ttf", 400],
] as const
).map(async ([name, file, weight]) => ({
name,
data: await readFile(join(FONTS, file)),
weight,
style: "normal" as const,
})),
);
return fonts;
}
/**
* Letters, digits, punctuation and spaces only: a character missing from the
* fonts would make the renderer download a font from the internet.
*/
export const printable = (s: string) => s.replace(/[^\p{L}\p{N}\p{P}\p{Zs}+=<>°]/gu, "");
export interface CardLine {
/** A zodiac or planet glyph (DejaVu Sans has them all). */
glyph: string;
label: string;
}
/** The preview image as a response with the given cache header. */
export async function chartCard({
chart,
timeKnown,
eyebrow,
title,
text,
lines,
cacheControl,
}: {
chart: ChartResult;
timeKnown: boolean;
eyebrow: string;
title: string;
text: string;
lines: CardLine[];
cacheControl: string;
}): Promise<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=""
/>
</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" }}>
{printable(eyebrow)}
</div>
<div style={{ display: "flex", fontFamily: "Cormorant Garamond", fontSize: 56, lineHeight: 1.05 }}>
{printable(title)}
</div>
{text && (
<div style={{ display: "flex", fontSize: 23, lineHeight: 1.45, color: "#c9cfdc" }}>{printable(text)}</div>
)}
<div style={{ display: "flex", flexWrap: "wrap", marginTop: "auto", gap: "8px 22px", fontSize: 21, color: "#c9cfdc" }}>
{lines.map((l) => (
<div key={l.label} style={{ display: "flex", alignItems: "center", gap: 8 }}>
<span style={{ fontFamily: "DejaVu Sans", color: "#d9b46a" }}>{l.glyph.replace(/︎/g, "")}</span>
<span>{printable(l.label)}</span>
</div>
))}
</div>
<div style={{ display: "flex", fontFamily: "Cormorant Garamond", fontSize: 30, color: "#ece6d8" }}>
sors<span style={{ color: "#d9b46a" }}>fonalak</span>
</div>
</div>
</div>
),
{ width: W, height: H, fonts: await loadFonts(), headers: { "Cache-Control": cacheControl } },
);
}