diff --git a/crates/site-builder/src/seo.rs b/crates/site-builder/src/seo.rs index 35e0919..60571df 100644 --- a/crates/site-builder/src/seo.rs +++ b/crates/site-builder/src/seo.rs @@ -30,7 +30,7 @@ pub const AUTHOR: &str = "M. Drake Stapleton"; pub const AUTHOR_URL: &str = "https://www.drakestapleton.com"; pub const AUTHOR_GITHUB: &str = "https://github.com/drakestapleton"; pub const LICENSE_NAME: &str = "Apache-2.0 WITH LLVM-exception"; -pub const LICENSE_URL: &str = "https://www.gnu.org/licenses/agpl-3.0.html"; +pub const LICENSE_URL: &str = "https://www.aienos.com/licensing/"; /// What a page is, for structured data. #[derive(Clone, Copy, PartialEq, Eq, Debug)] @@ -535,7 +535,7 @@ fn graph(page: &Emitted, info: &PageInfo, facts: &HeadFacts, has_mirror: bool, c let url = page.url(); let title = unescape(if facts.og_title.is_empty() { &facts.title } else { &facts.og_title }); let description = unescape(if facts.description.is_empty() { &facts.og_description } else { &facts.description }); - let image = format!("{HOST}{}", info.image); + let image = social_image_url(info); let zh = page.is_zh(); let kind = match info.kind { Kind::Home | Kind::Page | Kind::Live => "WebPage", @@ -611,13 +611,18 @@ fn graph(page: &Emitted, info: &PageInfo, facts: &HeadFacts, has_mirror: bool, c json!({"@context": "https://schema.org", "@graph": nodes}) } +/// Bump when cards change so preview crawlers fetch the new image bytes. +fn social_image_url(info: &PageInfo) -> String { + format!("{HOST}{}?v=20261024-apache-llvm", info.image) +} + /// The tags the pass writes into every head. fn head_block(page: &Emitted, info: &PageInfo, facts: &HeadFacts, has_mirror: bool, ctx: &BuildCtx, dist: &Path) -> String { let url = page.url(); let title = if facts.og_title.is_empty() { facts.title.clone() } else { facts.og_title.clone() }; let description = if facts.og_description.is_empty() { facts.description.clone() } else { facts.og_description.clone() }; let og_type = if !facts.og_type.is_empty() { facts.og_type.clone() } else { match info.kind { Kind::Article | Kind::Paper => "article".into(), _ => "website".into() } }; - let image = format!("{HOST}{}", info.image); + let image = social_image_url(info); let image_alt = escape(&format!("{SITE_NAME}: {}", info.name)); let locale = if page.is_zh() { "zh_CN" } else { "en_US" }; let mut b = String::new(); @@ -1124,6 +1129,27 @@ pub fn verify(dist: &Path) { mod tests { use super::*; + #[test] + fn social_previews_use_current_license_and_fresh_images() { + assert_eq!(LICENSE_NAME, "Apache-2.0 WITH LLVM-exception"); + assert_eq!(LICENSE_URL, "https://www.aienos.com/licensing/"); + let ctx = BuildCtx { built: "b".into(), head_committed: "h".into(), ledger_written: "l".into(), facts_generated: "f".into() }; + for info in PAGES { + for lang in ["en", "zh-CN"] { + let path = if lang == "en" { info.path.to_string() } else { format!("/zh-CN{}", info.path) }; + let page = Emitted { path, file: PathBuf::from("x"), lang: lang.into(), lastmod: "2026-10-24T00:00:00Z".into() }; + let facts = HeadFacts::default(); + let head = head_block(&page, info, &facts, false, &ctx, Path::new("/nonexistent")); + let image = social_image_url(info); + assert!(image.ends_with("?v=20261024-apache-llvm")); + assert!(head.contains(&format!("property=\"og:image\" content=\"{image}\""))); + assert!(head.contains(&format!("name=\"twitter:image\" content=\"{image}\""))); + assert!(head.contains(LICENSE_URL)); + assert!(!head.contains("gnu.org/licenses/agpl")); + } + } + } + #[test] fn rfc3339_round_trip() { assert_eq!(rfc3339(0), "1970-01-01T00:00:00Z"); diff --git a/public/og-blog.png b/public/og-blog.png index 6159e14..3faa632 100644 Binary files a/public/og-blog.png and b/public/og-blog.png differ diff --git a/public/og-discovery.png b/public/og-discovery.png index d6abe8f..a86ce35 100644 Binary files a/public/og-discovery.png and b/public/og-discovery.png differ diff --git a/public/og-evidence.png b/public/og-evidence.png index c347108..681c1cc 100644 Binary files a/public/og-evidence.png and b/public/og-evidence.png differ diff --git a/public/og-experiments.png b/public/og-experiments.png index e65b934..ca970f6 100644 Binary files a/public/og-experiments.png and b/public/og-experiments.png differ diff --git a/public/og-machine.png b/public/og-machine.png index c55281f..5437354 100644 Binary files a/public/og-machine.png and b/public/og-machine.png differ diff --git a/public/og-now.png b/public/og-now.png index d4b19b6..699dada 100644 Binary files a/public/og-now.png and b/public/og-now.png differ diff --git a/public/og-philosophy.png b/public/og-philosophy.png index 4c55f6c..4b232f5 100644 Binary files a/public/og-philosophy.png and b/public/og-philosophy.png differ diff --git a/public/og-research.png b/public/og-research.png index 21e344d..8f4bd55 100644 Binary files a/public/og-research.png and b/public/og-research.png differ diff --git a/public/og-turing.png b/public/og-turing.png index 54e741b..9d54ca7 100644 Binary files a/public/og-turing.png and b/public/og-turing.png differ diff --git a/public/og.png b/public/og.png index fea7cce..6930dc4 100644 Binary files a/public/og.png and b/public/og.png differ diff --git a/scripts/og-cards.py b/scripts/og-cards.py index ac93ff7..70c7f91 100644 --- a/scripts/og-cards.py +++ b/scripts/og-cards.py @@ -23,6 +23,19 @@ GREEN = (0, 229, 153) TEXT = (241, 245, 249) MUTED = (148, 163, 184) DIM = (100, 116, 139) +LICENSE_NAME = "Apache-2.0 WITH LLVM-exception" +BADGES = ((f"Open source, {LICENSE_NAME}", GREEN), + ("Experimental, pre-alpha", (245, 166, 35)), + ("Receipts over claims", BLUE)) + +def badge_font(draw): + # Keep the full license identifier and all three badges inside the margins. + for size in range(22, 11, -1): + candidate = font(MONO, size) + width = sum(draw.textlength(label, font=candidate) + 30 for label, _ in BADGES) + if width + 16 * (len(BADGES) - 1) <= W - 160: + return candidate + raise ValueError("Social card badges do not fit") CARDS = [ # file, kicker, claim (two lines max), sub line, address @@ -71,15 +84,16 @@ CARDS = [ FONT_DIRS = ["/System/Library/Fonts/Supplemental", "/System/Library/Fonts", "/usr/share/fonts/truetype/dejavu", "/usr/share/fonts/truetype/liberation"] def font(names, size): - for d in FONT_DIRS: - for n in names: + for n in names: + for d in FONT_DIRS: p = os.path.join(d, n) if os.path.exists(p): return ImageFont.truetype(p, size) return ImageFont.load_default(size) -BOLD = ["Arial Bold.ttf", "DejaVuSans-Bold.ttf", "LiberationSans-Bold.ttf"] -REG = ["Arial.ttf", "DejaVuSans.ttf", "LiberationSans-Regular.ttf"] +# Liberation Sans is metrically compatible with Arial; preserve the card layout on Linux. +BOLD = ["Arial Bold.ttf", "LiberationSans-Bold.ttf", "DejaVuSans-Bold.ttf"] +REG = ["Arial.ttf", "LiberationSans-Regular.ttf", "DejaVuSans.ttf"] MONO = ["Menlo.ttc", "DejaVuSansMono.ttf", "LiberationMono-Regular.ttf"] def glow(base, xy, r, color, alpha): @@ -135,7 +149,8 @@ def card(file, kicker, claim, sub, address): y += 38 # Badges along the bottom. bx = 80 - for label, col in (("Open source, AGPL-3.0-or-later", GREEN), ("Experimental, pre-alpha", (245, 166, 35)), ("Receipts over claims", BLUE)): + fm = badge_font(d) + for label, col in BADGES: tw = d.textlength(label, font=fm) d.rounded_rectangle((bx, 518, bx + tw + 30, 558), radius=6, outline=col, width=1, fill=(14, 18, 25, 255)) d.text((bx + 15, 526), label, font=fm, fill=col) diff --git a/scripts/test_og_cards.py b/scripts/test_og_cards.py new file mode 100644 index 0000000..d0c6196 --- /dev/null +++ b/scripts/test_og_cards.py @@ -0,0 +1,52 @@ +"""Social-card regression checks: python3 -m unittest discover -s scripts -p 'test_og_cards.py'.""" +import importlib.util +from pathlib import Path +import tempfile +import unittest + +from PIL import Image, ImageDraw + +SPEC = importlib.util.spec_from_file_location("og_cards", Path(__file__).with_name("og-cards.py")) +cards = importlib.util.module_from_spec(SPEC) +SPEC.loader.exec_module(cards) +ROOT = Path(__file__).resolve().parents[1] + + +class SocialCardsTests(unittest.TestCase): + def test_license_matches_site_metadata_and_controlling_text(self): + seo = (ROOT / "crates/site-builder/src/seo.rs").read_text() + self.assertIn(f'LICENSE_NAME: &str = "{cards.LICENSE_NAME}"', seo) + self.assertIn("LLVM Exceptions", (ROOT / "LICENSE").read_text()) + self.assertIn(cards.LICENSE_NAME, (ROOT / "public/licensing/index.html").read_text()) + self.assertEqual(cards.BADGES[0][0], f"Open source, {cards.LICENSE_NAME}") + self.assertNotIn("AGPL", cards.BADGES[0][0]) + + def test_badges_fit_inside_card_margins(self): + draw = ImageDraw.Draw(Image.new("RGB", (cards.W, cards.H))) + font = cards.badge_font(draw) + width = sum(draw.textlength(label, font=font) + 30 for label, _ in cards.BADGES) + self.assertLessEqual(width + 16 * (len(cards.BADGES) - 1), cards.W - 160) + + def test_all_cards_render_deterministically_at_published_dimensions(self): + old_out = cards.OUT + try: + with tempfile.TemporaryDirectory() as directory: + cards.OUT = directory + for card in cards.CARDS: + with self.subTest(card=card[0]): + cards.card(*card) + rendered = Path(directory, card[0]) + first = rendered.read_bytes() + cards.card(*card) + self.assertEqual(rendered.read_bytes(), first) + with Image.open(ROOT / "public" / card[0]) as published: + self.assertEqual(published.size, (1200, 630)) + with Image.open(rendered) as image: + self.assertEqual(image.size, (1200, 630)) + self.assertEqual(image.mode, "RGB") + finally: + cards.OUT = old_out + + +if __name__ == "__main__": + unittest.main()