Share reward and less robot load on shared links
CI / test (push) Successful in 1m9s
CI / build (push) Successful in 5m9s
CI / deploy (push) Skipped

The first visit of a shared link by someone else earns the sharer one free
natal analysis, once per user. The share page reports visits from the
visitor's browser; robots, the logged-in sharer and the address the link was
made at do not count. The share button is a proper card that says so in small
print; /v1/me tells whether the reward is used up.

Robots: reading a share writes nothing (view_count counts people only), the
frontend keeps shared content for five minutes (cleared when a link is
revoked), and robots.txt turns away the known AI crawlers while leaving the
link preview robots alone.

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-19 09:26:06 +00:00
co-authored by Claude Opus 5.5
parent c7600608d3
commit 19df36369c
16 changed files with 370 additions and 23 deletions
@@ -1,8 +1,10 @@
// Forwards /api/v1/* to the backend, so the browser talks to one origin and
// the session cookie belongs to the frontend's host (no CORS needed).
import { revalidateTag } from "next/cache";
import type { NextRequest } from "next/server";
import { BACKEND_URL } from "@/lib/server";
import { SHARES_TAG } from "@/lib/share";
const REQUEST_HEADERS = ["accept", "accept-language", "authorization", "content-type", "cookie", "user-agent"];
// Hop-by-hop or re-computed by the runtime.
@@ -38,6 +40,8 @@ async function forward(req: NextRequest, ctx: { params: Promise<{ path: string[]
if (!SKIP_RESPONSE_HEADERS.has(name)) out.set(name, value);
});
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 });
return new Response(res.body, { status: res.status, headers: out });
}
+17 -1
View File
@@ -697,7 +697,23 @@ a.pair-row:hover strong { color: var(--gold); }
}
/* Sharing a chart (summary card) and the public share page */
.share { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.share { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.share-button {
display: flex; align-items: center; gap: 14px; width: 100%; padding: 12px 16px; text-align: left; cursor: pointer;
border: 1px solid rgba(217, 180, 106, 0.55); border-radius: 12px; color: var(--ink); font: inherit;
background: linear-gradient(135deg, rgba(217, 180, 106, 0.14), rgba(217, 180, 106, 0.03));
transition: border-color 0.15s, background 0.15s;
}
.share-button:hover { border-color: var(--gold); background: linear-gradient(135deg, rgba(217, 180, 106, 0.22), rgba(217, 180, 106, 0.06)); }
.share-button:disabled { opacity: 0.7; cursor: default; }
.share-icon {
flex: none; width: 40px; height: 40px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
background: var(--gold); color: var(--gold-ink);
}
.share-button-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.share-button-text strong { font-family: var(--font-display); font-size: 21px; font-weight: 600; line-height: 1.15; }
.share-button-text small { font-size: 12.5px; color: var(--gold); }
.share-fine { margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.share-open { align-items: stretch; padding: 14px; border: 1px solid var(--line-2); border-radius: var(--radius); background: var(--panel-2); }
.share-link { display: flex; gap: 8px; }
.share-link .inp { min-height: 36px; font-size: 14px; }
@@ -77,6 +77,7 @@ export default async function ChartPage({ params }: { params: Promise<{ id: stri
initial={summary}
detailedDone={detailed?.status === "done"}
isAdmin={me.user.roles.includes("admin")}
shareRewardGranted={me.share_reward_granted}
/>
<BigThree chart={chart} />
{(elements || modalities || phase) && (
+49
View File
@@ -0,0 +1,49 @@
import type { MetadataRoute } from "next";
// AI crawlers that train models or answer from the site: they load pages
// far more often than visitors do. Link preview robots (Facebook, Messenger,
// Slack, WhatsApp, X, LinkedIn) stay allowed, they make the shared links work.
const AI_CRAWLERS = [
"GPTBot",
"ChatGPT-User",
"OAI-SearchBot",
"ClaudeBot",
"Claude-User",
"Claude-SearchBot",
"anthropic-ai",
"CCBot",
"Google-Extended",
"GoogleOther",
"Applebot-Extended",
"PerplexityBot",
"Perplexity-User",
"Bytespider",
"Amazonbot",
"meta-externalagent",
"meta-externalfetcher",
"FacebookBot",
"cohere-ai",
"cohere-training-data-crawler",
"Diffbot",
"ImagesiftBot",
"Omgilibot",
"Omgili",
"YouBot",
"Timpibot",
"AI2Bot",
"Ai2Bot-Dolma",
"DuckAssistBot",
"MistralAI-User",
"PetalBot",
"Scrapy",
];
export default function robots(): MetadataRoute.Robots {
return {
rules: [
{ userAgent: AI_CRAWLERS, disallow: "/" },
// Logged-in pages redirect anyway; shared links carry noindex.
{ userAgent: "*", allow: "/", disallow: ["/api/", "/admin", "/profil", "/kepletek", "/osszevetesek", "/szemelyek"] },
],
};
}
@@ -4,6 +4,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 { SIGNS, signName } from "@/lib/astro";
import { getMe } from "@/lib/server";
@@ -45,6 +46,7 @@ export default async function SharedChartPage({ params }: Props) {
return (
<>
<ShareVisit slug={slug} />
{!me && (
<header className="site-header">
<Logo />
@@ -25,6 +25,7 @@ export function ChartSummary({
initial,
detailedDone = false,
isAdmin = false,
shareRewardGranted = false,
}: {
chartId: string;
initial: Analysis | null;
@@ -32,6 +33,8 @@ export function ChartSummary({
detailedDone?: boolean;
/** Admins can write the summary again. */
isAdmin?: boolean;
/** The free analysis for sharing is used up. */
shareRewardGranted?: boolean;
}) {
const [summary, setSummary] = useState<Analysis | null>(initial);
const [gaveUp, setGaveUp] = useState(false);
@@ -82,7 +85,7 @@ export function ChartSummary({
<p className="summary-text" lang={summary?.language}>
<Rich text={content.summary ?? ""} />
</p>
<ShareChart chartId={chartId} />
<ShareChart chartId={chartId} rewardGranted={shareRewardGranted} />
<a
href="#elemzes"
className="summary-more"
@@ -9,8 +9,23 @@ interface Share {
url: string;
}
/** Share link of a chart with its short summary: copy, Facebook, the phone's share menu, revoke. */
export function ShareChart({ chartId }: { chartId: string }) {
function ShareIcon() {
return (
<svg viewBox="0 0 24 24" width="20" height="20" aria-hidden="true" fill="none" stroke="currentColor" strokeWidth="1.8">
<circle cx="18" cy="5" r="2.6" />
<circle cx="6" cy="12" r="2.6" />
<circle cx="18" cy="19" r="2.6" />
<path d="M8.3 10.8l7.4-4.4M8.3 13.2l7.4 4.4" strokeLinecap="round" />
</svg>
);
}
/**
* Share link of a chart with its short summary: copy, Facebook, the phone's
* share menu, revoke. The first visit by someone else earns one free natal
* analysis, once per user (`rewardGranted`: already received).
*/
export function ShareChart({ chartId, rewardGranted = false }: { chartId: string; rewardGranted?: boolean }) {
const [share, setShare] = useState<Share | null>(null);
const [busy, setBusy] = useState(false);
const [copied, setCopied] = useState(false);
@@ -67,8 +82,18 @@ export function ShareChart({ chartId }: { chartId: string }) {
if (!share) {
return (
<div className="share">
<button type="button" className="btn btn-sm" onClick={open} disabled={busy}>
{busy ? "Link készül…" : "Megosztás"}
<button type="button" className="share-button" onClick={open} disabled={busy} aria-busy={busy}>
<span className="share-icon">
<ShareIcon />
</span>
<span className="share-button-text">
<strong>{busy ? "Link készül…" : "Oszd meg a képleted"}</strong>
<small>
{rewardGranted
? "Küldd el a barátaidnak, vagy tedd ki Facebookra"
: "+1 ajándék elemzés jár érte, ha valaki megnézi"}
</small>
</span>
</button>
{revoked && <p className="hint">A linket visszavontad.</p>}
{error && (
@@ -87,6 +112,11 @@ export function ShareChart({ chartId }: { chartId: string }) {
A linken a képleted rajza és ez az összefoglaló látszik, név és születési adatok nélkül. Bárki megnyithatja,
akinek elküldöd.
</p>
<p className="share-fine">
{rewardGranted
? "Az ajándék elemzést már megkaptad. Köszönjük, hogy megosztottad!"
: "Ajándék képletelemzés egyszer jár: amikor valaki más először megnyitja a linkedet. A saját megnyitásod nem számít."}
</p>
<div className="share-link">
<input
className="inp"
@@ -0,0 +1,22 @@
"use client";
import { useEffect } from "react";
/**
* Reports a visit of the share page from the visitor's browser. Link preview
* robots do not run scripts, so only people are counted (the backend also
* leaves out the sharer).
*/
export function ShareVisit({ slug }: { slug: string }) {
useEffect(() => {
const key = `share-visit:${slug}`;
try {
if (sessionStorage.getItem(key)) return;
sessionStorage.setItem(key, "1");
} catch {
// storage blocked: report anyway
}
fetch(`/api/v1/public/shares/${slug}/visit`, { method: "POST", credentials: "same-origin" }).catch(() => {});
}, [slug]);
return null;
}
+11 -2
View File
@@ -27,10 +27,19 @@ export interface PublicShare {
const SLUG = /^[A-Za-z0-9_-]{8,64}$/;
/** The shared content, or `null` if the link is unknown or revoked (one backend call per request). */
/** Cache tag of the shared content; revoking a link clears it (see the /api/v1 proxy). */
export const SHARES_TAG = "shares";
/**
* The shared content, or `null` if the link is unknown or revoked. Kept for
* five minutes, so robots opening the page again and again do not reach the
* backend; one backend call per request at most.
*/
export const loadShare = cache(async (slug: string): Promise<PublicShare | null> => {
if (!SLUG.test(slug)) return null;
const res = await fetch(`${BACKEND_URL}/v1/public/shares/${slug}`, { cache: "no-store" });
const res = await fetch(`${BACKEND_URL}/v1/public/shares/${slug}`, {
next: { revalidate: 300, tags: [SHARES_TAG] },
});
if (res.status === 404) return null;
if (!res.ok) throw new Error(`share ${slug}: HTTP ${res.status}`);
return (await res.json()) as PublicShare;
+2
View File
@@ -21,6 +21,8 @@ export interface Me {
persons: PersonSlots;
/** The latest main package bought or given (null: none). */
package: { id: string; name: string; since: string } | null;
/** The free analysis for a shared link is used up (once per user). */
share_reward_granted: boolean;
}
/** A package from the catalog (`GET /v1/packages`). */