Files
bbeandClaude Opus 5.5 f0a59c33a3 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>
2026-10-13 01:05:29 +02:00

199 lines
7.2 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env node
//
// Crawlability check: fetches public pages the way a crawler does (no
// JavaScript, Googlebot user agent) and verifies the server HTML carries the
// real content, one H1, deep links, clean metadata and a nosnippet disclaimer.
//
// Usage:
// node scripts/seo-check.mjs # production
// node scripts/seo-check.mjs http://127.0.0.1:4157 # any other base URL
//
// Exits non-zero when any check fails.
const BASE = (process.argv[2] || "https://belgianbitcoinembassy.org").replace(/\/+$/, "");
const UA =
"Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)";
const BRAND = "Belgian Bitcoin Embassy";
const MAX_DESC = 160;
async function get(path) {
const res = await fetch(BASE + path, { headers: { "user-agent": UA }, redirect: "manual" });
return { status: res.status, body: await res.text() };
}
function decode(s) {
return s
.replace(/&amp;/g, "&")
.replace(/&lt;/g, "<")
.replace(/&gt;/g, ">")
.replace(/&quot;/g, '"')
.replace(/&#x27;|&#39;/g, "'")
.replace(/&nbsp;/g, " ");
}
function textOf(html) {
return decode(
html
.replace(/<script[\s\S]*?<\/script>/gi, " ")
.replace(/<style[\s\S]*?<\/style>/gi, " ")
.replace(/<template[\s\S]*?<\/template>/gi, " ")
.replace(/<[^>]+>/g, " "),
)
.replace(/\s+/g, " ")
.trim();
}
function mainText(html) {
const m = html.match(/<main\b[^>]*>([\s\S]*)<\/main>/i);
return m ? textOf(m[1]) : "";
}
function meta(html, attr, name) {
const re = new RegExp(`<meta[^>]*${attr}="${name}"[^>]*>`, "i");
const tag = html.match(re)?.[0];
if (!tag) return null;
const c = tag.match(/content="([^"]*)"/i);
return c ? decode(c[1]) : null;
}
function title(html) {
const m = html.match(/<title[^>]*>([\s\S]*?)<\/title>/i);
return m ? decode(m[1]).trim() : null;
}
function descProblems(label, d) {
if (d == null) return [`${label} missing`];
const out = [];
if (d.length > MAX_DESC) out.push(`${label} is ${d.length} chars`);
if (/[​-‍]/.test(d)) out.push(`${label} has zero-width chars`);
if (/https?:\/\/|www\./i.test(d)) out.push(`${label} has a URL`);
if (/[\r\n]/.test(d)) out.push(`${label} has newlines`);
if (/(^|\s)#{1,6}\s|\*\*|__|\]\(|`/.test(d)) out.push(`${label} has markdown`);
if (/[.?!][A-Z]/.test(d)) out.push(`${label} joins sentences without a space`);
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;
}
async function discover() {
const ev = await get("/events");
const eventId = ev.body.match(/href="\/events\/([0-9a-f-]{36})"/)?.[1];
const blog = await get("/blog");
const slug = [...blog.body.matchAll(/href="\/blog\/([^"?#/]+)"/g)].map((m) => m[1])[0];
return { eventId, slug };
}
async function checkPage(path, { home = false } = {}) {
const { status, body } = await get(path);
const problems = [];
if (status !== 200) problems.push(`HTTP ${status}`);
const main = mainText(body);
const h1 = (body.match(/<h1\b/gi) || []).length;
if (h1 !== 1) problems.push(`${h1} <h1>`);
if (main.length < 200) problems.push(`<main> only ${main.length} chars`);
if (/href="#"/.test(body)) problems.push('href="#" present');
const disclaimer = body.match(/<[a-z]+\b[^>]*data-nosnippet[^>]*>[\s\S]*?provides information for/i);
if (!disclaimer) problems.push("disclaimer lacks data-nosnippet");
const t = title(body);
const ogTitle = meta(body, "property", "og:title");
if (brandCount(t) > 1) problems.push(`doubled brand in <title>: "${t}"`);
if (brandCount(ogTitle) > 1) problems.push(`doubled brand in og:title: "${ogTitle}"`);
const desc = meta(body, "name", "description");
const ogDesc = meta(body, "property", "og:description");
const twDesc = meta(body, "name", "twitter:description");
problems.push(
...descProblems("description", desc),
...descProblems("og:description", ogDesc),
...descProblems("twitter:description", twDesc),
);
if (desc && twDesc && desc !== twDesc) problems.push("twitter:description differs from description");
if (desc && ogDesc && desc !== ogDesc) problems.push("og:description differs from description");
let links = "";
if (home) {
const ev = new Set([...body.matchAll(/href="\/events\/([0-9a-f-]{36})"/g)].map((m) => m[1]));
const posts = new Set([...body.matchAll(/href="\/blog\/([^"?#/]+)"/g)].map((m) => m[1]));
if (ev.size === 0) problems.push("no links to event detail pages");
if (posts.size === 0) problems.push("no links to blog posts");
links = `${ev.size} event / ${posts.size} post links`;
}
return { path, status, mainChars: main.length, h1, title: t, desc, links, problems };
}
async function checkSitemap() {
const { status, body } = await get("/sitemap.xml");
const problems = [];
if (status !== 200) problems.push(`HTTP ${status}`);
const urls = [...body.matchAll(/<url>([\s\S]*?)<\/url>/g)].map((m) => ({
loc: m[1].match(/<loc>([^<]*)<\/loc>/)?.[1] || "",
lastmod: m[1].match(/<lastmod>([^<]*)<\/lastmod>/)?.[1] || null,
}));
const paths = urls.map((u) => ({ ...u, path: u.loc.replace(/^https?:\/\/[^/]+/, "") || "/" }));
for (const p of ["/videos", "/board"]) {
if (!paths.some((u) => u.path === p)) problems.push(`missing ${p}`);
}
const events = paths.filter((u) => u.path.startsWith("/events/"));
const posts = paths.filter((u) => u.path.startsWith("/blog/"));
if (events.length === 0) problems.push("no event URLs");
if (posts.length === 0) problems.push("no post URLs");
const staticWithLastmod = paths.filter(
(u) => !/^\/(events|blog|videos)\/./.test(u.path) && u.lastmod,
);
if (staticWithLastmod.length) {
problems.push(`static pages with lastmod: ${staticWithLastmod.map((u) => u.path).join(", ")}`);
}
return { total: urls.length, events: events.length, posts: posts.length, problems };
}
const { eventId, slug } = await discover();
const targets = [
["/", { home: true }],
["/events"],
[eventId ? `/events/${eventId}` : null],
["/blog"],
[slug ? `/blog/${slug}` : null],
["/faq"],
["/contact"],
];
console.log(`SEO check against ${BASE}\n`);
let failed = 0;
for (const [path, opts] of targets) {
if (!path) {
console.log("FAIL could not discover a detail URL to check");
failed++;
continue;
}
const r = await checkPage(path, opts);
const ok = r.problems.length === 0;
if (!ok) failed++;
console.log(
`${ok ? "PASS" : "FAIL"} ${r.path}\n` +
` main=${r.mainChars} chars h1=${r.h1}${r.links ? ` ${r.links}` : ""}\n` +
` title: ${r.title}\n` +
` description (${r.desc?.length ?? 0}): ${r.desc}` +
(ok ? "" : `\n problems:\n - ${r.problems.join("\n - ")}`),
);
}
const sm = await checkSitemap();
if (sm.problems.length) failed++;
console.log(
`${sm.problems.length ? "FAIL" : "PASS"} /sitemap.xml\n` +
` ${sm.total} URLs (${sm.events} events, ${sm.posts} posts)` +
(sm.problems.length ? `\n problems:\n - ${sm.problems.join("\n - ")}` : ""),
);
console.log(failed ? `\n${failed} check(s) failed` : "\nAll checks passed");
process.exit(failed ? 1 : 0);