Add noindex pages, robots.txt and operator footer

- Page.noindex: marked pages get a robots meta tag and a Disallow line in the
  generated robots.txt (single source of truth in src/pages.py)
- templates/robots.txt: public pages indexable, noindex pages and data files not
- Footer shows an optional operator line from contents/snippets/footer_operator.md
- Tests for robots.txt, noindex meta and footer

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-10-10 15:33:37 +02:00
co-authored by Claude Sonnet 5.5
parent 874838f525
commit 81edf08d8e
5 changed files with 89 additions and 6 deletions
+48
View File
@@ -0,0 +1,48 @@
from src.build import Build
from src.config import Config
from src.pages import NOINDEX_DIRECTIVES
def write_site(tmp_path):
(tmp_path / "toc").mkdir()
(tmp_path / "contents" / "static").mkdir(parents=True)
(tmp_path / "contents" / "snippets").mkdir(parents=True)
(tmp_path / "contents" / "static" / "kontakt.html").write_text(
"<h1>Kontakt</h1> [email protected]", encoding="utf-8"
)
(tmp_path / "contents" / "static" / "info.html").write_text("<h1>Info</h1>", encoding="utf-8")
(tmp_path / "contents" / "snippets" / "footer_operator.md").write_text(
'Ansvarig: Test (SA0TST) &middot; <a href="kontakt.html" rel="nofollow">Kontakt</a>\n', encoding="utf-8"
)
def test_contact_page_is_noindex_and_listed_in_robots_txt(tmp_path):
write_site(tmp_path)
Build(Config(content_path=tmp_path, build_path=tmp_path / "build")).build_website()
out = tmp_path / "build"
robots = (out / "robots.txt").read_text(encoding="utf-8")
assert "User-agent: *" in robots
assert "Allow: /\n" in robots
assert "Disallow: /kontakt.html" in robots
assert "Disallow: /info.html" not in robots # normal pages stay indexable
assert f'<meta name="robots" content="{NOINDEX_DIRECTIVES}">' in (out / "kontakt.html").read_text(encoding="utf-8")
assert 'name="robots"' not in (out / "info.html").read_text(encoding="utf-8")
def test_footer_names_operator_without_contact_details(tmp_path):
write_site(tmp_path)
Build(Config(content_path=tmp_path, build_path=tmp_path / "build")).build_website()
info = (tmp_path / "build" / "info.html").read_text(encoding="utf-8")
assert "Ansvarig: Test (SA0TST)" in info
assert 'href="kontakt.html"' in info
assert "[email protected]" not in info
def test_no_footer_operator_without_snippet(tmp_path):
write_site(tmp_path)
(tmp_path / "contents" / "snippets" / "footer_operator.md").unlink()
Build(Config(content_path=tmp_path, build_path=tmp_path / "build")).build_website()
assert "Ansvarig" not in (tmp_path / "build" / "info.html").read_text(encoding="utf-8")