Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions tests/test_seo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<meta name="robots" content="noindex,follow" />', 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(
'<meta name="robots" content="noindex,follow" />', ""))
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")
Expand Down
7 changes: 7 additions & 0 deletions tests/test_versioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -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('<meta name="robots" content="noindex,follow" />', ""))
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",
Expand Down Expand Up @@ -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('<meta name="robots" content="noindex,follow" />', markup)
self.assertNotIn("/main/", markup)

def test_preview_redirects_stay_under_isolated_origin(self):
Expand Down
1 change: 1 addition & 0 deletions versioning/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def redirect_html(target: str) -> str:
json_target = json.dumps(target)
return (
"<!doctype html><html lang='en'><head><meta charset='utf-8'>"
'<meta name="robots" content="noindex,follow" />'
f"<meta http-equiv='refresh' content='0; url={quoted}'>"
f"<link rel='canonical' href='{quoted}'>"
"<title>LibreSign documentation has moved</title></head><body>"
Expand Down
2 changes: 2 additions & 0 deletions versioning/seo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 4 additions & 1 deletion versioning/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Loading