Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

site: RSS feeds for the English and Hebrew devlog (#415) (#425)

Eyal Golanc857c2638dfd
diff --git a/site/scripts/check-site.mjs b/site/scripts/check-site.mjs
index fa8137eb5..5891bc445 100644
--- a/site/scripts/check-site.mjs
+++ b/site/scripts/check-site.mjs
@@ -5,7 +5,8 @@
// (In-engine capture, Concept art — AI-generated, Cinematic promo — AI-generated, not gameplay, or Archival
// photograph), except contributor photos, which are portraits supplied by the owner;
// 4. nothing loads from another origin: no external script, stylesheet, font, image, video or frame;
-// 5. every file under _astro/ that a page names exists.
+// 5. every file under _astro/ that a page names exists;
+// 6. both devlog RSS feeds exist, are well-formed, list every post, and the devlog page links to them.
// Run after `astro build` (npm run build does both). Exit 1 with one line per problem.
import fs from 'node:fs';
import path from 'node:path';
@@ -102,9 +103,42 @@ for (const lang of ['en', 'he']) {
}
}
+// 6. Each devlog has an RSS feed that is well-formed, lists every post, and is linked from the devlog page and its <head>.
+function xmlProblem(xml) {
+ const stack = [];
+ const body = xml.replace(/^<\?xml[^?]*\?>/, '').replace(/<!\[CDATA\[[\s\S]*?\]\]>/g, '');
+ if (/&(?!(?:amp|lt|gt|quot|apos|#\d+|#x[0-9a-f]+);)/i.test(body)) return 'a bare &';
+ for (const m of body.matchAll(/<(\/?)([A-Za-z][\w:.-]*)((?:"[^"]*"|'[^']*'|[^'">])*?)(\/?)>|<|>/g)) {
+ if (m[0] === '<') return 'a stray <';
+ if (m[0] === '>') continue;
+ if (m[4]) continue;
+ if (!m[1]) stack.push(m[2]);
+ else if (stack.pop() !== m[2]) return `</${m[2]}> closes the wrong element`;
+ }
+ return stack.length ? `<${stack.at(-1)}> is not closed` : (/^\s*<rss[\s>]/.test(body) ? null : 'no <rss> root');
+}
+for (const lang of ['en', 'he']) {
+ const feed = path.join(dist, lang, 'devlog', 'rss.xml');
+ if (!fs.existsSync(feed)) { problems.push(`${lang}/devlog/rss.xml: missing`); continue; }
+ const xml = fs.readFileSync(feed, 'utf8');
+ const bad = xmlProblem(xml);
+ if (bad) fail(feed, `not well-formed: ${bad}`);
+ if (!xml.includes(`<language>${lang}</language>`)) fail(feed, `no <language>${lang}</language>`);
+ const links = [...xml.matchAll(/<item>[\s\S]*?<link>([^<]+)<\/link>/g)].map((m) => m[1]);
+ if (links.some((u) => !/^https?:\/\//.test(u))) fail(feed, 'an item link is not absolute');
+ const src = path.resolve(dist, '..', 'src', 'content', 'devlog', lang);
+ for (const md of fs.readdirSync(src).filter((n) => n.endsWith('.md'))) {
+ if (!links.some((u) => u.endsWith(`#${md.slice(0, -3)}`))) fail(feed, `does not list ${md}`);
+ }
+ const page = path.join(dist, lang, 'devlog', 'index.html');
+ const html = fs.existsSync(page) ? fs.readFileSync(page, 'utf8') : '';
+ if (!/<link rel="alternate" type="application\/rss\+xml"[^>]*href="https?:\/\/[^"]*\/devlog\/rss\.xml"/.test(html)) fail(page, 'no RSS <link> in <head>');
+ if (!/<main[\s\S]*<a href="[^"]*\/devlog\/rss\.xml"[\s\S]*<\/main>/.test(html)) fail(page, 'no link to the RSS feed');
+}
+
if (problems.length) {
console.error(problems.join('\n'));
console.error(`check-site: ${problems.length} problem(s)`);
process.exit(1);
}
-console.log(`check-site: ${pages.length} pages OK (both languages, labels on every image and video, nothing from other origins)`);
+console.log(`check-site: ${pages.length} pages OK (both languages, labels on every image and video, nothing from other origins, devlog RSS feeds)`);
diff --git a/site/src/layouts/Layout.astro b/site/src/layouts/Layout.astro
index 2682b22cd..814c296bf 100644
--- a/site/src/layouts/Layout.astro
+++ b/site/src/layouts/Layout.astro
@@ -16,9 +16,11 @@ interface Props {
/** Images to preload (the LCP image), as from getImage. */
preload?: { srcset: string; sizes: string; type: string }[];
noindex?: boolean;
+ /** An RSS feed for this page, announced in <head>. */
+ feed?: { title: string; href: string };
}
-const { lang, page, title, description = t(lang, 'site.tagline'), jsonLd, preload = [], noindex = false } = Astro.props;
+const { lang, page, title, description = t(lang, 'site.tagline'), jsonLd, preload = [], noindex = false, feed } = Astro.props;
const fullTitle = title ? `${title} — ${t(lang, 'site.name')}` : t(lang, 'site.name');
const abs = (p: string) => new URL(p, Astro.site).href;
const canonical = abs(href(lang, page));
@@ -49,6 +51,7 @@ const bodyFont = lang === 'he' ? 'fonts/FrankRuhlLibre-Regular.woff2' : 'fonts/E
<meta name="description" content={description} />
{noindex ? <meta name="robots" content="noindex" /> : <link rel="canonical" href={canonical} />}
{alternates.map((a) => <link rel="alternate" hreflang={a.hreflang} href={a.url} />)}
+ {feed && <link rel="alternate" type="application/rss+xml" title={feed.title} href={abs(feed.href)} />}
<link rel="icon" href={asset('favicon.svg')} type="image/svg+xml" />
<meta name="theme-color" content="#090e1a" />
<link rel="preload" href={asset(bodyFont)} as="font" type="font/woff2" crossorigin />
diff --git a/site/src/pages/[lang]/devlog/index.astro b/site/src/pages/[lang]/devlog/index.astro
index 0651e2670..820e0dbb6 100644
--- a/site/src/pages/[lang]/devlog/index.astro
+++ b/site/src/pages/[lang]/devlog/index.astro
@@ -1,15 +1,16 @@
---
import Layout from '../../../layouts/Layout.astro';
-import { type Lang, languages, t, formatDate, REPO } from '../../../i18n/ui';
+import { type Lang, languages, t, href, formatDate, REPO } from '../../../i18n/ui';
import { posts } from '../../../lib/devlog';
export const getStaticPaths = () => languages.map((lang) => ({ params: { lang } }));
const lang = Astro.params.lang as Lang;
const he = lang === 'he';
const list = posts(lang);
+const feed = { title: he ? 'יומן פיתוח (RSS)' : 'Devlog (RSS)', href: `${href(lang, 'devlog')}rss.xml` };
---
<Layout lang={lang} page="devlog" title={t(lang, 'nav.devlog')}
- description={he ? 'מה השתנה במשחק, מתוך יומן השינויים של המאגר.' : 'What changed in the game, from the repository’s changelog.'}>
+ description={he ? 'מה השתנה במשחק, מתוך יומן השינויים של המאגר.' : 'What changed in the game, from the repository’s changelog.'} feed={feed}>
<div class="wrap page">
<header class="page-head">
<span class="eyebrow">{t(lang, 'nav.devlog')}</span>
@@ -18,6 +19,7 @@ const list = posts(lang);
? 'רשומות קצרות על מה שהשתנה. הרשימה המלאה של השינויים נמצאת ביומן השינויים של המאגר (באנגלית).'
: 'Short notes on what changed. The full list of changes is in the repository’s changelog.'}
{' '}<a href={`${REPO}/blob/main/CHANGELOG.md`}>CHANGELOG.md</a></p>
+ <p><a href={feed.href} type="application/rss+xml">{he ? 'הרשמה ב־RSS' : 'Subscribe by RSS'}</a></p>
</header>
<div class="posts">
{list.map((p) => (
diff --git a/site/src/pages/[lang]/devlog/rss.xml.ts b/site/src/pages/[lang]/devlog/rss.xml.ts
new file mode 100644
index 000000000..c009e99d5
--- /dev/null
+++ b/site/src/pages/[lang]/devlog/rss.xml.ts
@@ -0,0 +1,40 @@
+// The devlog as an RSS 2.0 feed, one per language: /en/devlog/rss.xml and /he/devlog/rss.xml.
+// Written by hand, so the site needs no feed dependency. Every URL is absolute, built from `site` and `base`.
+import type { APIRoute } from 'astro';
+import { type Lang, languages, href, t } from '../../../i18n/ui';
+import { posts } from '../../../lib/devlog';
+
+export const getStaticPaths = () => languages.map((lang) => ({ params: { lang } }));
+
+const esc = (s: string) => s.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
+const rfc822 = (iso: string) => new Date(`${iso}T00:00:00Z`).toUTCString();
+
+export const GET: APIRoute = ({ params, site }) => {
+ const lang = params.lang as Lang;
+ const he = lang === 'he';
+ const abs = (p: string) => new URL(p, site).href;
+ const page = abs(href(lang, 'devlog'));
+ const list = posts(lang);
+ // Feed readers that render the description as HTML get the text direction from it, not only from <language>.
+ const body = (s: string) => esc(`<p dir="${he ? 'rtl' : 'ltr'}" lang="${lang}">${esc(s)}</p>`);
+ const items = list.map((p) => ` <item>
+ <title>${esc(p.title)}</title>
+ <link>${page}#${p.slug}</link>
+ <guid isPermaLink="true">${page}#${p.slug}</guid>
+ <pubDate>${rfc822(p.date)}</pubDate>
+ <description>${body(p.summary)}</description>
+ </item>`);
+ const xml = `<?xml version="1.0" encoding="UTF-8"?>
+<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
+ <channel>
+ <title>${esc(`${he ? 'יומן פיתוח' : 'Devlog'} — ${t(lang, 'site.name')}`)}</title>
+ <link>${page}</link>
+ <atom:link href="${page}rss.xml" rel="self" type="application/rss+xml" />
+ <description>${esc(he ? 'מה השתנה במשחק, מתוך יומן השינויים של המאגר.' : 'What changed in the game, from the repository’s changelog.')}</description>
+ <language>${lang}</language>
+${list.length ? ` <lastBuildDate>${rfc822(list[0].date)}</lastBuildDate>\n` : ''}${items.join('\n')}
+ </channel>
+</rss>
+`;
+ return new Response(xml, { headers: { 'Content-Type': 'application/rss+xml; charset=utf-8' } });
+};