feat: server-render public pages for crawlers
Event and blog detail pages, the homepage and the community and contact pages now ship their real content in the server HTML instead of loading it in the browser, so crawlers see events, posts and deep links. - Event detail renders fully on the server (ISR, 5 minutes); missing events return 404. Only the upcoming-events carousel stays client side. - Blog posts render title, author, date, image and the markdown body on the server. The backend fills the body of indexed posts from the Nostr event cache. Likes, replies and the profile avatar stay client islands, and unresolved slugs keep the in-browser relay fallback. Markdown headings shift down one level so the title is the only h1. - Homepage is a server component with real links to upcoming meetups and a new "Latest from the blog" section. - Social links come from server-fetched settings, with SOCIAL_LINKS as a fallback, so no card links to "#" and sameAs lists every profile. - One pageMetadata helper sets title, canonical, og and twitter tags. Section layouts keep the site-name title template alive for nested pages, and toMetaDescription cleans event and post descriptions. - Sitemap: static pages drop lastModified, /board is added, only published meetups are listed, and it revalidates hourly. - Server-side API calls go to the backend on loopback, and the deploy script points build-time prerendering at it. - scripts/seo-check.mjs (npm run seo-check) verifies all of the above. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -73,6 +73,7 @@ function buildPostShapeFromEvent(
|
||||
slug: identifier,
|
||||
content: event.content || '',
|
||||
excerpt: summary,
|
||||
summary,
|
||||
image,
|
||||
authorPubkey: event.pubkey,
|
||||
authorName: null,
|
||||
|
||||
@@ -1,51 +1,21 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import Link from "next/link";
|
||||
import { Heart, Send } from "lucide-react";
|
||||
import ReactMarkdown, { defaultUrlTransform } from "react-markdown";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import { api } from "@/lib/api";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
import {
|
||||
hasNostrExtension,
|
||||
getPublicKey,
|
||||
signEvent,
|
||||
publishEvent,
|
||||
shortenNpub,
|
||||
fetchNostrProfile,
|
||||
fetchLongformFromRelays,
|
||||
fetchEventFromRelays,
|
||||
resolveEventFromRelays,
|
||||
type NostrProfile,
|
||||
} from "@/lib/nostr";
|
||||
import { resolveEventFromRelays } from "@/lib/nostr";
|
||||
import { Button } from "@/components/ui/Button";
|
||||
import { BackLink, Container, ErrorState, PageShell } from "@/components/public/PageLayout";
|
||||
import { markdownComponents } from "./markdownComponents";
|
||||
import { remarkNostr } from "./remarkNostr";
|
||||
import { NostrAuthor } from "./NostrEmbeds";
|
||||
import { PostView, type PostViewData } from "./PostView";
|
||||
import { PostEngagement, RelayLoading } from "./PostIslands";
|
||||
|
||||
interface Post {
|
||||
// Client-only fallback for slugs the backend couldn't resolve at render time
|
||||
// (for example a NIP-19 reference only the visitor's relays know). Indexed
|
||||
// posts are rendered on the server by page.tsx instead.
|
||||
|
||||
interface Post extends PostViewData {
|
||||
id: string;
|
||||
slug: string;
|
||||
title: string;
|
||||
content: string;
|
||||
excerpt?: string;
|
||||
image?: string;
|
||||
authorName?: string;
|
||||
authorPubkey?: string;
|
||||
publishedAt?: string;
|
||||
createdAt?: string;
|
||||
nostrEventId?: string;
|
||||
naddr?: string;
|
||||
categories?: { category: { id: string; name: string; slug: string } }[];
|
||||
}
|
||||
|
||||
interface NostrReply {
|
||||
id: string;
|
||||
pubkey: string;
|
||||
content: string;
|
||||
created_at: number;
|
||||
}
|
||||
|
||||
// Builds a renderable Post from a raw long-form Nostr event, used when a slug is
|
||||
@@ -89,91 +59,30 @@ function ArticleSkeleton() {
|
||||
);
|
||||
}
|
||||
|
||||
function RelayLoading() {
|
||||
return (
|
||||
<div className="flex items-center justify-center gap-3 py-16 text-on-surface-variant">
|
||||
<span
|
||||
className="inline-block w-5 h-5 rounded-full border-2 border-primary/30 border-t-primary animate-spin"
|
||||
aria-hidden
|
||||
/>
|
||||
<span className="text-sm font-medium">Fetching from Nostr relays…</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function BlogPostClient({ slug }: { slug: string }) {
|
||||
const [post, setPost] = useState<Post | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [liked, setLiked] = useState(false);
|
||||
const [likeCount, setLikeCount] = useState(0);
|
||||
const [comment, setComment] = useState("");
|
||||
const [replies, setReplies] = useState<NostrReply[]>([]);
|
||||
const [hasNostr, setHasNostr] = useState(false);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [authorProfile, setAuthorProfile] = useState<NostrProfile | null>(null);
|
||||
const [liveContent, setLiveContent] = useState<string | null>(null);
|
||||
const [liveImage, setLiveImage] = useState<string | null>(null);
|
||||
const [loadingContent, setLoadingContent] = useState(false);
|
||||
const [resolvingFromRelays, setResolvingFromRelays] = useState(false);
|
||||
const [contentError, setContentError] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [retryKey, setRetryKey] = useState(0);
|
||||
|
||||
const retry = useCallback(() => setRetryKey((k) => k + 1), []);
|
||||
|
||||
useEffect(() => {
|
||||
setHasNostr(hasNostrExtension());
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!slug) return;
|
||||
let cancelled = false;
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
setLiveContent(null);
|
||||
setLiveImage(null);
|
||||
setPost(null);
|
||||
setAuthorProfile(null);
|
||||
setContentError(false);
|
||||
setResolvingFromRelays(false);
|
||||
|
||||
// Loads the author's profile, then hydrates the article body from relays
|
||||
// when only metadata is present (indexed posts store an empty body).
|
||||
const hydrate = (data: Post) => {
|
||||
if (cancelled) return;
|
||||
setPost(data);
|
||||
setLoading(false);
|
||||
if (data?.authorPubkey) {
|
||||
fetchNostrProfile(data.authorPubkey)
|
||||
.then((profile) => !cancelled && setAuthorProfile(profile))
|
||||
.catch(() => {});
|
||||
}
|
||||
if (!data?.content && (data?.naddr || data?.nostrEventId)) {
|
||||
setLoadingContent(true);
|
||||
setContentError(false);
|
||||
const fetchPromise = data.naddr
|
||||
? fetchLongformFromRelays(data.naddr)
|
||||
: fetchEventFromRelays(data.nostrEventId!);
|
||||
fetchPromise
|
||||
.then((event) => {
|
||||
if (cancelled) return;
|
||||
if (event?.content) {
|
||||
setLiveContent(event.content);
|
||||
// Pull the longform header image (`image` tag) for display.
|
||||
const img = event.tags?.find((t: string[]) => t[0] === "image")?.[1];
|
||||
if (img) setLiveImage(img);
|
||||
} else {
|
||||
setContentError(true); // not found / timed out
|
||||
}
|
||||
})
|
||||
.catch(() => !cancelled && setContentError(true))
|
||||
.finally(() => !cancelled && setLoadingContent(false));
|
||||
}
|
||||
};
|
||||
|
||||
api
|
||||
.getPost(slug)
|
||||
.then((data) => hydrate(data))
|
||||
.then((data) => {
|
||||
if (cancelled) return;
|
||||
setPost(data);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch(() => {
|
||||
// Not indexed: treat the slug itself as a NIP-19 reference and resolve
|
||||
// the long-form note live from relays.
|
||||
@@ -184,7 +93,7 @@ export default function BlogPostClient({ slug }: { slug: string }) {
|
||||
.then((event) => {
|
||||
if (cancelled) return;
|
||||
setResolvingFromRelays(false);
|
||||
if (event) hydrate(postFromEvent(event, slug));
|
||||
if (event) setPost(postFromEvent(event, slug));
|
||||
else setError("Post not found");
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -199,74 +108,6 @@ export default function BlogPostClient({ slug }: { slug: string }) {
|
||||
};
|
||||
}, [slug, retryKey]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!slug) return;
|
||||
api.getPostReactions(slug)
|
||||
.then((data) => setLikeCount(data.count))
|
||||
.catch(() => {});
|
||||
|
||||
api.getPostReplies(slug)
|
||||
.then((data) => setReplies(data.replies || []))
|
||||
.catch(() => {});
|
||||
}, [slug]);
|
||||
|
||||
const handleLike = useCallback(async () => {
|
||||
if (liked || !post?.nostrEventId || !hasNostr) return;
|
||||
try {
|
||||
const pubkey = await getPublicKey();
|
||||
const reactionEvent = {
|
||||
kind: 7,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [["e", post.nostrEventId], ["p", post.authorPubkey || ""]],
|
||||
content: "+",
|
||||
pubkey,
|
||||
};
|
||||
const signedReaction = await signEvent(reactionEvent);
|
||||
await publishEvent(signedReaction);
|
||||
setLiked(true);
|
||||
setLikeCount((c) => c + 1);
|
||||
} catch {
|
||||
// User rejected or extension unavailable
|
||||
}
|
||||
}, [liked, post, hasNostr]);
|
||||
|
||||
const handleComment = useCallback(async () => {
|
||||
if (!comment.trim() || !post?.nostrEventId || !hasNostr) return;
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const pubkey = await getPublicKey();
|
||||
const replyEvent = {
|
||||
kind: 1,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [["e", post.nostrEventId, "", "reply"], ["p", post.authorPubkey || ""]],
|
||||
content: comment.trim(),
|
||||
pubkey,
|
||||
};
|
||||
const signed = await signEvent(replyEvent);
|
||||
await publishEvent(signed);
|
||||
setReplies((prev) => [
|
||||
...prev,
|
||||
{
|
||||
id: signed.id || Date.now().toString(),
|
||||
pubkey,
|
||||
content: comment.trim(),
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
},
|
||||
]);
|
||||
setComment("");
|
||||
} catch {
|
||||
// User rejected or extension unavailable
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
}, [comment, post, hasNostr]);
|
||||
|
||||
const categories = post?.categories?.map((c) => c.category) || [];
|
||||
const headerImage = post?.image || liveImage;
|
||||
|
||||
const hasAuthor = !!(authorProfile || post?.authorName || post?.authorPubkey);
|
||||
const date = post?.publishedAt || post?.createdAt;
|
||||
|
||||
return (
|
||||
<PageShell>
|
||||
<Container width="narrow" className="pt-8 md:pt-12">
|
||||
@@ -292,164 +133,11 @@ export default function BlogPostClient({ slug }: { slug: string }) {
|
||||
|
||||
{!loading && !error && post && (
|
||||
<>
|
||||
<header className="mb-10">
|
||||
{categories.length > 0 && (
|
||||
<div className="mb-5 flex flex-wrap gap-2">
|
||||
{categories.map((cat) => (
|
||||
<span key={cat.id} className="badge">
|
||||
{cat.name}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<h1 className="mb-6 text-4xl font-black leading-[1.08] tracking-tight text-on-surface md:text-5xl">
|
||||
{post.title}
|
||||
</h1>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-on-surface-variant/80">
|
||||
{hasAuthor && (
|
||||
<div className="flex items-center gap-2.5">
|
||||
{authorProfile?.picture && (
|
||||
<img
|
||||
src={authorProfile.picture}
|
||||
alt=""
|
||||
className="h-8 w-8 shrink-0 rounded-full bg-zinc-800 object-cover"
|
||||
onError={(e) => { (e.target as HTMLImageElement).style.display = "none"; }}
|
||||
/>
|
||||
)}
|
||||
<span className="font-medium text-on-surface">
|
||||
{authorProfile?.name || post.authorName || shortenNpub(post.authorPubkey!)}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{date && (
|
||||
<>
|
||||
{hasAuthor && <span aria-hidden>·</span>}
|
||||
<time dateTime={date}>{formatDate(date)}</time>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{headerImage && (
|
||||
<img
|
||||
src={headerImage}
|
||||
alt=""
|
||||
className="mb-12 max-h-[28rem] w-full rounded-xl border border-white/[0.06] object-cover"
|
||||
onError={(e) => {
|
||||
(e.target as HTMLImageElement).style.display = "none";
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
<article className="mb-16 text-base md:text-[1.0625rem]">
|
||||
{loadingContent ? (
|
||||
<RelayLoading />
|
||||
) : contentError && !(post.content || liveContent) ? (
|
||||
<div className="py-12 text-center">
|
||||
<p className="mb-4 text-on-surface-variant">
|
||||
Couldn't fetch this article from the Nostr relays. It may be
|
||||
temporarily unavailable.
|
||||
</p>
|
||||
<Button variant="secondary" size="sm" onClick={retry}>
|
||||
Try again
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm, remarkNostr]}
|
||||
components={markdownComponents}
|
||||
// Preserve nostr: links (react-markdown strips unknown
|
||||
// schemes by default), so mentions/notes resolve correctly.
|
||||
urlTransform={(url) =>
|
||||
url.startsWith("nostr:") ? url : defaultUrlTransform(url)
|
||||
}
|
||||
>
|
||||
{post.content || liveContent || ""}
|
||||
</ReactMarkdown>
|
||||
)}
|
||||
</article>
|
||||
|
||||
<section aria-labelledby="comments-heading" className="border-t border-white/[0.06] pt-10">
|
||||
<div className="mb-8 flex flex-wrap items-center gap-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleLike}
|
||||
disabled={!hasNostr}
|
||||
aria-pressed={liked}
|
||||
title={hasNostr ? "Like this post" : "Install a Nostr extension to interact"}
|
||||
className={buttonClassLike(liked)}
|
||||
>
|
||||
<Heart size={17} fill={liked ? "currentColor" : "none"} aria-hidden />
|
||||
<span className="tabular-nums">{likeCount}</span>
|
||||
<span className="sr-only">likes</span>
|
||||
</button>
|
||||
{!hasNostr && (
|
||||
<span className="text-xs text-on-surface-variant/70">
|
||||
Install a Nostr extension to like and comment
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<h2 id="comments-heading" className="mb-6 text-2xl font-black tracking-tight text-on-surface">
|
||||
Comments {replies.length > 0 && <span className="text-on-surface-variant/70">({replies.length})</span>}
|
||||
</h2>
|
||||
|
||||
{hasNostr && (
|
||||
<div className="mb-8 flex gap-3">
|
||||
<label htmlFor="comment" className="sr-only">Your comment</label>
|
||||
<textarea
|
||||
id="comment"
|
||||
value={comment}
|
||||
onChange={(e) => setComment(e.target.value)}
|
||||
placeholder="Share your thoughts..."
|
||||
rows={3}
|
||||
className="field flex-1 resize-none py-3"
|
||||
/>
|
||||
<Button
|
||||
onClick={handleComment}
|
||||
disabled={!comment.trim() || submitting}
|
||||
aria-label="Post comment"
|
||||
className="self-end px-4"
|
||||
>
|
||||
<Send size={18} aria-hidden />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{replies.length > 0 ? (
|
||||
<ul className="space-y-4">
|
||||
{replies.map((r) => (
|
||||
<li key={r.id} className="card p-5">
|
||||
<div className="mb-2 flex items-center gap-2.5">
|
||||
<NostrAuthor pubkey={r.pubkey} />
|
||||
<span className="text-on-surface-variant/50" aria-hidden>·</span>
|
||||
<span className="text-xs text-on-surface-variant/70">
|
||||
{formatDate(new Date(r.created_at * 1000))}
|
||||
</span>
|
||||
</div>
|
||||
<p className="whitespace-pre-wrap break-words text-sm leading-relaxed text-on-surface-variant">
|
||||
{r.content}
|
||||
</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p className="text-sm text-on-surface-variant/70">
|
||||
No comments yet. Be the first to share your thoughts.
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
<PostView post={post} />
|
||||
<PostEngagement slug={slug} nostrEventId={post.nostrEventId} authorPubkey={post.authorPubkey} />
|
||||
</>
|
||||
)}
|
||||
</Container>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
|
||||
function buttonClassLike(liked: boolean) {
|
||||
return liked
|
||||
? "inline-flex h-10 items-center gap-2 rounded-lg border border-primary/30 bg-primary/10 px-4 text-sm font-semibold text-primary"
|
||||
: "inline-flex h-10 items-center gap-2 rounded-lg border border-white/10 bg-white/[0.04] px-4 text-sm font-semibold text-on-surface transition-colors hover:border-white/20 hover:bg-white/[0.08] disabled:opacity-50";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,321 @@
|
||||
"use client";
|
||||
|
||||
// Interactive pieces of a blog post page. The article itself is server-rendered
|
||||
// (see PostView); these hydrate in the browser for Nostr profile lookups,
|
||||
// relay fetches, likes and replies.
|
||||
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { Heart, Send } from "lucide-react";
|
||||
import { api } from "@/lib/api";
|
||||
import { formatDate } from "@/lib/utils";
|
||||
import {
|
||||
hasNostrExtension,
|
||||
getPublicKey,
|
||||
signEvent,
|
||||
publishEvent,
|
||||
shortenNpub,
|
||||
fetchNostrProfile,
|
||||
fetchLongformFromRelays,
|
||||
fetchEventFromRelays,
|
||||
type NostrProfile,
|
||||
} from "@/lib/nostr";
|
||||
import { Button } from "@/components/ui/Button";
|
||||
import { PostMarkdown } from "./PostMarkdown";
|
||||
import { NostrAuthor } from "./NostrEmbeds";
|
||||
|
||||
export function RelayLoading() {
|
||||
return (
|
||||
<div className="flex items-center justify-center gap-3 py-16 text-on-surface-variant">
|
||||
<span
|
||||
className="inline-block w-5 h-5 rounded-full border-2 border-primary/30 border-t-primary animate-spin"
|
||||
aria-hidden
|
||||
/>
|
||||
<span className="text-sm font-medium">Fetching from Nostr relays…</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/** Author name from the server, upgraded with the Nostr profile name and avatar. */
|
||||
export function PostAuthor({ pubkey, name }: { pubkey?: string; name?: string | null }) {
|
||||
const [profile, setProfile] = useState<NostrProfile | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!pubkey) return;
|
||||
let cancelled = false;
|
||||
fetchNostrProfile(pubkey)
|
||||
.then((p) => !cancelled && setProfile(p))
|
||||
.catch(() => {});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [pubkey]);
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-2.5">
|
||||
{profile?.picture && (
|
||||
<img
|
||||
src={profile.picture}
|
||||
alt=""
|
||||
className="h-8 w-8 shrink-0 rounded-full bg-zinc-800 object-cover"
|
||||
onError={(e) => { (e.target as HTMLImageElement).style.display = "none"; }}
|
||||
/>
|
||||
)}
|
||||
<span className="font-medium text-on-surface">
|
||||
{profile?.name || name || (pubkey ? shortenNpub(pubkey) : "")}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export function PostImage({ src }: { src: string }) {
|
||||
return (
|
||||
<img
|
||||
src={src}
|
||||
alt=""
|
||||
className="mb-12 max-h-[28rem] w-full rounded-xl border border-white/[0.06] object-cover"
|
||||
onError={(e) => {
|
||||
(e.target as HTMLImageElement).style.display = "none";
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fallback body for posts the server couldn't load: fetches the long-form
|
||||
* event from relays in the browser, as the page did before server rendering.
|
||||
*/
|
||||
export function PostLiveBody({
|
||||
naddr,
|
||||
nostrEventId,
|
||||
image,
|
||||
}: {
|
||||
naddr?: string | null;
|
||||
nostrEventId?: string;
|
||||
image?: string | null;
|
||||
}) {
|
||||
const [content, setContent] = useState<string | null>(null);
|
||||
const [liveImage, setLiveImage] = useState<string | null>(null);
|
||||
const [loading, setLoading] = useState(!!(naddr || nostrEventId));
|
||||
const [failed, setFailed] = useState(!(naddr || nostrEventId));
|
||||
const [retryKey, setRetryKey] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (!naddr && !nostrEventId) return;
|
||||
let cancelled = false;
|
||||
setLoading(true);
|
||||
setFailed(false);
|
||||
const fetchPromise = naddr ? fetchLongformFromRelays(naddr) : fetchEventFromRelays(nostrEventId!);
|
||||
fetchPromise
|
||||
.then((event) => {
|
||||
if (cancelled) return;
|
||||
if (event?.content) {
|
||||
setContent(event.content);
|
||||
// Pull the longform header image (`image` tag) for display.
|
||||
const img = event.tags?.find((t: string[]) => t[0] === "image")?.[1];
|
||||
if (img) setLiveImage(img);
|
||||
} else {
|
||||
setFailed(true); // not found / timed out
|
||||
}
|
||||
})
|
||||
.catch(() => !cancelled && setFailed(true))
|
||||
.finally(() => !cancelled && setLoading(false));
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [naddr, nostrEventId, retryKey]);
|
||||
|
||||
const headerImage = image || liveImage;
|
||||
|
||||
return (
|
||||
<>
|
||||
{headerImage && <PostImage src={headerImage} />}
|
||||
<article className="mb-16 text-base md:text-[1.0625rem]">
|
||||
{loading ? (
|
||||
<RelayLoading />
|
||||
) : failed || !content ? (
|
||||
<div className="py-12 text-center">
|
||||
<p className="mb-4 text-on-surface-variant">
|
||||
Couldn't fetch this article from the Nostr relays. It may be
|
||||
temporarily unavailable.
|
||||
</p>
|
||||
<Button variant="secondary" size="sm" onClick={() => setRetryKey((k) => k + 1)}>
|
||||
Try again
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<PostMarkdown content={content} />
|
||||
)}
|
||||
</article>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
interface NostrReply {
|
||||
id: string;
|
||||
pubkey: string;
|
||||
content: string;
|
||||
created_at: number;
|
||||
}
|
||||
|
||||
/** Likes (kind 7) and comments (kind 1 replies) on the post's Nostr event. */
|
||||
export function PostEngagement({
|
||||
slug,
|
||||
nostrEventId,
|
||||
authorPubkey,
|
||||
}: {
|
||||
slug: string;
|
||||
nostrEventId?: string;
|
||||
authorPubkey?: string;
|
||||
}) {
|
||||
const [liked, setLiked] = useState(false);
|
||||
const [likeCount, setLikeCount] = useState(0);
|
||||
const [comment, setComment] = useState("");
|
||||
const [replies, setReplies] = useState<NostrReply[]>([]);
|
||||
const [hasNostr, setHasNostr] = useState(false);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setHasNostr(hasNostrExtension());
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!slug) return;
|
||||
api.getPostReactions(slug)
|
||||
.then((data) => setLikeCount(data.count))
|
||||
.catch(() => {});
|
||||
|
||||
api.getPostReplies(slug)
|
||||
.then((data) => setReplies(data.replies || []))
|
||||
.catch(() => {});
|
||||
}, [slug]);
|
||||
|
||||
const handleLike = useCallback(async () => {
|
||||
if (liked || !nostrEventId || !hasNostr) return;
|
||||
try {
|
||||
const pubkey = await getPublicKey();
|
||||
const reactionEvent = {
|
||||
kind: 7,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [["e", nostrEventId], ["p", authorPubkey || ""]],
|
||||
content: "+",
|
||||
pubkey,
|
||||
};
|
||||
const signedReaction = await signEvent(reactionEvent);
|
||||
await publishEvent(signedReaction);
|
||||
setLiked(true);
|
||||
setLikeCount((c) => c + 1);
|
||||
} catch {
|
||||
// User rejected or extension unavailable
|
||||
}
|
||||
}, [liked, nostrEventId, authorPubkey, hasNostr]);
|
||||
|
||||
const handleComment = useCallback(async () => {
|
||||
if (!comment.trim() || !nostrEventId || !hasNostr) return;
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const pubkey = await getPublicKey();
|
||||
const replyEvent = {
|
||||
kind: 1,
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
tags: [["e", nostrEventId, "", "reply"], ["p", authorPubkey || ""]],
|
||||
content: comment.trim(),
|
||||
pubkey,
|
||||
};
|
||||
const signed = await signEvent(replyEvent);
|
||||
await publishEvent(signed);
|
||||
setReplies((prev) => [
|
||||
...prev,
|
||||
{
|
||||
id: signed.id || Date.now().toString(),
|
||||
pubkey,
|
||||
content: comment.trim(),
|
||||
created_at: Math.floor(Date.now() / 1000),
|
||||
},
|
||||
]);
|
||||
setComment("");
|
||||
} catch {
|
||||
// User rejected or extension unavailable
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
}, [comment, nostrEventId, authorPubkey, hasNostr]);
|
||||
|
||||
return (
|
||||
<section aria-labelledby="comments-heading" className="border-t border-white/[0.06] pt-10">
|
||||
<div className="mb-8 flex flex-wrap items-center gap-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleLike}
|
||||
disabled={!hasNostr}
|
||||
aria-pressed={liked}
|
||||
title={hasNostr ? "Like this post" : "Install a Nostr extension to interact"}
|
||||
className={buttonClassLike(liked)}
|
||||
>
|
||||
<Heart size={17} fill={liked ? "currentColor" : "none"} aria-hidden />
|
||||
<span className="tabular-nums">{likeCount}</span>
|
||||
<span className="sr-only">likes</span>
|
||||
</button>
|
||||
{!hasNostr && (
|
||||
<span className="text-xs text-on-surface-variant/70">
|
||||
Install a Nostr extension to like and comment
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<h2 id="comments-heading" className="mb-6 text-2xl font-black tracking-tight text-on-surface">
|
||||
Comments {replies.length > 0 && <span className="text-on-surface-variant/70">({replies.length})</span>}
|
||||
</h2>
|
||||
|
||||
{hasNostr && (
|
||||
<div className="mb-8 flex gap-3">
|
||||
<label htmlFor="comment" className="sr-only">Your comment</label>
|
||||
<textarea
|
||||
id="comment"
|
||||
value={comment}
|
||||
onChange={(e) => setComment(e.target.value)}
|
||||
placeholder="Share your thoughts..."
|
||||
rows={3}
|
||||
className="field flex-1 resize-none py-3"
|
||||
/>
|
||||
<Button
|
||||
onClick={handleComment}
|
||||
disabled={!comment.trim() || submitting}
|
||||
aria-label="Post comment"
|
||||
className="self-end px-4"
|
||||
>
|
||||
<Send size={18} aria-hidden />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{replies.length > 0 ? (
|
||||
<ul className="space-y-4">
|
||||
{replies.map((r) => (
|
||||
<li key={r.id} className="card p-5">
|
||||
<div className="mb-2 flex items-center gap-2.5">
|
||||
<NostrAuthor pubkey={r.pubkey} />
|
||||
<span className="text-on-surface-variant/50" aria-hidden>·</span>
|
||||
<span className="text-xs text-on-surface-variant/70">
|
||||
{formatDate(new Date(r.created_at * 1000))}
|
||||
</span>
|
||||
</div>
|
||||
<p className="whitespace-pre-wrap break-words text-sm leading-relaxed text-on-surface-variant">
|
||||
{r.content}
|
||||
</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<p className="text-sm text-on-surface-variant/70">
|
||||
No comments yet. Be the first to share your thoughts.
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function buttonClassLike(liked: boolean) {
|
||||
return liked
|
||||
? "inline-flex h-10 items-center gap-2 rounded-lg border border-primary/30 bg-primary/10 px-4 text-sm font-semibold text-primary"
|
||||
: "inline-flex h-10 items-center gap-2 rounded-lg border border-white/10 bg-white/[0.04] px-4 text-sm font-semibold text-on-surface transition-colors hover:border-white/20 hover:bg-white/[0.08] disabled:opacity-50";
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import ReactMarkdown, { defaultUrlTransform } from "react-markdown";
|
||||
import remarkGfm from "remark-gfm";
|
||||
import { markdownComponents } from "./markdownComponents";
|
||||
import { remarkNostr } from "./remarkNostr";
|
||||
|
||||
/** Article body renderer, shared by server-rendered posts and the relay fallback. */
|
||||
export function PostMarkdown({ content }: { content: string }) {
|
||||
return (
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm, remarkNostr]}
|
||||
components={markdownComponents}
|
||||
// Preserve nostr: links (react-markdown strips unknown schemes by
|
||||
// default), so mentions/notes resolve correctly.
|
||||
urlTransform={(url) => (url.startsWith("nostr:") ? url : defaultUrlTransform(url))}
|
||||
>
|
||||
{content}
|
||||
</ReactMarkdown>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { formatDateUtc } from "@/lib/utils";
|
||||
import { PostMarkdown } from "./PostMarkdown";
|
||||
import { PostAuthor, PostImage, PostLiveBody } from "./PostIslands";
|
||||
|
||||
export interface PostViewData {
|
||||
title: string;
|
||||
content: string;
|
||||
image?: string | null;
|
||||
authorName?: string | null;
|
||||
authorPubkey?: string;
|
||||
publishedAt?: string | null;
|
||||
createdAt?: string;
|
||||
nostrEventId?: string;
|
||||
naddr?: string | null;
|
||||
categories?: { category: { id: string; name: string; slug: string } }[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Post header, header image and body. Has no state of its own, so it renders
|
||||
* on the server for indexed posts; only the author avatar, image error
|
||||
* handling and (when the server had no body) the relay fetch hydrate.
|
||||
*/
|
||||
export function PostView({ post }: { post: PostViewData }) {
|
||||
const categories = post.categories?.map((c) => c.category) || [];
|
||||
const hasAuthor = !!(post.authorName || post.authorPubkey);
|
||||
const date = post.publishedAt || post.createdAt;
|
||||
|
||||
return (
|
||||
<>
|
||||
<header className="mb-10">
|
||||
{categories.length > 0 && (
|
||||
<div className="mb-5 flex flex-wrap gap-2">
|
||||
{categories.map((cat) => (
|
||||
<span key={cat.id} className="badge">
|
||||
{cat.name}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<h1 className="mb-6 text-4xl font-black leading-[1.08] tracking-tight text-on-surface md:text-5xl">
|
||||
{post.title}
|
||||
</h1>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-sm text-on-surface-variant/80">
|
||||
{hasAuthor && <PostAuthor pubkey={post.authorPubkey} name={post.authorName} />}
|
||||
{date && (
|
||||
<>
|
||||
{hasAuthor && <span aria-hidden>·</span>}
|
||||
<time dateTime={date}>{formatDateUtc(date)}</time>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{post.content ? (
|
||||
<>
|
||||
{post.image && <PostImage src={post.image} />}
|
||||
<article className="mb-16 text-base md:text-[1.0625rem]">
|
||||
<PostMarkdown content={post.content} />
|
||||
</article>
|
||||
</>
|
||||
) : (
|
||||
<PostLiveBody naddr={post.naddr} nostrEventId={post.nostrEventId} image={post.image} />
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -4,18 +4,28 @@ import { NostrEntity } from "./NostrEmbeds";
|
||||
// Shared markdown renderers for blog article bodies. The `remarkNostr` plugin
|
||||
// rewrites NIP-27 `nostr:` references into links with that scheme, which the
|
||||
// `a` renderer below swaps for live profile/note embeds.
|
||||
//
|
||||
// Headings are shifted down one level (markdown `#` renders as <h2>, and so on)
|
||||
// so the post title stays the page's only <h1>. Each keeps the look of its
|
||||
// markdown level.
|
||||
export const markdownComponents: Components = {
|
||||
h1: ({ children }) => (
|
||||
<h1 className="mb-4 mt-12 text-3xl font-black tracking-tight text-on-surface">{children}</h1>
|
||||
<h2 className="mb-4 mt-12 text-3xl font-black tracking-tight text-on-surface">{children}</h2>
|
||||
),
|
||||
h2: ({ children }) => (
|
||||
<h2 className="mb-4 mt-12 text-2xl font-black tracking-tight text-on-surface">{children}</h2>
|
||||
<h3 className="mb-4 mt-12 text-2xl font-black tracking-tight text-on-surface">{children}</h3>
|
||||
),
|
||||
h3: ({ children }) => (
|
||||
<h3 className="mb-3 mt-8 text-xl font-bold text-on-surface">{children}</h3>
|
||||
<h4 className="mb-3 mt-8 text-xl font-bold text-on-surface">{children}</h4>
|
||||
),
|
||||
h4: ({ children }) => (
|
||||
<h4 className="mb-2 mt-6 text-lg font-semibold text-on-surface">{children}</h4>
|
||||
<h5 className="mb-2 mt-6 text-lg font-semibold text-on-surface">{children}</h5>
|
||||
),
|
||||
h5: ({ children }) => (
|
||||
<h6 className="mb-2 mt-6 text-base font-semibold text-on-surface">{children}</h6>
|
||||
),
|
||||
h6: ({ children }) => (
|
||||
<h6 className="mb-2 mt-6 text-base font-semibold text-on-surface-variant">{children}</h6>
|
||||
),
|
||||
p: ({ children }) => (
|
||||
<p className="mb-6 leading-[1.75] text-on-surface-variant">{children}</p>
|
||||
|
||||
@@ -1,85 +1,93 @@
|
||||
import type { Metadata } from "next";
|
||||
import BlogPostClient from "./BlogPostClient";
|
||||
import { PostView } from "./PostView";
|
||||
import { PostEngagement } from "./PostIslands";
|
||||
import { BlogPostingJsonLd, BreadcrumbJsonLd } from "@/components/public/JsonLd";
|
||||
import { apiUrl } from "@/lib/api-base";
|
||||
import { BackLink, Container, PageShell } from "@/components/public/PageLayout";
|
||||
import { getPost, type Post } from "@/lib/server/data";
|
||||
import { pageMetadata, SITE_NAME } from "@/lib/seo";
|
||||
import { toMetaDescription } from "@/lib/text";
|
||||
|
||||
async function fetchPost(slug: string) {
|
||||
try {
|
||||
const res = await fetch(apiUrl(`/posts/${slug}`), {
|
||||
next: { revalidate: 300 },
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
return res.json();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
// Incremental static regeneration: rebuilt in the background at most every 5 minutes.
|
||||
export const revalidate = 300;
|
||||
|
||||
// No paths at build time; each page is rendered on its first visit, then cached.
|
||||
export function generateStaticParams() {
|
||||
return [];
|
||||
}
|
||||
|
||||
interface Props {
|
||||
params: Promise<{ slug: string }>;
|
||||
params: { slug: string };
|
||||
}
|
||||
|
||||
function describe(post: Post): string {
|
||||
// Some authors set a `summary` tag that just repeats the title; use the body then.
|
||||
const summary = toMetaDescription(post.summary);
|
||||
const usefulSummary = summary.length >= 50 && summary !== post.title ? summary : "";
|
||||
return (
|
||||
usefulSummary ||
|
||||
toMetaDescription(post.content || post.excerpt) ||
|
||||
`Read "${post.title}" on the ${SITE_NAME} blog.`
|
||||
);
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const post = await fetchPost(slug);
|
||||
const post = await getPost(params.slug);
|
||||
if (!post) {
|
||||
return { title: "Post Not Found" };
|
||||
}
|
||||
|
||||
const description =
|
||||
post.excerpt ||
|
||||
`Read "${post.title}" on the Belgian Bitcoin Embassy blog.`;
|
||||
const author = post.authorName || "Belgian Bitcoin Embassy";
|
||||
const author = post.authorName || SITE_NAME;
|
||||
// Prefer the post's own header image (Nostr `image` tag); fall back to a
|
||||
// generated OG card so every post still gets a real preview image.
|
||||
const ogImageUrl = post.image || `/og?title=${encodeURIComponent(post.title)}&type=blog`;
|
||||
|
||||
return {
|
||||
return pageMetadata({
|
||||
title: post.title,
|
||||
description,
|
||||
description: describe(post),
|
||||
path: `/blog/${params.slug}`,
|
||||
image: ogImageUrl,
|
||||
type: "article",
|
||||
openGraph: {
|
||||
type: "article",
|
||||
title: post.title,
|
||||
description,
|
||||
publishedTime: post.publishedAt || post.createdAt,
|
||||
modifiedTime: post.updatedAt,
|
||||
authors: [author],
|
||||
images: [{ url: ogImageUrl, width: 1200, height: 630, alt: post.title }],
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: post.title,
|
||||
description,
|
||||
images: [ogImageUrl],
|
||||
},
|
||||
alternates: { canonical: `/blog/${slug}` },
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export default async function BlogDetailPage({ params }: Props) {
|
||||
const { slug } = await params;
|
||||
const post = await fetchPost(slug);
|
||||
const { slug } = params;
|
||||
const post = await getPost(slug);
|
||||
|
||||
// The backend couldn't resolve this slug; let the browser try its relays.
|
||||
if (!post) return <BlogPostClient slug={slug} />;
|
||||
|
||||
return (
|
||||
<>
|
||||
{post && (
|
||||
<>
|
||||
<BlogPostingJsonLd
|
||||
title={post.title}
|
||||
description={post.excerpt || `Read "${post.title}" on the Belgian Bitcoin Embassy blog.`}
|
||||
slug={slug}
|
||||
publishedAt={post.publishedAt || post.createdAt}
|
||||
authorName={post.authorName}
|
||||
/>
|
||||
<BreadcrumbJsonLd
|
||||
items={[
|
||||
{ name: "Home", href: "/" },
|
||||
{ name: "Blog", href: "/blog" },
|
||||
{ name: post.title, href: `/blog/${slug}` },
|
||||
]}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<BlogPostClient slug={slug} />
|
||||
<BlogPostingJsonLd
|
||||
title={post.title}
|
||||
description={describe(post)}
|
||||
slug={slug}
|
||||
publishedAt={post.publishedAt || post.createdAt}
|
||||
authorName={post.authorName ?? undefined}
|
||||
/>
|
||||
<BreadcrumbJsonLd
|
||||
items={[
|
||||
{ name: "Home", href: "/" },
|
||||
{ name: "Blog", href: "/blog" },
|
||||
{ name: post.title, href: `/blog/${slug}` },
|
||||
]}
|
||||
/>
|
||||
<PageShell>
|
||||
<Container width="narrow" className="pt-8 md:pt-12">
|
||||
<BackLink href="/blog" className="mb-8 md:mb-10">
|
||||
All posts
|
||||
</BackLink>
|
||||
<PostView post={post} />
|
||||
<PostEngagement slug={slug} nostrEventId={post.nostrEventId} authorPubkey={post.authorPubkey} />
|
||||
</Container>
|
||||
</PageShell>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import type { Metadata } from "next";
|
||||
import { pageMetadata } from "@/lib/seo";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
export const metadata: Metadata = pageMetadata({
|
||||
title: "Blog - Curated Bitcoin Content from Nostr",
|
||||
description:
|
||||
"Read curated Bitcoin articles from the Nostr network. Education, technical analysis, and community insights from the Belgian Bitcoin Embassy.",
|
||||
openGraph: {
|
||||
title: "Blog - Belgian Bitcoin Embassy",
|
||||
description:
|
||||
"Curated Bitcoin content from the Nostr network. Education, analysis, and insights.",
|
||||
},
|
||||
alternates: { canonical: "/blog" },
|
||||
};
|
||||
path: "/blog",
|
||||
layout: true,
|
||||
});
|
||||
|
||||
export default function BlogLayout({ children }: { children: React.ReactNode }) {
|
||||
return children;
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
import type { Metadata } from "next";
|
||||
import { pageMetadata } from "@/lib/seo";
|
||||
import { BreadcrumbJsonLd } from "@/components/public/JsonLd";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "Message Board — Pay with Lightning",
|
||||
export const metadata: Metadata = pageMetadata({
|
||||
title: "Message Board - Pay with Lightning",
|
||||
description:
|
||||
"Post a public message on the Belgian Bitcoin Embassy board. Pay a small Lightning invoice via LNbits to publish.",
|
||||
openGraph: {
|
||||
title: "Message Board — Belgian Bitcoin Embassy",
|
||||
description: "Pay with Lightning to post a message.",
|
||||
},
|
||||
alternates: { canonical: "/board" },
|
||||
};
|
||||
path: "/board",
|
||||
layout: true,
|
||||
});
|
||||
|
||||
export default function BoardLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import type { Metadata } from "next";
|
||||
import { pageMetadata } from "@/lib/seo";
|
||||
import { BreadcrumbJsonLd } from "@/components/public/JsonLd";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
export const metadata: Metadata = pageMetadata({
|
||||
title: "Community - Connect with Belgian Bitcoiners",
|
||||
description:
|
||||
"Join the Belgian Bitcoin Embassy community on Telegram, Nostr, X, YouTube, Discord, and LinkedIn. Connect with Bitcoiners across Belgium.",
|
||||
openGraph: {
|
||||
title: "Community - Belgian Bitcoin Embassy",
|
||||
description:
|
||||
"Connect with Belgian Bitcoiners across every platform.",
|
||||
},
|
||||
alternates: { canonical: "/community" },
|
||||
};
|
||||
path: "/community",
|
||||
layout: true,
|
||||
});
|
||||
|
||||
export default function CommunityLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
|
||||
@@ -1,18 +1,9 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { api } from "@/lib/api";
|
||||
import { PageHeader, PageShell } from "@/components/public/PageLayout";
|
||||
import { CommunityLinksSection } from "@/components/public/CommunityLinksSection";
|
||||
import { fetchPublicSettings } from "@/lib/seo";
|
||||
|
||||
export default function CommunityPage() {
|
||||
const [settings, setSettings] = useState<Record<string, string>>({});
|
||||
|
||||
useEffect(() => {
|
||||
api.getPublicSettings()
|
||||
.then((data) => setSettings(data))
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
export default async function CommunityPage() {
|
||||
const settings = await fetchPublicSettings();
|
||||
|
||||
return (
|
||||
<PageShell>
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
import type { Metadata } from "next";
|
||||
import { fetchPublicSettings, pageMetadata } from "@/lib/seo";
|
||||
import { Container, PageHeader, PageShell } from "@/components/public/PageLayout";
|
||||
import { ContactChannelGrid } from "@/components/public/ContactChannelGrid";
|
||||
import { BreadcrumbJsonLd } from "@/components/public/JsonLd";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
export const metadata: Metadata = pageMetadata({
|
||||
title: "Contact Us",
|
||||
description:
|
||||
"Get in touch with the Belgian Bitcoin Embassy community through Telegram, Nostr, or X. Join our monthly Bitcoin meetups in Belgium.",
|
||||
openGraph: {
|
||||
title: "Contact the Belgian Bitcoin Embassy",
|
||||
description:
|
||||
"Reach the Belgian Bitcoin community through our decentralized channels.",
|
||||
},
|
||||
alternates: { canonical: "/contact" },
|
||||
};
|
||||
path: "/contact",
|
||||
});
|
||||
|
||||
export default function ContactPage() {
|
||||
export default async function ContactPage() {
|
||||
const settings = await fetchPublicSettings();
|
||||
return (
|
||||
<>
|
||||
<BreadcrumbJsonLd
|
||||
@@ -30,7 +27,7 @@ export default function ContactPage() {
|
||||
description="The best way to reach us is through our community channels. We are a decentralized community, so there is no central office or email inbox."
|
||||
/>
|
||||
<Container>
|
||||
<ContactChannelGrid />
|
||||
<ContactChannelGrid settings={settings} />
|
||||
</Container>
|
||||
</PageShell>
|
||||
</>
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
import Link from "next/link";
|
||||
import { MapPin, Clock, Calendar, ExternalLink, Building2 } from "lucide-react";
|
||||
import { buttonClass } from "@/components/ui/Button";
|
||||
import { DateBadge } from "@/components/public/MeetupCard";
|
||||
import { BackLink, Container, PageShell } from "@/components/public/PageLayout";
|
||||
import { UpcomingEventsCarousel } from "@/components/public/UpcomingEventsCarousel";
|
||||
import { formatMeetupCivilDate, formatMeetupCivilDateLong, getMeetupStartUtc } from "@/lib/meetupEventTime";
|
||||
import type { MeetupDetail } from "@/lib/server/data";
|
||||
|
||||
const URL_PATTERN = /https?:\/\/[^\s<>"']+/gi;
|
||||
|
||||
function splitTrailingPunctuation(value: string) {
|
||||
let end = value.length;
|
||||
|
||||
while (end > 0 && /[.,!?;:]/.test(value[end - 1])) end -= 1;
|
||||
|
||||
while (
|
||||
end > 0 &&
|
||||
value[end - 1] === ")" &&
|
||||
(value.slice(0, end).match(/\)/g)?.length ?? 0) >
|
||||
(value.slice(0, end).match(/\(/g)?.length ?? 0)
|
||||
) {
|
||||
end -= 1;
|
||||
}
|
||||
|
||||
return [value.slice(0, end), value.slice(end)] as const;
|
||||
}
|
||||
|
||||
function LinkifiedDescription({ text }: { text: string }) {
|
||||
const content: React.ReactNode[] = [];
|
||||
let previousEnd = 0;
|
||||
|
||||
for (const match of text.matchAll(URL_PATTERN)) {
|
||||
const start = match.index;
|
||||
const matchedText = match[0];
|
||||
const [url, trailingPunctuation] = splitTrailingPunctuation(matchedText);
|
||||
|
||||
if (start > previousEnd) content.push(text.slice(previousEnd, start));
|
||||
|
||||
content.push(
|
||||
<a
|
||||
key={`${start}-${url}`}
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="max-w-full text-primary underline underline-offset-4 hover:opacity-80 [overflow-wrap:anywhere] [word-break:break-word]"
|
||||
>
|
||||
{url}
|
||||
</a>
|
||||
);
|
||||
|
||||
if (trailingPunctuation) content.push(trailingPunctuation);
|
||||
previousEnd = start + matchedText.length;
|
||||
}
|
||||
|
||||
if (previousEnd < text.length) content.push(text.slice(previousEnd));
|
||||
|
||||
return <>{content}</>;
|
||||
}
|
||||
|
||||
// Rendered on the server so crawlers get the full event without running JS.
|
||||
// Only the "more upcoming events" carousel hydrates on the client.
|
||||
export default function EventDetail({ meetup }: { meetup: MeetupDetail }) {
|
||||
const start = getMeetupStartUtc(meetup.date, meetup.time || "00:00");
|
||||
const isPast = !Number.isNaN(start.getTime()) && start < new Date();
|
||||
const civil = formatMeetupCivilDate(meetup.date);
|
||||
|
||||
return (
|
||||
<PageShell>
|
||||
<Container width="narrow" className="min-w-0 pt-8 md:pt-12">
|
||||
<BackLink href="/events" className="mb-8 md:mb-10">
|
||||
All events
|
||||
</BackLink>
|
||||
|
||||
<header className="mb-8 flex items-start gap-5">
|
||||
<DateBadge month={civil?.monthShort ?? ""} day={civil?.day ?? ""} size="lg" muted={isPast} />
|
||||
<div className="min-w-0">
|
||||
<span className={isPast ? "badge badge-muted mb-3" : "badge mb-3"}>
|
||||
{isPast ? "Past event" : "Upcoming"}
|
||||
</span>
|
||||
<h1 className="max-w-full text-3xl font-black leading-tight tracking-tight text-on-surface [overflow-wrap:anywhere] md:text-5xl">
|
||||
{meetup.title}
|
||||
</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<dl className="mb-10 flex min-w-0 max-w-full flex-wrap gap-x-6 gap-y-3 border-y border-white/[0.06] py-5 text-sm text-on-surface-variant">
|
||||
<div className="flex items-center gap-2">
|
||||
<dt>
|
||||
<Calendar size={15} className="shrink-0 text-on-surface-variant/60" aria-hidden />
|
||||
<span className="sr-only">Date</span>
|
||||
</dt>
|
||||
<dd>{formatMeetupCivilDateLong(meetup.date)}</dd>
|
||||
</div>
|
||||
{meetup.time && (
|
||||
<div className="flex items-center gap-2">
|
||||
<dt>
|
||||
<Clock size={15} className="shrink-0 text-on-surface-variant/60" aria-hidden />
|
||||
<span className="sr-only">Time</span>
|
||||
</dt>
|
||||
<dd>{meetup.time}</dd>
|
||||
</div>
|
||||
)}
|
||||
{meetup.location && (
|
||||
<div className="flex min-w-0 max-w-full items-center gap-2">
|
||||
<dt>
|
||||
<MapPin size={15} className="shrink-0 text-on-surface-variant/60" aria-hidden />
|
||||
<span className="sr-only">Location</span>
|
||||
</dt>
|
||||
<dd className="min-w-0 max-w-full [overflow-wrap:anywhere]">{meetup.location}</dd>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex min-w-0 max-w-full items-center gap-2">
|
||||
<dt>
|
||||
<Building2 size={15} className="shrink-0 text-on-surface-variant/60" aria-hidden />
|
||||
<span className="sr-only">Organizer</span>
|
||||
</dt>
|
||||
<dd className="min-w-0 max-w-full [overflow-wrap:anywhere]">
|
||||
{meetup.organizer?.slug ? (
|
||||
<Link
|
||||
href={`/events/organizer/${meetup.organizer.slug}`}
|
||||
className="font-medium text-primary underline-offset-4 hover:underline"
|
||||
>
|
||||
{meetup.organizer.name || "Belgian Bitcoin Embassy"}
|
||||
</Link>
|
||||
) : (
|
||||
meetup.organizer?.name || "Belgian Bitcoin Embassy"
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
{meetup.imageId && (
|
||||
<div className="mb-10 aspect-video overflow-hidden rounded-xl border border-white/[0.06] bg-zinc-900">
|
||||
<img
|
||||
src={`/media/${meetup.imageId}`}
|
||||
alt={meetup.title}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{meetup.description && (
|
||||
<p className="mb-12 max-w-full whitespace-pre-wrap text-base leading-relaxed text-on-surface-variant [overflow-wrap:anywhere] md:text-lg">
|
||||
<LinkifiedDescription text={meetup.description} />
|
||||
</p>
|
||||
)}
|
||||
|
||||
{meetup.link && (
|
||||
<a
|
||||
href={meetup.link}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className={buttonClass({ size: "lg" })}
|
||||
>
|
||||
Register for this event <ExternalLink size={16} aria-hidden />
|
||||
</a>
|
||||
)}
|
||||
|
||||
<UpcomingEventsCarousel excludeId={meetup.id} />
|
||||
</Container>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
@@ -1,212 +0,0 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { MapPin, Clock, Calendar, ExternalLink, Building2 } from "lucide-react";
|
||||
import { api } from "@/lib/api";
|
||||
import { buttonClass } from "@/components/ui/Button";
|
||||
import { DateBadge } from "@/components/public/MeetupCard";
|
||||
import { BackLink, Container, ErrorState, PageShell } from "@/components/public/PageLayout";
|
||||
import { UpcomingEventsCarousel } from "@/components/public/UpcomingEventsCarousel";
|
||||
import { formatMeetupCivilDate, formatMeetupCivilDateLong, getMeetupStartUtc } from "@/lib/meetupEventTime";
|
||||
|
||||
const URL_PATTERN = /https?:\/\/[^\s<>"']+/gi;
|
||||
|
||||
function splitTrailingPunctuation(value: string) {
|
||||
let end = value.length;
|
||||
|
||||
while (end > 0 && /[.,!?;:]/.test(value[end - 1])) end -= 1;
|
||||
|
||||
while (
|
||||
end > 0 &&
|
||||
value[end - 1] === ")" &&
|
||||
(value.slice(0, end).match(/\)/g)?.length ?? 0) >
|
||||
(value.slice(0, end).match(/\(/g)?.length ?? 0)
|
||||
) {
|
||||
end -= 1;
|
||||
}
|
||||
|
||||
return [value.slice(0, end), value.slice(end)] as const;
|
||||
}
|
||||
|
||||
function LinkifiedDescription({ text }: { text: string }) {
|
||||
const content: React.ReactNode[] = [];
|
||||
let previousEnd = 0;
|
||||
|
||||
for (const match of text.matchAll(URL_PATTERN)) {
|
||||
const start = match.index;
|
||||
const matchedText = match[0];
|
||||
const [url, trailingPunctuation] = splitTrailingPunctuation(matchedText);
|
||||
|
||||
if (start > previousEnd) content.push(text.slice(previousEnd, start));
|
||||
|
||||
content.push(
|
||||
<a
|
||||
key={`${start}-${url}`}
|
||||
href={url}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="max-w-full text-primary underline underline-offset-4 hover:opacity-80 [overflow-wrap:anywhere] [word-break:break-word]"
|
||||
>
|
||||
{url}
|
||||
</a>
|
||||
);
|
||||
|
||||
if (trailingPunctuation) content.push(trailingPunctuation);
|
||||
previousEnd = start + matchedText.length;
|
||||
}
|
||||
|
||||
if (previousEnd < text.length) content.push(text.slice(previousEnd));
|
||||
|
||||
return <>{content}</>;
|
||||
}
|
||||
|
||||
function EventSkeleton() {
|
||||
return (
|
||||
<div aria-hidden>
|
||||
<div className="mb-8 flex items-start gap-5">
|
||||
<div className="skeleton h-[70px] w-16 rounded-lg" />
|
||||
<div className="flex-1 space-y-3 pt-1">
|
||||
<div className="skeleton h-5 w-24 rounded-full" />
|
||||
<div className="skeleton h-9 w-3/4" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="skeleton mb-10 h-4 w-1/2" />
|
||||
<div className="space-y-3">
|
||||
{[90, 80, 95, 70].map((w, i) => (
|
||||
<div key={i} className="skeleton h-4" style={{ width: `${w}%` }} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function EventDetailClient({ id }: { id: string }) {
|
||||
const [meetup, setMeetup] = useState<any>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!id) return;
|
||||
setLoading(true);
|
||||
api
|
||||
.getMeetup(id)
|
||||
.then(setMeetup)
|
||||
.catch((err) => setError(err.message))
|
||||
.finally(() => setLoading(false));
|
||||
}, [id]);
|
||||
|
||||
const isPast = meetup
|
||||
? (() => {
|
||||
const start = getMeetupStartUtc(meetup.date, meetup.time || "00:00");
|
||||
return !Number.isNaN(start.getTime()) && start < new Date();
|
||||
})()
|
||||
: false;
|
||||
|
||||
const civil = meetup ? formatMeetupCivilDate(meetup.date) : null;
|
||||
|
||||
return (
|
||||
<PageShell>
|
||||
<Container width="narrow" className="min-w-0 pt-8 md:pt-12">
|
||||
<BackLink href="/events" className="mb-8 md:mb-10">
|
||||
All events
|
||||
</BackLink>
|
||||
|
||||
{loading && <EventSkeleton />}
|
||||
|
||||
{error && <ErrorState>Failed to load event: {error}</ErrorState>}
|
||||
|
||||
{!loading && !error && meetup && (
|
||||
<>
|
||||
<header className="mb-8 flex items-start gap-5">
|
||||
<DateBadge month={civil?.monthShort ?? ""} day={civil?.day ?? ""} size="lg" muted={isPast} />
|
||||
<div className="min-w-0">
|
||||
<span className={isPast ? "badge badge-muted mb-3" : "badge mb-3"}>
|
||||
{isPast ? "Past event" : "Upcoming"}
|
||||
</span>
|
||||
<h1 className="max-w-full text-3xl font-black leading-tight tracking-tight text-on-surface [overflow-wrap:anywhere] md:text-5xl">
|
||||
{meetup.title}
|
||||
</h1>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<dl className="mb-10 flex min-w-0 max-w-full flex-wrap gap-x-6 gap-y-3 border-y border-white/[0.06] py-5 text-sm text-on-surface-variant">
|
||||
<div className="flex items-center gap-2">
|
||||
<dt>
|
||||
<Calendar size={15} className="shrink-0 text-on-surface-variant/60" aria-hidden />
|
||||
<span className="sr-only">Date</span>
|
||||
</dt>
|
||||
<dd>{formatMeetupCivilDateLong(meetup.date)}</dd>
|
||||
</div>
|
||||
{meetup.time && (
|
||||
<div className="flex items-center gap-2">
|
||||
<dt>
|
||||
<Clock size={15} className="shrink-0 text-on-surface-variant/60" aria-hidden />
|
||||
<span className="sr-only">Time</span>
|
||||
</dt>
|
||||
<dd>{meetup.time}</dd>
|
||||
</div>
|
||||
)}
|
||||
{meetup.location && (
|
||||
<div className="flex min-w-0 max-w-full items-center gap-2">
|
||||
<dt>
|
||||
<MapPin size={15} className="shrink-0 text-on-surface-variant/60" aria-hidden />
|
||||
<span className="sr-only">Location</span>
|
||||
</dt>
|
||||
<dd className="min-w-0 max-w-full [overflow-wrap:anywhere]">{meetup.location}</dd>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex min-w-0 max-w-full items-center gap-2">
|
||||
<dt>
|
||||
<Building2 size={15} className="shrink-0 text-on-surface-variant/60" aria-hidden />
|
||||
<span className="sr-only">Organizer</span>
|
||||
</dt>
|
||||
<dd className="min-w-0 max-w-full [overflow-wrap:anywhere]">
|
||||
{meetup.organizer?.slug ? (
|
||||
<Link
|
||||
href={`/events/organizer/${meetup.organizer.slug}`}
|
||||
className="font-medium text-primary underline-offset-4 hover:underline"
|
||||
>
|
||||
{meetup.organizer.name || "Belgian Bitcoin Embassy"}
|
||||
</Link>
|
||||
) : (
|
||||
meetup.organizer?.name || "Belgian Bitcoin Embassy"
|
||||
)}
|
||||
</dd>
|
||||
</div>
|
||||
</dl>
|
||||
|
||||
{meetup.imageId && (
|
||||
<div className="mb-10 aspect-video overflow-hidden rounded-xl border border-white/[0.06] bg-zinc-900">
|
||||
<img
|
||||
src={`/media/${meetup.imageId}`}
|
||||
alt={meetup.title}
|
||||
className="h-full w-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{meetup.description && (
|
||||
<p className="mb-12 max-w-full whitespace-pre-wrap text-base leading-relaxed text-on-surface-variant [overflow-wrap:anywhere] md:text-lg">
|
||||
<LinkifiedDescription text={meetup.description} />
|
||||
</p>
|
||||
)}
|
||||
|
||||
{meetup.link && (
|
||||
<a
|
||||
href={meetup.link}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className={buttonClass({ size: "lg" })}
|
||||
>
|
||||
Register for this event <ExternalLink size={16} aria-hidden />
|
||||
</a>
|
||||
)}
|
||||
|
||||
<UpcomingEventsCarousel excludeId={meetup.id} />
|
||||
</>
|
||||
)}
|
||||
</Container>
|
||||
</PageShell>
|
||||
);
|
||||
}
|
||||
@@ -1,68 +1,55 @@
|
||||
import type { Metadata } from "next";
|
||||
import EventDetailClient from "./EventDetailClient";
|
||||
import { notFound } from "next/navigation";
|
||||
import EventDetail from "./EventDetail";
|
||||
import { EventJsonLd, BreadcrumbJsonLd } from "@/components/public/JsonLd";
|
||||
import { apiUrl } from "@/lib/api-base";
|
||||
import { getMeetupStartUtc, getMeetupEndUtc } from "@/lib/meetupEventTime";
|
||||
import { getMeetup } from "@/lib/server/data";
|
||||
import { pageMetadata, SITE_NAME, SITE_URL } from "@/lib/seo";
|
||||
import { toMetaDescription, toPlainText } from "@/lib/text";
|
||||
|
||||
async function fetchEvent(id: string) {
|
||||
try {
|
||||
const res = await fetch(apiUrl(`/meetups/${id}`), {
|
||||
next: { revalidate: 300 },
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
return res.json();
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
// Incremental static regeneration: rebuilt in the background at most every 5 minutes.
|
||||
export const revalidate = 300;
|
||||
|
||||
// No paths at build time; each page is rendered on its first visit, then cached.
|
||||
export function generateStaticParams() {
|
||||
return [];
|
||||
}
|
||||
|
||||
interface Props {
|
||||
params: Promise<{ id: string }>;
|
||||
params: { id: string };
|
||||
}
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { id } = await params;
|
||||
const event = await fetchEvent(id);
|
||||
const event = await getMeetup(params.id);
|
||||
if (!event) {
|
||||
return { title: "Event Not Found" };
|
||||
}
|
||||
|
||||
const orgLabel = event.organizer?.name || "Belgian Bitcoin Embassy";
|
||||
const orgLabel = event.organizer?.name || SITE_NAME;
|
||||
const description =
|
||||
event.description?.slice(0, 160) ||
|
||||
toMetaDescription(event.description) ||
|
||||
`Bitcoin meetup: ${event.title}${event.location ? ` in ${event.location}` : ""}. Organized by ${orgLabel}.`;
|
||||
|
||||
const ogImage = event.imageId
|
||||
? `/media/${event.imageId}`
|
||||
: `/og?title=${encodeURIComponent(event.title)}&type=event`;
|
||||
|
||||
return {
|
||||
return pageMetadata({
|
||||
title: event.title,
|
||||
description,
|
||||
openGraph: {
|
||||
type: "article",
|
||||
title: event.title,
|
||||
description,
|
||||
images: [{ url: ogImage, width: 1200, height: 630, alt: event.title }],
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: event.title,
|
||||
description,
|
||||
images: [ogImage],
|
||||
},
|
||||
alternates: { canonical: `/events/${id}` },
|
||||
};
|
||||
path: `/events/${params.id}`,
|
||||
image: ogImage,
|
||||
type: "article",
|
||||
});
|
||||
}
|
||||
|
||||
export default async function EventDetailPage({ params }: Props) {
|
||||
const { id } = await params;
|
||||
const event = await fetchEvent(id);
|
||||
const siteUrl = process.env.NEXT_PUBLIC_SITE_URL || "https://belgianbitcoinembassy.org";
|
||||
const event = await getMeetup(params.id);
|
||||
if (!event) notFound();
|
||||
|
||||
let startDate = event?.date;
|
||||
let startDate = event.date;
|
||||
let endDate: string | undefined;
|
||||
if (event?.date) {
|
||||
if (event.date) {
|
||||
const start = getMeetupStartUtc(event.date, event.time || "00:00");
|
||||
if (!Number.isNaN(start.getTime())) startDate = start.toISOString();
|
||||
const end = getMeetupEndUtc(event.date, event.time || "");
|
||||
@@ -71,33 +58,29 @@ export default async function EventDetailPage({ params }: Props) {
|
||||
|
||||
return (
|
||||
<>
|
||||
{event && (
|
||||
<>
|
||||
<EventJsonLd
|
||||
name={event.title}
|
||||
description={event.description}
|
||||
startDate={startDate}
|
||||
endDate={endDate}
|
||||
location={event.location}
|
||||
url={`${siteUrl}/events/${id}`}
|
||||
imageUrl={event.imageId ? `${siteUrl}/media/${event.imageId}` : undefined}
|
||||
organizerName={event.organizer?.name}
|
||||
organizerUrl={
|
||||
event.organizer?.slug
|
||||
? `${siteUrl}/events/organizer/${event.organizer.slug}`
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
<BreadcrumbJsonLd
|
||||
items={[
|
||||
{ name: "Home", href: "/" },
|
||||
{ name: "Events", href: "/events" },
|
||||
{ name: event.title, href: `/events/${id}` },
|
||||
]}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<EventDetailClient id={id} />
|
||||
<EventJsonLd
|
||||
name={event.title}
|
||||
description={toPlainText(event.description) || undefined}
|
||||
startDate={startDate}
|
||||
endDate={endDate}
|
||||
location={event.location}
|
||||
url={`${SITE_URL}/events/${params.id}`}
|
||||
imageUrl={event.imageId ? `${SITE_URL}/media/${event.imageId}` : undefined}
|
||||
organizerName={event.organizer?.name}
|
||||
organizerUrl={
|
||||
event.organizer?.slug
|
||||
? `${SITE_URL}/events/organizer/${event.organizer.slug}`
|
||||
: undefined
|
||||
}
|
||||
/>
|
||||
<BreadcrumbJsonLd
|
||||
items={[
|
||||
{ name: "Home", href: "/" },
|
||||
{ name: "Events", href: "/events" },
|
||||
{ name: event.title, href: `/events/${params.id}` },
|
||||
]}
|
||||
/>
|
||||
<EventDetail meetup={event} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,14 @@
|
||||
import type { Metadata } from "next";
|
||||
import { pageMetadata } from "@/lib/seo";
|
||||
import { BreadcrumbJsonLd } from "@/components/public/JsonLd";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
export const metadata: Metadata = pageMetadata({
|
||||
title: "Events - Bitcoin Meetups in Belgium",
|
||||
description:
|
||||
"Browse upcoming and past Bitcoin meetups in Belgium organized by the Belgian Bitcoin Embassy. Monthly gatherings for education and community.",
|
||||
openGraph: {
|
||||
title: "Events - Belgian Bitcoin Embassy",
|
||||
description:
|
||||
"Upcoming and past Bitcoin meetups in Belgium. Join the community.",
|
||||
},
|
||||
alternates: { canonical: "/events" },
|
||||
};
|
||||
path: "/events",
|
||||
layout: true,
|
||||
});
|
||||
|
||||
export default function EventsLayout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { Metadata } from "next";
|
||||
import { pageMetadata } from "@/lib/seo";
|
||||
import { notFound } from "next/navigation";
|
||||
import OrganizerEventsClient from "./OrganizerEventsClient";
|
||||
import { apiUrl } from "@/lib/api-base";
|
||||
@@ -25,11 +26,11 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
if (!org) {
|
||||
return { title: "Organizer not found" };
|
||||
}
|
||||
return {
|
||||
return pageMetadata({
|
||||
title: `Events by ${org.name}`,
|
||||
description: `Upcoming and past Bitcoin events organized by ${org.name} in Belgium.`,
|
||||
alternates: { canonical: `/events/organizer/${slug}` },
|
||||
};
|
||||
path: `/events/organizer/${slug}`,
|
||||
});
|
||||
}
|
||||
|
||||
export default async function OrganizerArchivePage({ params }: Props) {
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import type { Metadata } from "next";
|
||||
import { pageMetadata } from "@/lib/seo";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
export const metadata: Metadata = pageMetadata({
|
||||
title: "FAQ - Frequently Asked Questions",
|
||||
description:
|
||||
"Everything you need to know about the Belgian Bitcoin Embassy. Common questions about Bitcoin meetups, community, education, and how to get involved.",
|
||||
openGraph: {
|
||||
title: "FAQ - Belgian Bitcoin Embassy",
|
||||
description:
|
||||
"Answers to common questions about the Belgian Bitcoin Embassy.",
|
||||
},
|
||||
alternates: { canonical: "/faq" },
|
||||
};
|
||||
path: "/faq",
|
||||
layout: true,
|
||||
});
|
||||
|
||||
export default function FaqLayout({ children }: { children: React.ReactNode }) {
|
||||
return children;
|
||||
|
||||
+38
-53
@@ -1,81 +1,66 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { Navbar } from "@/components/public/Navbar";
|
||||
import { HeroSection } from "@/components/public/HeroSection";
|
||||
import { AboutSection } from "@/components/public/AboutSection";
|
||||
import { CommunityLinksSection } from "@/components/public/CommunityLinksSection";
|
||||
import { MeetupsSection } from "@/components/public/MeetupsSection";
|
||||
import { BlogPreviewSection } from "@/components/public/BlogPreviewSection";
|
||||
import { FAQSection } from "@/components/public/FAQSection";
|
||||
import { FinalCTASection } from "@/components/public/FinalCTASection";
|
||||
import { Footer } from "@/components/public/Footer";
|
||||
import { api } from "@/lib/api";
|
||||
import { formatMeetupCivilDate, getMeetupStartUtc, isMeetupOver } from "@/lib/meetupEventTime";
|
||||
import { formatMeetupCivilDate } from "@/lib/meetupEventTime";
|
||||
import { selectHomepageMeetups } from "@/lib/meetupsData";
|
||||
import { fetchPublicSettings } from "@/lib/seo";
|
||||
import { getLatestPosts, getMeetups } from "@/lib/server/data";
|
||||
|
||||
export default function HomePage() {
|
||||
const [meetup, setMeetup] = useState<any>(null);
|
||||
const [allMeetups, setAllMeetups] = useState<any[]>([]);
|
||||
const [meetupsLoading, setMeetupsLoading] = useState(true);
|
||||
const [settings, setSettings] = useState<Record<string, string>>({});
|
||||
// Server-rendered so crawlers see the next meetups and latest posts as real
|
||||
// links. Regenerated in the background at most every 5 minutes.
|
||||
export const revalidate = 300;
|
||||
|
||||
useEffect(() => {
|
||||
api.getMeetups()
|
||||
.then((data: any) => {
|
||||
const all = Array.isArray(data) ? data : data?.meetups ?? [];
|
||||
const now = new Date();
|
||||
// Keep only PUBLISHED events with a future start (Brussels wall time → UTC), sorted closest-first
|
||||
const upcoming = all
|
||||
.filter((m: any) => {
|
||||
if (m.status !== "PUBLISHED" || !m.date) return false;
|
||||
const start = getMeetupStartUtc(m.date, m.time || "00:00");
|
||||
return !Number.isNaN(start.getTime()) && start > now;
|
||||
})
|
||||
.sort(
|
||||
(a: any, b: any) =>
|
||||
getMeetupStartUtc(a.date, a.time || "00:00").getTime() -
|
||||
getMeetupStartUtc(b.date, b.time || "00:00").getTime()
|
||||
);
|
||||
setAllMeetups(upcoming);
|
||||
// The hero shows the featured event while it isn't over, else the next one up.
|
||||
const featured = all.find(
|
||||
(m: any) => m.featured && m.status === "PUBLISHED" && m.date && !isMeetupOver(m.date, m.time || "")
|
||||
);
|
||||
const hero = featured ?? upcoming[0];
|
||||
if (hero) setMeetup(hero);
|
||||
})
|
||||
.catch(() => {})
|
||||
.finally(() => setMeetupsLoading(false));
|
||||
export default async function HomePage() {
|
||||
const [meetups, posts, settings] = await Promise.all([
|
||||
getMeetups(),
|
||||
getLatestPosts(3),
|
||||
fetchPublicSettings(),
|
||||
]);
|
||||
|
||||
api.getPublicSettings()
|
||||
.then((data) => setSettings(data))
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
const featuredCivil = meetup ? formatMeetupCivilDate(meetup.date) : null;
|
||||
const meetupProps = meetup
|
||||
const { upcoming, hero } = selectHomepageMeetups(meetups);
|
||||
const heroCivil = hero ? formatMeetupCivilDate(hero.date) : null;
|
||||
const heroProps = hero
|
||||
? {
|
||||
id: meetup.id,
|
||||
month: featuredCivil?.monthShort ?? "",
|
||||
day: featuredCivil?.day ?? "",
|
||||
title: meetup.title,
|
||||
location: meetup.location,
|
||||
time: meetup.time,
|
||||
link: meetup.link,
|
||||
id: hero.id,
|
||||
month: heroCivil?.monthShort ?? "",
|
||||
day: heroCivil?.day ?? "",
|
||||
title: hero.title,
|
||||
location: hero.location,
|
||||
time: hero.time,
|
||||
link: hero.link ?? undefined,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const meetupCards = upcoming.map((m) => ({
|
||||
id: m.id,
|
||||
title: m.title,
|
||||
date: m.date,
|
||||
time: m.time,
|
||||
location: m.location,
|
||||
link: m.link ?? undefined,
|
||||
description: m.description,
|
||||
organizer: m.organizer?.name ? { name: m.organizer.name, slug: m.organizer.slug } : undefined,
|
||||
}));
|
||||
|
||||
return (
|
||||
<>
|
||||
<Navbar />
|
||||
<main id="main">
|
||||
<div id="meetup">
|
||||
<HeroSection meetup={meetupProps} loading={meetupsLoading} />
|
||||
<HeroSection meetup={heroProps} />
|
||||
</div>
|
||||
<AboutSection />
|
||||
<CommunityLinksSection settings={settings} />
|
||||
<div id="upcoming-meetups">
|
||||
<MeetupsSection meetups={allMeetups} loading={meetupsLoading} />
|
||||
<MeetupsSection meetups={meetupCards} />
|
||||
</div>
|
||||
<BlogPreviewSection posts={posts} />
|
||||
<FAQSection />
|
||||
<FinalCTASection telegramLink={settings.telegram_link} />
|
||||
</main>
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
import type { Metadata } from "next";
|
||||
import { pageMetadata } from "@/lib/seo";
|
||||
import Link from "next/link";
|
||||
import { Container, PageHeader, PageShell } from "@/components/public/PageLayout";
|
||||
import { BreadcrumbJsonLd } from "@/components/public/JsonLd";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
export const metadata: Metadata = pageMetadata({
|
||||
title: "Privacy Policy",
|
||||
description:
|
||||
"GDPR-oriented privacy policy for the Belgian Bitcoin Embassy. Learn what data we process, why we process it, and your rights.",
|
||||
openGraph: {
|
||||
title: "Privacy Policy - Belgian Bitcoin Embassy",
|
||||
description:
|
||||
"How we process data for account access, moderation, and community features, with clear GDPR rights and transparency.",
|
||||
},
|
||||
alternates: { canonical: "/privacy" },
|
||||
};
|
||||
path: "/privacy",
|
||||
});
|
||||
|
||||
export default function PrivacyPage() {
|
||||
return (
|
||||
|
||||
+18
-10
@@ -4,6 +4,10 @@ import { apiUrl } from "@/lib/api-base";
|
||||
const siteUrl =
|
||||
process.env.NEXT_PUBLIC_SITE_URL || "https://belgianbitcoinembassy.org";
|
||||
|
||||
// Regenerate hourly even if a fetch failed at build time (a failed fetch
|
||||
// records no revalidate period, which would freeze the sitemap).
|
||||
export const revalidate = 3600;
|
||||
|
||||
async function fetchJson<T>(path: string): Promise<T | null> {
|
||||
try {
|
||||
const res = await fetch(apiUrl(path), { next: { revalidate: 3600 } });
|
||||
@@ -15,16 +19,19 @@ async function fetchJson<T>(path: string): Promise<T | null> {
|
||||
}
|
||||
|
||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
// Static pages carry no lastModified: we have no real last-changed date for
|
||||
// them, and a request-time timestamp would tell crawlers they always changed.
|
||||
const staticRoutes: MetadataRoute.Sitemap = [
|
||||
{ url: siteUrl, lastModified: new Date(), changeFrequency: "weekly", priority: 1.0 },
|
||||
{ url: `${siteUrl}/blog`, lastModified: new Date(), changeFrequency: "daily", priority: 0.9 },
|
||||
{ url: `${siteUrl}/events`, lastModified: new Date(), changeFrequency: "weekly", priority: 0.9 },
|
||||
{ url: `${siteUrl}/videos`, lastModified: new Date(), changeFrequency: "weekly", priority: 0.8 },
|
||||
{ url: `${siteUrl}/community`, lastModified: new Date(), changeFrequency: "monthly", priority: 0.7 },
|
||||
{ url: `${siteUrl}/contact`, lastModified: new Date(), changeFrequency: "monthly", priority: 0.5 },
|
||||
{ url: `${siteUrl}/faq`, lastModified: new Date(), changeFrequency: "monthly", priority: 0.6 },
|
||||
{ url: `${siteUrl}/privacy`, lastModified: new Date(), changeFrequency: "yearly", priority: 0.3 },
|
||||
{ url: `${siteUrl}/terms`, lastModified: new Date(), changeFrequency: "yearly", priority: 0.3 },
|
||||
{ url: siteUrl, changeFrequency: "weekly", priority: 1.0 },
|
||||
{ url: `${siteUrl}/blog`, changeFrequency: "daily", priority: 0.9 },
|
||||
{ url: `${siteUrl}/events`, changeFrequency: "weekly", priority: 0.9 },
|
||||
{ url: `${siteUrl}/videos`, changeFrequency: "weekly", priority: 0.8 },
|
||||
{ url: `${siteUrl}/board`, changeFrequency: "daily", priority: 0.6 },
|
||||
{ url: `${siteUrl}/community`, changeFrequency: "monthly", priority: 0.7 },
|
||||
{ url: `${siteUrl}/contact`, changeFrequency: "monthly", priority: 0.5 },
|
||||
{ url: `${siteUrl}/faq`, changeFrequency: "monthly", priority: 0.6 },
|
||||
{ url: `${siteUrl}/privacy`, changeFrequency: "yearly", priority: 0.3 },
|
||||
{ url: `${siteUrl}/terms`, changeFrequency: "yearly", priority: 0.3 },
|
||||
];
|
||||
|
||||
const blogRoutes: MetadataRoute.Sitemap = [];
|
||||
@@ -43,7 +50,8 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
const eventRoutes: MetadataRoute.Sitemap = [];
|
||||
const meetups = await fetchJson<any[]>("/meetups");
|
||||
if (Array.isArray(meetups)) {
|
||||
for (const meetup of meetups) {
|
||||
// Only published meetups: the detail page 404s for drafts and cancelled ones.
|
||||
for (const meetup of meetups.filter((m) => m.status === "PUBLISHED")) {
|
||||
eventRoutes.push({
|
||||
url: `${siteUrl}/events/${meetup.id}`,
|
||||
lastModified: meetup.updatedAt || meetup.createdAt,
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
import type { Metadata } from "next";
|
||||
import { pageMetadata } from "@/lib/seo";
|
||||
import Link from "next/link";
|
||||
import { Container, PageHeader, PageShell } from "@/components/public/PageLayout";
|
||||
import { BreadcrumbJsonLd } from "@/components/public/JsonLd";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
export const metadata: Metadata = pageMetadata({
|
||||
title: "Terms of Use",
|
||||
description:
|
||||
"Terms of use for the Belgian Bitcoin Embassy website, including education-only scope, risk warnings, and user responsibilities.",
|
||||
openGraph: {
|
||||
title: "Terms of Use - Belgian Bitcoin Embassy",
|
||||
description:
|
||||
"Terms governing access, risk disclosures, no-investment-advice scope, and liability limits for the Belgian Bitcoin Embassy platform.",
|
||||
},
|
||||
alternates: { canonical: "/terms" },
|
||||
};
|
||||
path: "/terms",
|
||||
});
|
||||
|
||||
export default function TermsPage() {
|
||||
return (
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import type { Metadata } from "next";
|
||||
import { pageMetadata } from "@/lib/seo";
|
||||
import { toMetaDescription } from "@/lib/text";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { ArrowRight, Calendar, Clock, ExternalLink, Mic, Users } from "lucide-react";
|
||||
@@ -27,8 +29,8 @@ interface Props {
|
||||
}
|
||||
|
||||
function summary(video: VideoDetail): string {
|
||||
const text = video.description.replace(/\s+/g, " ").trim();
|
||||
if (text) return text.length > 200 ? `${text.slice(0, 197)}…` : text;
|
||||
const text = toMetaDescription(video.description);
|
||||
if (text) return text;
|
||||
return video.speaker
|
||||
? `Watch "${video.title}" by ${video.speaker} on the Belgian Bitcoin Embassy.`
|
||||
: `Watch "${video.title}" on the Belgian Bitcoin Embassy.`;
|
||||
@@ -41,23 +43,13 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const description = summary(video);
|
||||
const image = video.thumbnailUrl || `/og?title=${encodeURIComponent(video.title)}&subtitle=Video`;
|
||||
|
||||
return {
|
||||
return pageMetadata({
|
||||
title: video.title,
|
||||
description,
|
||||
openGraph: {
|
||||
type: "video.other",
|
||||
title: video.title,
|
||||
description,
|
||||
images: [{ url: image, alt: video.title }],
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: video.title,
|
||||
description,
|
||||
images: [image],
|
||||
},
|
||||
alternates: { canonical: `/videos/${video.slug}` },
|
||||
};
|
||||
path: `/videos/${video.slug}`,
|
||||
image,
|
||||
type: "video.other",
|
||||
});
|
||||
}
|
||||
|
||||
export default async function VideoDetailPage({ params }: Props) {
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import type { Metadata } from "next";
|
||||
import { pageMetadata } from "@/lib/seo";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
export const metadata: Metadata = pageMetadata({
|
||||
title: "Bitcoin Videos - Talks, Documentaries, Movies and Tutorials",
|
||||
description:
|
||||
"Watch Bitcoin talks, documentaries, movies and tutorials picked by the Belgian Bitcoin Embassy, plus recordings from our meetups and BBE Productions.",
|
||||
openGraph: {
|
||||
title: "Bitcoin Videos - Belgian Bitcoin Embassy",
|
||||
description: "Bitcoin talks, documentaries, movies, tutorials and meetup recordings, picked by the Belgian Bitcoin community.",
|
||||
},
|
||||
alternates: { canonical: "/videos" },
|
||||
};
|
||||
path: "/videos",
|
||||
layout: true,
|
||||
});
|
||||
|
||||
export default function VideosLayout({ children }: { children: React.ReactNode }) {
|
||||
return children;
|
||||
|
||||
@@ -1,81 +1,63 @@
|
||||
import { ArrowRight } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { ArrowRight } from "lucide-react";
|
||||
import { buttonClass } from "@/components/ui/Button";
|
||||
import { CardGrid, Container, SectionHeader } from "@/components/public/PageLayout";
|
||||
import { formatDateUtc } from "@/lib/utils";
|
||||
import { toMetaDescription } from "@/lib/text";
|
||||
import type { Post } from "@/lib/server/data";
|
||||
|
||||
interface BlogPost {
|
||||
slug: string;
|
||||
title: string;
|
||||
excerpt: string;
|
||||
categories: string[];
|
||||
}
|
||||
// Server-rendered so the homepage links straight to recent articles.
|
||||
export function BlogPreviewSection({ posts }: { posts: Post[] }) {
|
||||
if (posts.length === 0) return null;
|
||||
|
||||
interface BlogPreviewSectionProps {
|
||||
posts?: BlogPost[];
|
||||
}
|
||||
|
||||
export function BlogPreviewSection({ posts }: BlogPreviewSectionProps) {
|
||||
return (
|
||||
<section className="py-24 px-8 border-t border-zinc-800/50">
|
||||
<div className="max-w-6xl mx-auto">
|
||||
<div className="flex justify-between items-end mb-12">
|
||||
<div>
|
||||
<p className="uppercase tracking-[0.2em] text-primary mb-2 font-semibold text-xs">
|
||||
From the network
|
||||
</p>
|
||||
<h2 className="text-3xl font-black tracking-tight">Latest from the Blog</h2>
|
||||
</div>
|
||||
<Link
|
||||
href="/blog"
|
||||
className="hidden md:flex items-center gap-2 text-sm text-primary font-semibold hover:gap-3 transition-all"
|
||||
>
|
||||
View All <ArrowRight size={16} />
|
||||
</Link>
|
||||
</div>
|
||||
<section className="py-16 md:py-20">
|
||||
<Container>
|
||||
<SectionHeader
|
||||
title="Latest from the blog"
|
||||
action={
|
||||
<Link href="/blog" className={buttonClass({ variant: "tertiary", className: "h-9 text-sm" })}>
|
||||
All posts <ArrowRight size={16} aria-hidden />
|
||||
</Link>
|
||||
}
|
||||
/>
|
||||
|
||||
{!posts || posts.length === 0 ? (
|
||||
<p className="text-on-surface-variant text-center py-16 text-sm">
|
||||
No posts yet. Check back soon for curated Bitcoin content.
|
||||
</p>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-3 gap-5">
|
||||
{posts.map((post) => (
|
||||
<CardGrid>
|
||||
{posts.map((post) => {
|
||||
const date = post.publishedAt || post.createdAt;
|
||||
const excerpt = toMetaDescription(post.excerpt, 180);
|
||||
return (
|
||||
<Link
|
||||
key={post.slug}
|
||||
key={post.id}
|
||||
href={`/blog/${post.slug}`}
|
||||
className="group flex flex-col bg-zinc-900 border border-zinc-800 rounded-xl p-6 hover:border-zinc-700 hover:-translate-y-0.5 hover:shadow-xl transition-all duration-200"
|
||||
className="card card-hover group flex flex-col p-6"
|
||||
>
|
||||
{post.categories.length > 0 && (
|
||||
<div className="flex flex-wrap gap-2 mb-4">
|
||||
{post.categories.map((cat) => (
|
||||
<span
|
||||
key={cat}
|
||||
className="text-primary text-[10px] uppercase tracking-widest font-bold"
|
||||
>
|
||||
{cat}
|
||||
</span>
|
||||
{post.categories && post.categories.length > 0 && (
|
||||
<p className="mb-3 flex flex-wrap gap-x-3 text-[11px] font-semibold uppercase tracking-wider text-primary">
|
||||
{post.categories.slice(0, 3).map((pc) => (
|
||||
<span key={pc.category.id}>{pc.category.name}</span>
|
||||
))}
|
||||
</div>
|
||||
</p>
|
||||
)}
|
||||
<h3 className="font-bold text-base mb-3 leading-snug group-hover:text-primary transition-colors">
|
||||
|
||||
<h3 className="mb-2 text-lg font-bold leading-snug text-on-surface transition-colors group-hover:text-primary">
|
||||
{post.title}
|
||||
</h3>
|
||||
<p className="text-on-surface-variant text-sm leading-relaxed mb-5 flex-1 line-clamp-3">
|
||||
{post.excerpt}
|
||||
</p>
|
||||
<span className="text-primary text-xs font-semibold flex items-center gap-1.5 group-hover:gap-2.5 transition-all mt-auto">
|
||||
Read More <ArrowRight size={13} />
|
||||
</span>
|
||||
</Link>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Link
|
||||
href="/blog"
|
||||
className="md:hidden flex items-center justify-center gap-2 text-primary font-semibold mt-8 text-sm"
|
||||
>
|
||||
View All <ArrowRight size={16} />
|
||||
</Link>
|
||||
</div>
|
||||
{excerpt && (
|
||||
<p className="mb-5 line-clamp-3 text-sm leading-relaxed text-on-surface-variant">{excerpt}</p>
|
||||
)}
|
||||
|
||||
{date && (
|
||||
<p className="mt-auto border-t border-white/[0.06] pt-4 text-xs text-on-surface-variant/70">
|
||||
<time dateTime={date}>{formatDateUtc(date)}</time>
|
||||
</p>
|
||||
)}
|
||||
</Link>
|
||||
);
|
||||
})}
|
||||
</CardGrid>
|
||||
</Container>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,9 @@ export function CommunityLinksSection({ settings = {}, showHeader = true, classN
|
||||
|
||||
<div className="grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{PLATFORMS.map((platform) => {
|
||||
const href = settings[platform.settingKey] || "#";
|
||||
const href = settings[platform.settingKey]?.trim();
|
||||
// Skip platforms without a configured URL rather than linking to "#".
|
||||
if (!href) return null;
|
||||
const isExternal = href.startsWith("http");
|
||||
const Icon = platform.Icon;
|
||||
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { CalendarDays } from "lucide-react";
|
||||
import { api } from "@/lib/api";
|
||||
import { IconNostr, IconTelegram, IconX } from "@/components/public/CommunityLinksSection";
|
||||
|
||||
const CHANNELS = [
|
||||
@@ -32,20 +28,13 @@ const cardClass = "card card-hover group flex flex-col p-6";
|
||||
const iconClass =
|
||||
"mb-5 flex h-10 w-10 items-center justify-center rounded-lg border border-white/[0.08] bg-zinc-800/80 text-primary-container";
|
||||
|
||||
export function ContactChannelGrid() {
|
||||
const [settings, setSettings] = useState<Record<string, string>>({});
|
||||
|
||||
useEffect(() => {
|
||||
api
|
||||
.getPublicSettings()
|
||||
.then((data) => setSettings(data))
|
||||
.catch(() => {});
|
||||
}, []);
|
||||
|
||||
/** `settings` comes from the server (`fetchPublicSettings`) so links are in the initial HTML. */
|
||||
export function ContactChannelGrid({ settings }: { settings: Record<string, string> }) {
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-5 sm:grid-cols-2 lg:grid-cols-4">
|
||||
{CHANNELS.map(({ key, title, description, Icon }) => {
|
||||
const href = settings[key] || "#";
|
||||
const href = settings[key]?.trim();
|
||||
if (!href) return null;
|
||||
const isExternal = href.startsWith("http");
|
||||
return (
|
||||
<a
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* stale or build-time-empty list.
|
||||
*/
|
||||
import { apiUrl } from "./api-base";
|
||||
import { getMeetupStartUtc } from "./meetupEventTime";
|
||||
import { getMeetupStartUtc, isMeetupOver } from "./meetupEventTime";
|
||||
|
||||
export interface Meetup {
|
||||
id: string;
|
||||
@@ -69,3 +69,26 @@ export function partitionMeetups(
|
||||
export function countUpcoming(meetups: Meetup[], now: Date = new Date()): number {
|
||||
return partitionMeetups(meetups, now).upcoming.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Homepage selection: published meetups that haven't started yet (soonest
|
||||
* first), and the hero meetup, which is the featured one while it isn't over,
|
||||
* else the next upcoming one.
|
||||
*/
|
||||
export function selectHomepageMeetups<T extends Meetup & { featured?: boolean }>(
|
||||
meetups: T[],
|
||||
now: Date = new Date(),
|
||||
): { upcoming: T[]; hero: T | null } {
|
||||
const startMs = (m: T) => getMeetupStartUtc(m.date, m.time || "00:00").getTime();
|
||||
const upcoming = meetups
|
||||
.filter((m) => {
|
||||
if (m.status !== "PUBLISHED" || !m.date) return false;
|
||||
const start = startMs(m);
|
||||
return !Number.isNaN(start) && start > now.getTime();
|
||||
})
|
||||
.sort((a, b) => startMs(a) - startMs(b));
|
||||
const featured = meetups.find(
|
||||
(m) => m.featured && m.status === "PUBLISHED" && m.date && !isMeetupOver(m.date, m.time || "", now),
|
||||
);
|
||||
return { upcoming, hero: featured ?? upcoming[0] ?? null };
|
||||
}
|
||||
|
||||
+97
-5
@@ -1,21 +1,42 @@
|
||||
import type { Metadata } from "next";
|
||||
import { apiUrl } from "./api-base";
|
||||
|
||||
export const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || "https://belgianbitcoinembassy.org";
|
||||
export const SITE_NAME = "Belgian Bitcoin Embassy";
|
||||
export const TITLE_TEMPLATE = `%s | ${SITE_NAME}`;
|
||||
export const DEFAULT_OG_IMAGE = "/og-default.png";
|
||||
|
||||
/**
|
||||
* Server-side fetch of the public site settings (social links, titles, …).
|
||||
* Cached/revalidated so it doesn't hit the backend on every render.
|
||||
* Cached/revalidated so it doesn't hit the backend on every render. Social
|
||||
* links fall back to `SOCIAL_LINKS` when a setting is empty or the fetch fails.
|
||||
*/
|
||||
export async function fetchPublicSettings(): Promise<Record<string, string>> {
|
||||
try {
|
||||
const res = await fetch(apiUrl("/settings/public"), {
|
||||
next: { revalidate: 3600 },
|
||||
});
|
||||
if (!res.ok) return {};
|
||||
return (await res.json()) as Record<string, string>;
|
||||
if (!res.ok) return withSocialDefaults({});
|
||||
return withSocialDefaults((await res.json()) as Record<string, string>);
|
||||
} catch {
|
||||
return {};
|
||||
return withSocialDefaults({});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Official social profiles, used when the matching admin setting is empty or
|
||||
* the settings API is unreachable. Admin settings always take precedence.
|
||||
*/
|
||||
export const SOCIAL_LINKS: Record<SocialSettingKey, string> = {
|
||||
telegram_link: "https://t.me/belgianbitcoinembassy",
|
||||
nostr_link:
|
||||
"https://primal.net/p/nprofile1qqsx6wn0nr67eq0q2zf67radjnyfacgyq2vdt9eya7dq9h0fwm42m3grk3c6n",
|
||||
x_link: "https://x.com/BelgianBitcoin",
|
||||
youtube_link: "https://youtube.com/@belgianbitcoinembassy",
|
||||
discord_link: "https://discord.gg/m4U7w5kJhC",
|
||||
linkedin_link: "https://www.linkedin.com/company/belgian-bitcoin-embassy/",
|
||||
};
|
||||
|
||||
/** Setting keys that hold a public social/profile URL, in display order. */
|
||||
const SOCIAL_SETTING_KEYS = [
|
||||
"telegram_link",
|
||||
@@ -26,6 +47,21 @@ const SOCIAL_SETTING_KEYS = [
|
||||
"linkedin_link",
|
||||
] as const;
|
||||
|
||||
type SocialSettingKey = (typeof SOCIAL_SETTING_KEYS)[number];
|
||||
|
||||
function isHttpUrl(value: string | undefined): value is string {
|
||||
return !!value && /^https?:\/\//i.test(value.trim());
|
||||
}
|
||||
|
||||
/** Fill empty or invalid social settings with the `SOCIAL_LINKS` defaults. */
|
||||
export function withSocialDefaults(settings: Record<string, string>): Record<string, string> {
|
||||
const merged = { ...settings };
|
||||
for (const key of SOCIAL_SETTING_KEYS) {
|
||||
if (!isHttpUrl(merged[key])) merged[key] = SOCIAL_LINKS[key];
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the list of real social URLs for schema.org `sameAs` from settings.
|
||||
* Only includes entries that are actually configured (non-empty, http(s)).
|
||||
@@ -34,5 +70,61 @@ export function socialUrlsFromSettings(
|
||||
settings: Record<string, string>,
|
||||
): string[] {
|
||||
return SOCIAL_SETTING_KEYS.map((key) => settings[key]?.trim())
|
||||
.filter((url): url is string => !!url && /^https?:\/\//i.test(url));
|
||||
.filter((url): url is string => isHttpUrl(url));
|
||||
}
|
||||
|
||||
interface PageMetadataInput {
|
||||
/** Page title without the site name; the root template appends it. */
|
||||
title: string;
|
||||
description: string;
|
||||
/** Canonical path, e.g. `/blog`. */
|
||||
path: string;
|
||||
image?: string;
|
||||
imageAlt?: string;
|
||||
type?: "website" | "article" | "video.other";
|
||||
/**
|
||||
* Set for metadata exported from a layout: keeps the site-name template
|
||||
* alive for nested pages (a plain string title would reset it).
|
||||
*/
|
||||
layout?: boolean;
|
||||
openGraph?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consistent title, description, canonical, Open Graph and Twitter tags for a
|
||||
* public page. og/twitter titles carry the site name once; descriptions match
|
||||
* the meta description.
|
||||
*/
|
||||
export function pageMetadata({
|
||||
title,
|
||||
description,
|
||||
path,
|
||||
image = DEFAULT_OG_IMAGE,
|
||||
imageAlt,
|
||||
type = "website",
|
||||
layout = false,
|
||||
openGraph,
|
||||
}: PageMetadataInput): Metadata {
|
||||
const fullTitle = title.endsWith(` | ${SITE_NAME}`) ? title : TITLE_TEMPLATE.replace("%s", title);
|
||||
return {
|
||||
title: layout ? { default: title, template: TITLE_TEMPLATE } : title,
|
||||
description,
|
||||
alternates: { canonical: path },
|
||||
openGraph: {
|
||||
type,
|
||||
locale: "en_BE",
|
||||
siteName: SITE_NAME,
|
||||
url: path,
|
||||
title: fullTitle,
|
||||
description,
|
||||
images: [{ url: image, width: 1200, height: 630, alt: imageAlt || title }],
|
||||
...openGraph,
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: fullTitle,
|
||||
description,
|
||||
images: [image],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Server-side data loaders for server-rendered public pages. They call the
|
||||
* backend directly over loopback (see `apiUrl`), revalidate every 5 minutes,
|
||||
* and are wrapped in React `cache()` so `generateMetadata` and the page share
|
||||
* one fetch per request.
|
||||
*/
|
||||
import { cache } from "react";
|
||||
import { apiUrl } from "@/lib/api-base";
|
||||
import type { Meetup } from "@/lib/meetupsData";
|
||||
|
||||
export const REVALIDATE_SECONDS = 300;
|
||||
|
||||
class NotFound extends Error {}
|
||||
|
||||
async function getJson<T>(path: string): Promise<T> {
|
||||
const res = await fetch(apiUrl(path), { next: { revalidate: REVALIDATE_SECONDS } });
|
||||
if (res.status === 404) throw new NotFound(path);
|
||||
if (!res.ok) throw new Error(`GET ${path} failed with ${res.status}`);
|
||||
return (await res.json()) as T;
|
||||
}
|
||||
|
||||
/** Null on a real 404; other failures throw so ISR keeps serving the last good page. */
|
||||
async function getOrNull<T>(path: string): Promise<T | null> {
|
||||
try {
|
||||
return await getJson<T>(path);
|
||||
} catch (err) {
|
||||
if (err instanceof NotFound) return null;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/** Lists degrade to empty so one failing section never takes a page down. */
|
||||
async function getOrFallback<T>(path: string, fallback: T): Promise<T> {
|
||||
try {
|
||||
return await getJson<T>(path);
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
export interface MeetupDetail extends Meetup {
|
||||
link?: string | null;
|
||||
imageId?: string | null;
|
||||
featured?: boolean;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
}
|
||||
|
||||
export interface PostCategory {
|
||||
category: { id: string; name: string; slug: string };
|
||||
}
|
||||
|
||||
export interface Post {
|
||||
id: string;
|
||||
slug: string;
|
||||
title: string;
|
||||
content: string;
|
||||
excerpt?: string | null;
|
||||
summary?: string | null;
|
||||
image?: string | null;
|
||||
authorName?: string | null;
|
||||
authorPubkey?: string;
|
||||
publishedAt?: string | null;
|
||||
createdAt?: string;
|
||||
updatedAt?: string;
|
||||
nostrEventId?: string;
|
||||
naddr?: string | null;
|
||||
categories?: PostCategory[];
|
||||
}
|
||||
|
||||
export const getMeetup = cache((id: string) =>
|
||||
getOrNull<MeetupDetail>(`/meetups/${encodeURIComponent(id)}`),
|
||||
);
|
||||
|
||||
export const getMeetups = cache(async (): Promise<MeetupDetail[]> => {
|
||||
const data = await getOrFallback<unknown>("/meetups", []);
|
||||
return Array.isArray(data) ? (data as MeetupDetail[]) : [];
|
||||
});
|
||||
|
||||
export const getPost = cache((slug: string) =>
|
||||
getOrNull<Post>(`/posts/${encodeURIComponent(slug)}`),
|
||||
);
|
||||
|
||||
export const getLatestPosts = cache(async (limit: number): Promise<Post[]> => {
|
||||
const data = await getOrFallback<{ posts?: Post[] }>(`/posts?limit=${limit}`, {});
|
||||
return data.posts ?? [];
|
||||
});
|
||||
@@ -13,6 +13,16 @@ export function formatDate(date: string | Date) {
|
||||
});
|
||||
}
|
||||
|
||||
/** Same format as `formatDate`, pinned to UTC so server and browser render identical text. */
|
||||
export function formatDateUtc(date: string | Date) {
|
||||
return new Date(date).toLocaleDateString("en-US", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
timeZone: "UTC",
|
||||
});
|
||||
}
|
||||
|
||||
export function slugify(text: string) {
|
||||
return text
|
||||
.toLowerCase()
|
||||
|
||||
+2
-1
@@ -4,6 +4,7 @@
|
||||
"scripts": {
|
||||
"db:push": "npm run db:push --prefix backend",
|
||||
"db:seed": "npm run db:seed --prefix backend",
|
||||
"db:studio": "npm run db:studio --prefix backend"
|
||||
"db:studio": "npm run db:studio --prefix backend",
|
||||
"seo-check": "node scripts/seo-check.mjs"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,20 @@ if [ -n "${free_mb}" ] && [ "${free_mb}" -lt "${MIN_FREE_MB}" ]; then
|
||||
die "only ${free_mb}MB available memory (< ${MIN_FREE_MB}MB). Free memory or set MIN_FREE_MB=... to override."
|
||||
fi
|
||||
|
||||
# Point build-time prerendering at the backend on loopback (the port from the
|
||||
# root .env), so pages, the sitemap and structured data are built from live
|
||||
# data instead of failing fetches. Only this one variable is read from .env.
|
||||
if [ -z "${INTERNAL_API_URL:-}" ]; then
|
||||
backend_port="$(grep -E '^BACKEND_PORT=' "${REPO_DIR}/.env" 2>/dev/null | tail -n1 | cut -d= -f2 | tr -d '[:space:]\"'"'"'' || true)"
|
||||
if [ -n "${backend_port}" ]; then
|
||||
export INTERNAL_API_URL="http://127.0.0.1:${backend_port}/api"
|
||||
fi
|
||||
fi
|
||||
if [ -n "${INTERNAL_API_URL:-}" ]; then
|
||||
curl -fsS -o /dev/null --max-time 5 "${INTERNAL_API_URL}/health" \
|
||||
|| log "WARNING: backend not reachable at ${INTERNAL_API_URL}; prerendered pages will be empty until they revalidate"
|
||||
fi
|
||||
|
||||
log "building into ${BUILD_DIR} ..."
|
||||
rm -rf "${BUILD_DIR}"
|
||||
NEXT_DIST_DIR=".next-build" npm run build
|
||||
|
||||
@@ -73,8 +73,10 @@ function descProblems(label, d) {
|
||||
return out;
|
||||
}
|
||||
|
||||
// Counts the " | Belgian Bitcoin Embassy" suffix; a title may still mention
|
||||
// the name itself (e.g. "#59 Belgian Bitcoin Embassy Meetup").
|
||||
function brandCount(s) {
|
||||
return s ? s.split(BRAND).length - 1 : 0;
|
||||
return s ? s.split(` | ${BRAND}`).length - 1 : 0;
|
||||
}
|
||||
|
||||
async function discover() {
|
||||
|
||||
Reference in New Issue
Block a user