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
3 changes: 2 additions & 1 deletion robots.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
User-agent: *
Allow: /

Sitemap: https://nscheuer.github.io/sitemap-index.xml
Sitemap: https://nscheuer.github.io/sitemap.xml
Sitemap: https://nscheuer.github.io/Generalized_ADCS/sitemap.xml
Sitemap: https://nscheuer.github.io/Generalized_ADCS/sitemap.xml
29 changes: 24 additions & 5 deletions scripts/check_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ROOT = Path(__file__).resolve().parents[1]
SITE_URL = "https://nscheuer.github.io/"
SITEMAP_URL = f"{SITE_URL}sitemap.xml"
SITEMAP_INDEX_URL = f"{SITE_URL}sitemap-index.xml"


class LocalReferenceParser(HTMLParser):
Expand Down Expand Up @@ -61,17 +62,35 @@ def repo_path_from_url(value: str, source: Path) -> Path | None:


def check_sitemap() -> None:
for sitemap in sorted(ROOT.glob("sitemap*.xml")):
ET.parse(sitemap)
text = sitemap.read_text(encoding="utf-8-sig")
if not text.lstrip().startswith("<?xml"):
fail(f"{sitemap.name} should start with an XML declaration")

sitemap = ROOT / "sitemap.xml"
sitemap_index = ROOT / "sitemap-index.xml"
if not sitemap.is_file():
fail("sitemap.xml is missing")
if not sitemap_index.is_file():
fail("sitemap-index.xml is missing")

ET.parse(sitemap)
text = sitemap.read_text(encoding="utf-8-sig")
if not text.lstrip().startswith("<?xml"):
fail("sitemap.xml should start with an XML declaration")
if SITEMAP_URL not in (ROOT / "robots.txt").read_text(encoding="utf-8"):
robots = (ROOT / "robots.txt").read_text(encoding="utf-8")
if SITEMAP_INDEX_URL not in robots:
fail(f"robots.txt does not advertise {SITEMAP_INDEX_URL}")
if SITEMAP_URL not in robots:
fail(f"robots.txt does not advertise {SITEMAP_URL}")

index_root = ET.parse(sitemap_index).getroot()
namespace = {"sm": "http://www.sitemaps.org/schemas/sitemap/0.9"}
for loc in index_root.findall("sm:sitemap/sm:loc", namespace):
if not loc.text or not loc.text.startswith(SITE_URL):
fail(f"sitemap-index.xml has invalid sitemap location: {loc.text!r}")

relative_path = loc.text.removeprefix(SITE_URL)
if "/" not in relative_path and not (ROOT / relative_path).is_file():
fail(f"sitemap-index.xml points to missing local sitemap: {loc.text}")


def check_html_references() -> None:
html_files = sorted(ROOT.glob("**/*.html"))
Expand Down
3 changes: 0 additions & 3 deletions sitemap-index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@
<sitemap>
<loc>https://nscheuer.github.io/Generalized_ADCS/sitemap.xml</loc>
</sitemap>
<sitemap>
<loc>https://nscheuer.github.io/SALTRO/sitemap.xml</loc>
</sitemap>
</sitemapindex>
3 changes: 3 additions & 0 deletions sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<url>
<loc>https://nscheuer.github.io/</loc>
</url>
<url>
<loc>https://nscheuer.github.io/Generalized_ADCS/</loc>
</url>
<url>
<loc>https://nscheuer.github.io/projects/project-local-assistant-and-compute.html</loc>
</url>
Expand Down
Loading