From 1e7f44ff56903bbc20039dd988c6a8a46ad5632c Mon Sep 17 00:00:00 2001 From: Lukas Wallrich Date: Thu, 19 Nov 2026 15:22:49 +0000 Subject: [PATCH 1/2] SEO checks: one module per check, so new checks stop colliding Each hard check in check_seo_html.py moves to scripts/seo_checks/.py (docstring plus check(site)), with its tests in scripts/tests/test_seo_.py. The runner loads every module in that folder in name order, so adding a check touches no shared file. Numbers are gone; the summary shows each check's module name and first docstring line. CLI, exit code and report-only output are unchanged. The newsletter third-party check ran twice (as 12 and 19); it now runs once. The runner test that faked a whole site to get exit 0 is replaced by stub checks, and the crumb-links test now runs the check, not the parser. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 2 +- content/resources/resource.py | 2 +- scripts/check_seo_html.py | 837 ++---------------- scripts/seo_checks/__init__.py | 0 scripts/seo_checks/_site.py | 238 +++++ scripts/seo_checks/breadcrumb_jsonld.py | 64 ++ scripts/seo_checks/breadcrumb_links.py | 9 + scripts/seo_checks/citation_targets.py | 12 + scripts/seo_checks/cluster_title_markup.py | 27 + scripts/seo_checks/clusters_map.py | 102 +++ scripts/seo_checks/conditional_assets.py | 21 + scripts/seo_checks/description_entities.py | 28 + scripts/seo_checks/description_present.py | 10 + scripts/seo_checks/flora_citation.py | 19 + scripts/seo_checks/glossary_aka_filter.py | 47 + scripts/seo_checks/glossary_links.py | 26 + .../seo_checks/glossary_related_language.py | 29 + scripts/seo_checks/glossary_title_markdown.py | 18 + scripts/seo_checks/homepage_assets.py | 11 + scripts/seo_checks/homepage_img_dims.py | 10 + scripts/seo_checks/homepage_share_image.py | 24 + scripts/seo_checks/img_alt.py | 9 + scripts/seo_checks/inline_scripts.py | 11 + scripts/seo_checks/learning_resource.py | 47 + scripts/seo_checks/newsletter_third_party.py | 9 + scripts/seo_checks/resource_pagination.py | 67 ++ scripts/seo_checks/search_heading.py | 9 + scripts/seo_checks/share_image_metadata.py | 31 + scripts/seo_checks/single_h1.py | 5 + scripts/tests/test_check_seo_html.py | 409 +-------- scripts/tests/test_seo_breadcrumb_links.py | 19 + scripts/tests/test_seo_citation_targets.py | 29 + .../tests/test_seo_cluster_title_markup.py | 38 + scripts/tests/test_seo_clusters_map.py | 45 + .../tests/test_seo_description_entities.py | 37 + scripts/tests/test_seo_flora_citation.py | 33 + scripts/tests/test_seo_glossary_aka_filter.py | 41 + scripts/tests/test_seo_glossary_links.py | 38 + .../test_seo_glossary_related_language.py | 43 + .../tests/test_seo_glossary_title_markdown.py | 29 + scripts/tests/test_seo_inline_scripts.py | 27 + scripts/tests/test_seo_resource_pagination.py | 67 ++ .../tests/test_seo_share_image_metadata.py | 33 + 43 files changed, 1465 insertions(+), 1147 deletions(-) create mode 100644 scripts/seo_checks/__init__.py create mode 100644 scripts/seo_checks/_site.py create mode 100644 scripts/seo_checks/breadcrumb_jsonld.py create mode 100644 scripts/seo_checks/breadcrumb_links.py create mode 100644 scripts/seo_checks/citation_targets.py create mode 100644 scripts/seo_checks/cluster_title_markup.py create mode 100644 scripts/seo_checks/clusters_map.py create mode 100644 scripts/seo_checks/conditional_assets.py create mode 100644 scripts/seo_checks/description_entities.py create mode 100644 scripts/seo_checks/description_present.py create mode 100644 scripts/seo_checks/flora_citation.py create mode 100644 scripts/seo_checks/glossary_aka_filter.py create mode 100644 scripts/seo_checks/glossary_links.py create mode 100644 scripts/seo_checks/glossary_related_language.py create mode 100644 scripts/seo_checks/glossary_title_markdown.py create mode 100644 scripts/seo_checks/homepage_assets.py create mode 100644 scripts/seo_checks/homepage_img_dims.py create mode 100644 scripts/seo_checks/homepage_share_image.py create mode 100644 scripts/seo_checks/img_alt.py create mode 100644 scripts/seo_checks/inline_scripts.py create mode 100644 scripts/seo_checks/learning_resource.py create mode 100644 scripts/seo_checks/newsletter_third_party.py create mode 100644 scripts/seo_checks/resource_pagination.py create mode 100644 scripts/seo_checks/search_heading.py create mode 100644 scripts/seo_checks/share_image_metadata.py create mode 100644 scripts/seo_checks/single_h1.py create mode 100644 scripts/tests/test_seo_breadcrumb_links.py create mode 100644 scripts/tests/test_seo_citation_targets.py create mode 100644 scripts/tests/test_seo_cluster_title_markup.py create mode 100644 scripts/tests/test_seo_clusters_map.py create mode 100644 scripts/tests/test_seo_description_entities.py create mode 100644 scripts/tests/test_seo_flora_citation.py create mode 100644 scripts/tests/test_seo_glossary_aka_filter.py create mode 100644 scripts/tests/test_seo_glossary_links.py create mode 100644 scripts/tests/test_seo_glossary_related_language.py create mode 100644 scripts/tests/test_seo_glossary_title_markdown.py create mode 100644 scripts/tests/test_seo_inline_scripts.py create mode 100644 scripts/tests/test_seo_resource_pagination.py create mode 100644 scripts/tests/test_seo_share_image_metadata.py diff --git a/AGENTS.md b/AGENTS.md index a6254100d8a..c5539cc3dd0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,7 +19,7 @@ Much of the site is generated from Google Sheets and Docs, and the generated fil Run both against a build (`hugo -d `), as `deploy.yaml` does: -- `python3 scripts/check_seo_html.py `. Add a regression check here when you fix a template. +- `python3 scripts/check_seo_html.py `. When you fix a template, add a regression check as a new module in `scripts/seo_checks/` (a docstring and `check(site)`), with tests in `scripts/tests/test_seo_.py`; the runner finds it, so no shared file changes. - `python3 scripts/check_sitemap_lastmod.py /sitemap.xml [--compare-source]` (needs full Git history). Unit tests: `python3 -m unittest discover -s scripts/tests`. `scripts/test_parse_disciplines_gdoc.py` sits outside that folder and no CI job runs it: `python3 -m unittest discover -s scripts -p 'test_parse_disciplines_gdoc.py'`. diff --git a/content/resources/resource.py b/content/resources/resource.py index 6f7d93b92aa..e12ebbd4ce1 100644 --- a/content/resources/resource.py +++ b/content/resources/resource.py @@ -102,7 +102,7 @@ def wrangle_data(df): # Titles and abstracts pasted from publisher pages can carry HTML entities such as # "“". Hugo escapes the "&" again, so pages showed "“" as text and the -# meta description failed check 10 of scripts/check_seo_html.py. Only complete +# meta description failed scripts/seo_checks/description_entities.py. Only complete # entities ending in ";" are decoded, so a bare "&" stays as it is, and a name is # decoded only if the whole name is an HTML entity. "<" and ">" stay encoded: # abstracts are rendered as Markdown with raw HTML allowed, so decoding them diff --git a/scripts/check_seo_html.py b/scripts/check_seo_html.py index 1846c8845ad..fe7868099d7 100644 --- a/scripts/check_seo_html.py +++ b/scripts/check_seo_html.py @@ -3,674 +3,67 @@ Run: python3 scripts/check_seo_html.py public -Hard checks (exit 1 if any fails): - 1. No page carries an

