Forum: the link module, with YouTube previews
- services/forum/src/links: recognises the links in a post and shows a preview for the ones a provider knows; for now YouTube (watch, shorts, live, embed and youtu.be links, with the start time). Title and channel come from YouTube's oEmbed answer, the thumbnail is cut to 16:9 and kept in our own storage, so reading a thread loads nothing from YouTube. Made when a post is written or edited; without it the link stays text. - The card: on a computer a click plays the video in place (youtube-nocookie.com); on a phone it opens the YouTube app (Android: an intent with the web page as fallback; iOS: the link the app takes over), and "Lejátszás itt" plays it in place. - The privacy notice (HU, EN) says what YouTube sees when one plays it. - "Pörgős most" is now "Élénk beszélgetések"; the new thread form lost its note about text and emoji. - docs: the Turnstile captcha is on the list before going live. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -237,7 +237,11 @@ export default async function PrivacyPage() {
|
||||
belépett tagok látják: a rajzot fokokkal és házakkal, a rövid összefoglalót vagy az előrejelzés szövegét,
|
||||
nevek, születési dátum, idő és hely nélkül. A fokokból egy jártas asztrológus nagyjából kiszámolhatja a
|
||||
születési napot és időt, az előrejelzés kezdőnapjából pedig a születésnap kiderül. A csatolt képletet
|
||||
bármikor leveheted, és a kérdés törlésével a link is megszűnik. A fórum szabályai az{" "}
|
||||
bármikor leveheted, és a kérdés törlésével a link is megszűnik. Ha egy hozzászólásban YouTube-link van, a
|
||||
videó címét és képét a szerverünk kéri le, és a saját szerverünkről mutatjuk: a fórum olvasásakor a YouTube
|
||||
nem kap rólad adatot. Ha a videót a fórumon elindítod, a lejátszó a YouTube (Google) szerveréről töltődik be
|
||||
(youtube-nocookie.com), amely látja az IP-címedet és a lejátszás adatait; telefonon a megnyitás a YouTube
|
||||
alkalmazásába visz. A fórum szabályai az{" "}
|
||||
<Link href="/aszf#forum">ÁSZF 8. pontjában</Link> vannak.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
@@ -702,3 +702,26 @@ a.fh-online-item:hover { color: var(--gold); }
|
||||
.fshare-open { margin-top: 4px; }
|
||||
.fnew-share { display: flex; flex-direction: column; gap: 8px; }
|
||||
.fnew-share .fshare { margin-top: 0; }
|
||||
|
||||
/* --- link previews (YouTube) --- */
|
||||
.flinks { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
|
||||
.flink {
|
||||
display: flex; flex-direction: column; max-width: 480px; overflow: hidden;
|
||||
border: 1px solid var(--line-2); border-radius: 14px; background: var(--panel);
|
||||
}
|
||||
.flink-thumb { position: relative; display: block; aspect-ratio: 16 / 9; background: #0e1424; }
|
||||
.flink-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
|
||||
.flink-noimg { display: block; width: 100%; height: 100%; }
|
||||
.flink-play {
|
||||
position: absolute; left: 50%; top: 50%; width: 56px; height: 40px; transform: translate(-50%, -50%);
|
||||
display: grid; place-items: center; border-radius: 12px; background: rgba(15, 15, 15, 0.78);
|
||||
transition: background 0.15s;
|
||||
}
|
||||
.flink-play svg { width: 22px; height: 22px; fill: #fff; }
|
||||
.flink-thumb:hover .flink-play, .flink-thumb:focus-visible .flink-play { background: #d32020; }
|
||||
.flink-meta { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px 12px; }
|
||||
.flink-title { font-weight: 600; font-size: 15px; line-height: 1.35; }
|
||||
.flink-here { align-self: flex-start; margin-top: 4px; }
|
||||
.flink-frame { position: relative; aspect-ratio: 16 / 9; background: #000; }
|
||||
.flink-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
|
||||
.flink .fp-link { display: inline-flex; align-items: center; padding: 0; text-decoration: none; }
|
||||
|
||||
@@ -159,8 +159,8 @@ export default async function ForumHomePage() {
|
||||
{hot.length > 0 && (
|
||||
<section className="fh-section o-5" aria-labelledby="fh-hot">
|
||||
<div className="fh-section-head">
|
||||
<h2 id="fh-hot">Pörgős most</h2>
|
||||
<span className="hint">az utóbbi 24 órában</span>
|
||||
<h2 id="fh-hot">Élénk beszélgetések</h2>
|
||||
<span className="hint">ma sokan írtak bennük</span>
|
||||
</div>
|
||||
<div className="fh-card fh-flush">
|
||||
<ThreadList threads={hot} />
|
||||
|
||||
@@ -145,10 +145,6 @@ export function NewThreadForm({
|
||||
required
|
||||
placeholder={intent === "listen" ? "Írd le, ami benned van…" : "Írd le a gondolataidat…"}
|
||||
/>
|
||||
<span className="hint">
|
||||
Szöveg és emoji: a :) és a {"<3"} magától emojivá alakul. Képet és videót nem lehet beilleszteni, a linkek
|
||||
sima szövegként látszanak.
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<p className="hint">
|
||||
|
||||
@@ -203,7 +203,11 @@ export default async function PrivacyPolicyPage() {
|
||||
yearly forecast or a comparison to a question, only logged-in members see it: the drawing with degrees and
|
||||
houses, the short summary or the forecast text, without names, birth date, time or place. A practised
|
||||
astrologer can roughly work out the birth date and time from the degrees, and a forecast's first day is the
|
||||
birthday. You can take it off at any time, and deleting the question ends the link. The forum rules are in
|
||||
birthday. You can take it off at any time, and deleting the question ends the link. If a post has a YouTube
|
||||
link, our server fetches the video's title and picture and we show them from our own server: reading the
|
||||
forum sends YouTube nothing about you. If you play the video on the forum, the player loads from YouTube's
|
||||
(Google's) servers (youtube-nocookie.com), which see your IP address and what you play; on a phone, opening
|
||||
it takes you to the YouTube app. The forum rules are in
|
||||
point 8 of the <Link href="/aszf#forum">terms (ÁSZF, in Hungarian)</Link>.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
import type { LinkPreview } from "@/lib/forum";
|
||||
|
||||
type Device = "android" | "ios" | "desktop";
|
||||
|
||||
function detect(): Device {
|
||||
const ua = navigator.userAgent;
|
||||
if (/Android/i.test(ua)) return "android";
|
||||
// iPadOS reports itself as a Mac with touch.
|
||||
if (/iPhone|iPad|iPod/i.test(ua) || (/Macintosh/.test(ua) && navigator.maxTouchPoints > 1)) return "ios";
|
||||
return "desktop";
|
||||
}
|
||||
|
||||
/**
|
||||
* A YouTube link under a post: our own copy of the thumbnail (nothing is
|
||||
* loaded from YouTube until someone plays it). On a computer a click plays
|
||||
* it here; on a phone it opens the YouTube app (Android: an intent with the
|
||||
* web page as fallback; iOS: the link, which the app takes over), and
|
||||
* "Lejátszás itt" plays it here.
|
||||
*/
|
||||
function YouTubeCard({ link }: { link: LinkPreview }) {
|
||||
const [playing, setPlaying] = useState(false);
|
||||
const [device, setDevice] = useState<Device>("desktop");
|
||||
useEffect(() => setDevice(detect()), []);
|
||||
const at = link.start ? `&t=${link.start}s` : "";
|
||||
const watch = `https://www.youtube.com/watch?v=${link.id}${at}`;
|
||||
const app =
|
||||
device === "android"
|
||||
? `intent://www.youtube.com/watch?v=${link.id}${at}#Intent;scheme=https;package=com.google.android.youtube;` +
|
||||
`S.browser_fallback_url=${encodeURIComponent(watch)};end`
|
||||
: watch;
|
||||
const mobile = device !== "desktop";
|
||||
|
||||
if (playing) {
|
||||
const start = link.start ? `&start=${link.start}` : "";
|
||||
return (
|
||||
<div className="flink flink-playing">
|
||||
<div className="flink-frame">
|
||||
<iframe
|
||||
src={`https://www.youtube-nocookie.com/embed/${link.id}?autoplay=1&rel=0&playsinline=1${start}`}
|
||||
title={link.title}
|
||||
allow="autoplay; encrypted-media; picture-in-picture; fullscreen"
|
||||
allowFullScreen
|
||||
referrerPolicy="strict-origin-when-cross-origin"
|
||||
/>
|
||||
</div>
|
||||
<div className="flink-meta">
|
||||
<span className="flink-title">{link.title}</span>
|
||||
<a href={watch} target="_blank" rel="noopener noreferrer" className="fp-link">
|
||||
Megnyitás a YouTube-on
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div className="flink">
|
||||
<a
|
||||
className="flink-thumb"
|
||||
href={mobile ? app : watch}
|
||||
onClick={(e) => {
|
||||
if (!mobile) {
|
||||
e.preventDefault();
|
||||
setPlaying(true);
|
||||
}
|
||||
}}
|
||||
aria-label={mobile ? `Megnyitás a YouTube alkalmazásban: ${link.title}` : `Lejátszás: ${link.title}`}
|
||||
>
|
||||
{link.thumbnail ? (
|
||||
// Our own copy of the thumbnail (already small).
|
||||
<img src={link.thumbnail} alt="" width={480} height={270} loading="lazy" />
|
||||
) : (
|
||||
<span className="flink-noimg" />
|
||||
)}
|
||||
<span className="flink-play" aria-hidden="true">
|
||||
<svg viewBox="0 0 24 24">
|
||||
<path d="M8 5.5v13l11-6.5z" />
|
||||
</svg>
|
||||
</span>
|
||||
</a>
|
||||
<div className="flink-meta">
|
||||
<span className="flink-title">{link.title}</span>
|
||||
<span className="hint">
|
||||
YouTube{link.author ? ` · ${link.author}` : ""}
|
||||
{link.start ? ` · ${Math.floor(link.start / 60)}:${String(link.start % 60).padStart(2, "0")}-tól` : ""}
|
||||
</span>
|
||||
{mobile ? (
|
||||
<button type="button" className="fp-link flink-here" onClick={() => setPlaying(true)}>
|
||||
Lejátszás itt
|
||||
</button>
|
||||
) : (
|
||||
<a href={watch} target="_blank" rel="noopener noreferrer" className="fp-link flink-here">
|
||||
Megnyitás a YouTube-on
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** The previews of the links in a post (the link module: YouTube for now). */
|
||||
export function LinkPreviews({ links }: { links: LinkPreview[] }) {
|
||||
return (
|
||||
<div className="flinks">
|
||||
{links.map((link) => (link.provider === "youtube" ? <YouTubeCard key={link.id} link={link} /> : null))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -26,20 +26,34 @@ function withMentions(line: string, mentions: string[]): React.ReactNode[] {
|
||||
return out;
|
||||
}
|
||||
|
||||
/** A post's text: paragraphs and line breaks as typed; links stay plain text; mentions link to profiles. */
|
||||
export function PostBody({ text, mentions = [] }: { text: string; mentions?: string[] }) {
|
||||
/**
|
||||
* A post's text: paragraphs and line breaks as typed; links stay plain text;
|
||||
* mentions link to profiles. `hide`: links shown as a preview below, left
|
||||
* out where they stand on a line of their own.
|
||||
*/
|
||||
export function PostBody({ text, mentions = [], hide = [] }: { text: string; mentions?: string[]; hide?: string[] }) {
|
||||
const shown = hide.length
|
||||
? text
|
||||
.split("\n")
|
||||
.filter((line) => !hide.includes(line.trim()))
|
||||
.join("\n")
|
||||
.trim()
|
||||
: text;
|
||||
return (
|
||||
<div className="fp-body">
|
||||
{text.split(/\n{2,}/).map((para, i) => (
|
||||
<p key={i}>
|
||||
{para.split("\n").map((line, j) => (
|
||||
<span key={j}>
|
||||
{j > 0 && <br />}
|
||||
{withMentions(line, mentions)}
|
||||
</span>
|
||||
))}
|
||||
</p>
|
||||
))}
|
||||
{shown
|
||||
.split(/\n{2,}/)
|
||||
.filter((para) => para.trim() !== "")
|
||||
.map((para, i) => (
|
||||
<p key={i}>
|
||||
{para.split("\n").map((line, j) => (
|
||||
<span key={j}>
|
||||
{j > 0 && <br />}
|
||||
{withMentions(line, mentions)}
|
||||
</span>
|
||||
))}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import { PostBody } from "./PostBody";
|
||||
import type { LiveNotice } from "./ForumNav";
|
||||
import { ReactionIcon } from "./ReactionIcon";
|
||||
import { ReportForm } from "./ReportButton";
|
||||
import { LinkPreviews } from "./LinkPreviews";
|
||||
import { ShareCard } from "./ShareCard";
|
||||
import { TypingLine, useTypingSender, useTypingWatch } from "./typing";
|
||||
import { Badge, RankBadge } from "./Badges";
|
||||
@@ -336,7 +337,8 @@ function PostCard({
|
||||
) : (
|
||||
post.body !== null && (
|
||||
<>
|
||||
<PostBody text={post.body} mentions={post.mentions} />
|
||||
<PostBody text={post.body} mentions={post.mentions} hide={post.links?.map((l) => l.url) ?? []} />
|
||||
{post.links && post.links.length > 0 && <LinkPreviews links={post.links} />}
|
||||
{post.share && <ShareCard share={post.share} />}
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -121,6 +121,22 @@ export interface ForumPost {
|
||||
muted?: boolean;
|
||||
/** A chart, forecast or synastry shared with the question. */
|
||||
share?: ShareCardData | null;
|
||||
/** Previews of the links a provider knows (YouTube for now). */
|
||||
links?: LinkPreview[] | null;
|
||||
}
|
||||
|
||||
/** A link the forum's link module knows, under a post. */
|
||||
export interface LinkPreview {
|
||||
provider: "youtube";
|
||||
id: string;
|
||||
/** As written in the post. */
|
||||
url: string;
|
||||
/** Where to start playing, in seconds. */
|
||||
start: number | null;
|
||||
title: string;
|
||||
author: string | null;
|
||||
/** Our own copy of the thumbnail. */
|
||||
thumbnail: string | null;
|
||||
}
|
||||
|
||||
/** A shared chart in a post: in full for members, `locked` for visitors, `revoked` when taken down. */
|
||||
|
||||
Reference in New Issue
Block a user