From e2f0883bf8cb44c9d56dca808162000bc6da53d0 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Fri, 13 Nov 2026 18:32:47 +0000 Subject: [PATCH] fix(docs): noindex legacy and alias redirect pages Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- tests/test_seo.py | 23 +++++++++++++++++++++++ tests/test_versioning.py | 7 +++++++ versioning/build.py | 1 + versioning/seo.py | 2 ++ versioning/verify.py | 5 ++++- 5 files changed, 37 insertions(+), 1 deletion(-) diff --git a/tests/test_seo.py b/tests/test_seo.py index f6bdf4be..f46df133 100644 --- a/tests/test_seo.py +++ b/tests/test_seo.py @@ -51,6 +51,29 @@ def test_legacy_redirects_keep_individual_targets_across_new_stable(self): redirect = (self.site / "user_manual/functionality.html").read_text() self.assertIn("url=/main/user_manual/functionality.html", redirect) self.assertNotIn("url=/15/user_manual/index.html", redirect) + self.assertIn('', redirect) + + def test_published_legacy_redirect_without_noindex_fails_verification(self): + self.page("15/index.html") + self.page("main/user_manual/functionality.html") + (self.site / "versions.json").write_text(json.dumps(self.catalog)) + (self.root / "versioning").mkdir() + (self.root / "versioning/legacy-routes.json").write_text(json.dumps({ + "user_manual/functionality.html": "main/user_manual/functionality.html", + })) + with patch.dict("os.environ", {"LIBRESIGN_DOC_BASE_PATH": ""}), \ + patch("versioning.build.version_overview", + return_value=self.page("index.html").read_text()): + legacy_redirects(self.site, "15", routes={ + "user_manual/functionality.html": "main/user_manual/functionality.html", + }) + apply_seo(self.site, self.catalog) + self.assertEqual(verify_seo(self.site, self.catalog, root=self.root), []) + page = self.site / "user_manual/functionality.html" + page.write_text(page.read_text().replace( + '', "")) + self.assertIn("Indexable legacy redirect: user_manual/functionality.html", + verify_seo(self.site, self.catalog, root=self.root)) def test_preview_legacy_routes_and_placeholder_are_not_indexable(self): self.page("15/index.html") diff --git a/tests/test_versioning.py b/tests/test_versioning.py index 1c9fa72b..247c94de 100644 --- a/tests/test_versioning.py +++ b/tests/test_versioning.py @@ -92,6 +92,12 @@ def test_moving_aliases_cover_deep_links_openapi_and_preview_prefix(self): (api / "openapi.provenance.json").write_text('{"branch": "' + slug + '"}') write_version_aliases(site, catalog) self.assertEqual(verify_version_aliases(site, catalog), []) + alias = site / "stable/developer_manual/api/openapi.html" + self.assertIn('name="robots" content="noindex,follow"', alias.read_text()) + alias.write_text(alias.read_text().replace('', "")) + self.assertTrue(any("Indexable /stable/ redirect" in error + for error in verify_version_aliases(site, catalog))) + write_version_aliases(site, catalog) self.assertIn("url=/site-preview/docs-preview/pr-149/main/developer_manual/api/openapi.html", (site / "latest/developer_manual/api/openapi.html").read_text()) self.assertIn("url=/site-preview/docs-preview/pr-149/15/developer_manual/api/openapi.html", @@ -188,6 +194,7 @@ def test_redirect_keeps_parameters_and_fragment(self): markup = redirect_html("/15/developer_manual/api/openapi.html") self.assertIn("location.search", markup) self.assertIn("location.hash", markup) + self.assertIn('', markup) self.assertNotIn("/main/", markup) def test_preview_redirects_stay_under_isolated_origin(self): diff --git a/versioning/build.py b/versioning/build.py index 851fdb93..82b9046a 100644 --- a/versioning/build.py +++ b/versioning/build.py @@ -87,6 +87,7 @@ def redirect_html(target: str) -> str: json_target = json.dumps(target) return ( "" + '' f"" f"" "LibreSign documentation has moved" diff --git a/versioning/seo.py b/versioning/seo.py index 7120afbf..2f4ef1d8 100644 --- a/versioning/seo.py +++ b/versioning/seo.py @@ -175,4 +175,6 @@ def verify_seo(site: Path, catalog: dict, *, preview: bool = False, markup = old_page.read_text(encoding="utf-8") if f"url=/{destination}" not in markup or 'http-equiv=\'refresh\'' not in markup: errors.append(f"Incorrect legacy redirect: {source} => {destination}") + if 'name="robots" content="noindex,follow"' not in markup: + errors.append(f"Indexable legacy redirect: {source}") return errors diff --git a/versioning/verify.py b/versioning/verify.py index adacbc7f..b526210a 100644 --- a/versioning/verify.py +++ b/versioning/verify.py @@ -41,6 +41,8 @@ def verify_version_aliases(output: Path, catalog: dict) -> list[str]: if (f"url={target_url}" not in content or "location.search" not in content or "location.hash" not in content): errors.append(f"Incorrect /{alias}/ redirect: {relative}") + if 'name="robots" content="noindex,follow"' not in content: + errors.append(f"Indexable /{alias}/ redirect: {relative}") for filename in ("openapi.json", "openapi.provenance.json"): relative = Path("developer_manual/api") / filename pinned = source / relative @@ -193,7 +195,8 @@ def verify_site(output: Path, versions: list[str] | None = None, if (output / ".nojekyll").exists(): errors.extend(verify_version_aliases(output, catalog)) errors.extend(verify_seo(output, catalog, - preview=bool(os.environ.get("LIBRESIGN_PREVIEW_PR")))) + preview=bool(os.environ.get("LIBRESIGN_PREVIEW_PR")), + root=Path(__file__).resolve().parent.parent)) if errors: raise ValueError("\n".join(errors[:60])) return {