whose text is exactly "Search". - 2. The homepage loads no Mermaid or highlight.js script or stylesheet. - 3. highlight.min.js is loaded exactly on pages with a
 block in
-     their content (the cite modal's  on every page does
-     not count; language-mermaid blocks belong to Mermaid), and mermaid.min.js
-     exactly on pages with a language-mermaid block.
-  4. Every  carries an alt attribute (a bare `alt` counts as present).
-  5. Every homepage  carries both width and height, so the browser reserves
-     its box before the file loads (#869).
-  6. The homepage share image (og:image, twitter:image) is a 1200x630 PNG or
-     JPEG (per og:image:width/height), and twitter:card is summary_large_image.
-     X and LinkedIn show no preview for WebP (#870).
-  8. Every curated-resource page carries exactly one LearningResource JSON-LD
-     block that parses, has a name and url, and holds no empty or placeholder
-     values (#863). Every JSON-LD block on those pages must parse.
-  7. Breadcrumb JSON-LD (#867): at most one BreadcrumbList per page; every
-     itemListElement is a non-empty list of objects; every ListItem has a
-     non-empty item URL; positions run 1..n; the page has a canonical link and
-     the last item is that URL; no name repeats, except that the current page
-     may share the root's name (an author or glossary term called "FORRT").
-  9. Every indexable page (no robots noindex, not a meta-refresh redirect) has a
-     non-empty meta description (#864).
-  10. No meta description contains a double-escaped entity such as `&ldquo;`
-     (#864). Text that merely looks like an entity (`&name;`) is not one.
-  11. No page has more than one 

(#928). - 12. Numbered resource subsets have unique, self-canonical metadata and - CollectionPage data matching their HTML cards (#868). - 13. PNG/JPEG social images have matching Open Graph/Twitter URLs, type and - positive dimensions (#927). Unsupported formats remain report-only. - 14. No page inlines more than 200 KB in one ' - '

Resource

') % (name, url, url, name, number, json.dumps(data), resource) - pages.append(page_from_html(text, relative + "index.html")) - return pages - - def test_self_canonical_numbered_subsets_pass_with_preview_prefix(self): - for prefix in ("", "/rebrand-doors"): - with self.subTest(prefix=prefix): - self.assertEqual(seo.check_resource_pagination(self.pages(prefix)), []) - - def test_staging_noindex_applies_to_directory_and_subsets(self): - pages = self.pages("/rebrand-doors") - for page in pages: - page.noindex = True - self.assertEqual(seo.check_resource_pagination(pages), []) - - def test_repeated_first_page_metadata_fails(self): - pages = self.pages() - pages[1].canonical = pages[0].canonical - pages[1].title = pages[0].title - pages[1].descriptions = pages[0].descriptions - failures = seo.check_resource_pagination(pages) - self.assertEqual(len(failures), 1) - for text in ("not self-canonical", "repeated title", "repeated description", "omits page number"): - self.assertIn(text, failures[0]) - - def test_wrong_structured_subset_fails(self): - pages = self.pages() - pages[1].resource_links = pages[0].resource_links - self.assertIn("subset does not match HTML cards", seo.check_resource_pagination(pages)[0]) - - def test_query_canonical_is_never_used_for_subsets(self): - pages = self.pages() - pages[1].canonical += "?type=reading" - self.assertIn("not self-canonical", seo.check_resource_pagination(pages)[0]) - - -class InlineScriptCheck(unittest.TestCase): - def failures(self, body): - with tempfile.TemporaryDirectory() as public: - (Path(public) / "index.html").write_text("%s" % body, encoding="utf-8") - return seo.check_inline_scripts(seo.load_pages(public)) - - def test_small_inline_and_external_scripts_pass(self): - self.assertEqual(self.failures(""), []) - - def test_inline_data_over_the_limit_fails(self): - data = "x" * (seo.MAX_INLINE_SCRIPT + 1) - self.assertEqual(self.failures("" % data), ["index.html (200 KB)"]) - - def test_unclosed_inline_data_fails(self): - data = "x" * (seo.MAX_INLINE_SCRIPT + 1) - self.assertEqual(self.failures(""), []) + + def test_inline_data_over_the_limit_fails(self): + data = "x" * (inline_scripts.MAX_INLINE_SCRIPT + 1) + self.assertEqual(self.failures("" % data), ["index.html (200 KB)"]) + + def test_unclosed_inline_data_fails(self): + data = "x" * (inline_scripts.MAX_INLINE_SCRIPT + 1) + self.assertEqual(self.failures("' + '

Resource

') % (name, url, url, name, number, json.dumps(data), resource) + pages.append(page_from_html(text, relative + "index.html")) + return pages + + def test_self_canonical_numbered_subsets_pass_with_preview_prefix(self): + for prefix in ("", "/rebrand-doors"): + with self.subTest(prefix=prefix): + self.assertEqual(check(self.pages(prefix)), []) + + def test_staging_noindex_applies_to_directory_and_subsets(self): + pages = self.pages("/rebrand-doors") + for page in pages: + page.noindex = True + self.assertEqual(check(pages), []) + + def test_repeated_first_page_metadata_fails(self): + pages = self.pages() + pages[1].canonical = pages[0].canonical + pages[1].title = pages[0].title + pages[1].descriptions = pages[0].descriptions + failures = check(pages) + self.assertEqual(len(failures), 1) + for text in ("not self-canonical", "repeated title", "repeated description", "omits page number"): + self.assertIn(text, failures[0]) + + def test_wrong_structured_subset_fails(self): + pages = self.pages() + pages[1].resource_links = pages[0].resource_links + self.assertIn("subset does not match HTML cards", check(pages)[0]) + + def test_query_canonical_is_never_used_for_subsets(self): + pages = self.pages() + pages[1].canonical += "?type=reading" + self.assertIn("not self-canonical", check(pages)[0]) + + +if __name__ == "__main__": + unittest.main() diff --git a/scripts/tests/test_seo_share_image_metadata.py b/scripts/tests/test_seo_share_image_metadata.py new file mode 100644 index 00000000000..516549654be --- /dev/null +++ b/scripts/tests/test_seo_share_image_metadata.py @@ -0,0 +1,33 @@ +import sys +import unittest +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parents[1])) +from seo_checks import share_image_metadata # noqa: E402 +from seo_checks._site import Site, page_from_html # noqa: E402 + + +class ShareImageMetadataCheck(unittest.TestCase): + def failures(self, **overrides): + meta = {"og:image": "https://example.org/preview/social/test.png", + "twitter:image": "https://example.org/preview/social/test.png", + "og:image:type": "image/png", "og:image:width": "7", "og:image:height": "5"} + meta.update(overrides) + page = page_from_html("".join('' % (k, v) for k, v in meta.items())) + return share_image_metadata.check(Site("", [page])) + + def test_matching_png_metadata_passes(self): + self.assertEqual(self.failures(), []) + + def test_incorrect_type_dimensions_or_twitter_url_fail(self): + for change in ({"og:image:type": "image/webp"}, {"og:image:width": "0"}, + {"og:image:height": "unknown"}, {"twitter:image": "original.webp"}): + with self.subTest(change=change): + self.assertTrue(self.failures(**change)) + + def test_undecodable_original_remains_report_only(self): + self.assertEqual(self.failures(**{"og:image": "original.webp"}), []) + + +if __name__ == "__main__": + unittest.main() From 73b654057ee962879a303a10bacd52c1528cef25 Mon Sep 17 00:00:00 2001 From: Lukas Wallrich Date: Thu, 19 Nov 2026 16:24:02 +0000 Subject: [PATCH 2/2] Drop the FLoRA citation check It looked for one hard-coded DOI on one page: a content check, not a template regression. Co-Authored-By: Claude Opus 5.5 --- scripts/seo_checks/flora_citation.py | 19 -------------- scripts/tests/test_seo_flora_citation.py | 33 ------------------------ 2 files changed, 52 deletions(-) delete mode 100644 scripts/seo_checks/flora_citation.py delete mode 100644 scripts/tests/test_seo_flora_citation.py diff --git a/scripts/seo_checks/flora_citation.py b/scripts/seo_checks/flora_citation.py deleted file mode 100644 index c94eeeed889..00000000000 --- a/scripts/seo_checks/flora_citation.py +++ /dev/null @@ -1,19 +0,0 @@ -"""The FLoRA page shows its citation. - -The FLoRA page (replication-hub/flora/) contains the FLoRA citation DOI. -""" - -import os - -FLORA_PAGE = "replication-hub/flora/index.html" - - -def check(site): - path = os.path.join(site.public_dir, FLORA_PAGE) - if not os.path.exists(path): - return ["%s (page not found)" % FLORA_PAGE] - with open(path, encoding="utf-8") as handle: - html = handle.read() - if "doi.org/10.17605/OSF.IO/9R62X" not in html: - return ["%s (no FLoRA DOI in the citation)" % FLORA_PAGE] - return [] diff --git a/scripts/tests/test_seo_flora_citation.py b/scripts/tests/test_seo_flora_citation.py deleted file mode 100644 index a4b7e172e5d..00000000000 --- a/scripts/tests/test_seo_flora_citation.py +++ /dev/null @@ -1,33 +0,0 @@ -import sys -import tempfile -import unittest -from pathlib import Path - -sys.path.insert(0, str(Path(__file__).resolve().parents[1])) -from seo_checks import flora_citation # noqa: E402 -from seo_checks._site import Site # noqa: E402 - - -def flora_failures(html): - """The check on a FLoRA page with this HTML (None: no page).""" - with tempfile.TemporaryDirectory() as public: - if html is not None: - page = Path(public) / flora_citation.FLORA_PAGE - page.parent.mkdir(parents=True) - page.write_text(html, encoding="utf-8") - return flora_citation.check(Site(public, [])) - - -class FloraCitationCheck(unittest.TestCase): - DOI = 'https://doi.org/10.17605/OSF.IO/9R62X' - - def test_citation_passes(self): - self.assertEqual(flora_failures("

Wallrich, L.*, ... %s

" % self.DOI), []) - - def test_missing_citation_or_page_fails(self): - self.assertIn("DOI", flora_failures("

How to cite:

")[0]) - self.assertIn("not found", flora_failures(None)[0]) - - -if __name__ == "__main__": - unittest.main()