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
25 changes: 24 additions & 1 deletion tests/test_seo.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def test_legacy_redirects_keep_individual_targets_across_new_stable(self):
(self.site / "versions.json").write_text(
json.dumps(self.catalog), encoding="utf-8")
self.page("index.html", '<div id="main-content"></div>')
with patch("versioning.build.version_overview", return_value=self.page("index.html").read_text()):
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/index.html": "15/user_manual/index.html",
"user_manual/functionality.html": "main/user_manual/functionality.html",
Expand All @@ -64,6 +65,28 @@ def test_legacy_redirects_keep_individual_targets_across_new_stable(self):
self.assertIn("url=/main/user_manual/functionality.html", redirect)
self.assertNotIn("url=/15/user_manual/index.html", redirect)

def test_preview_legacy_routes_and_placeholder_are_not_indexable(self):
self.page("15/index.html")
self.page("main/user_manual/functionality.html")
self.page("index.html")
(self.site / "versions.json").write_text(json.dumps(self.catalog))
prefix = "/site-preview/docs-preview/pr-7"
with patch.dict("os.environ", {
"LIBRESIGN_DOC_BASE_PATH": prefix,
"LIBRESIGN_PREVIEW_PR": "7",
}), 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, preview=True)

redirect = (self.site / "user_manual/functionality.html").read_text()
self.assertIn(f"url={prefix}/main/user_manual/functionality.html", redirect)
self.assertEqual(verify_seo(self.site, self.catalog, preview=True), [])
self.assertIn('name="robots" content="noindex,follow"',
(self.site / "_review/index.html").read_text())

def test_missing_redirect_destination_fails_before_deploy(self):
self.page("15/index.html")
(self.site / "versions.json").write_text(json.dumps(self.catalog))
Expand Down
9 changes: 5 additions & 4 deletions versioning/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ def legacy_redirects(output: Path, current: str, *, routes: dict[str, str] | Non
entry = output / "_review/index.html"
entry.parent.mkdir(parents=True, exist_ok=True)
entry.write_text(
"<!doctype html><html lang='en'><meta charset='utf-8'>"
"<title>Preview-only documentation</title>"
"<h1>Preview-only documentation</h1>"
"<p>Release-specific review pages are generated after validation.</p>",
"<!doctype html><html lang='en'><head><meta charset='utf-8'>"
"<title>Preview-only documentation</title></head><body>"
"<main><h1>Preview-only documentation</h1>"
"<p>Release-specific review pages are generated after validation.</p>"
"</main></body></html>",
encoding="utf-8",
)
# The previous unversioned URLs are a permanent migration interface.
Expand Down
Loading