Share reward and less robot load on shared links
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:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user