Software security research, and the tools we build for it.
+
diff --git a/scripts/check-copy.py b/scripts/check-copy.py
index d7df68f..b5c697d 100644
--- a/scripts/check-copy.py
+++ b/scripts/check-copy.py
@@ -1,4 +1,5 @@
"""Fail when the site's tagline, work-area cards or tools list differ from the org profile README's."""
+
import re
import sys
import urllib.request
@@ -9,22 +10,60 @@
def profile_copy(md: str) -> tuple[str, list[tuple[str, str]], list[tuple[str, str]]]:
tagline = re.search(r'
\s*([^<]+?)\s*
', md).group(1)
- tools = re.findall(r"^- \[([^\]]+)\]\(https://github\.com/Totative/[^)]+\): (.+)$", md, re.M)
+ tools = re.findall(
+ r"^- \[([^\]]+)\]\(https://github\.com/Totative/[^)]+\): (.+)$", md, re.M
+ )
return tagline, re.findall(r"
([^<]+) ([^<]+)", md), tools
def site_copy(html: str) -> tuple[str, list[tuple[str, str]], list[tuple[str, str]]]:
- tagline = re.search(r"
([^<]+)
", html).group(1)
- tools = re.findall(r'
([^<]+) : ([^<]+)', html)
+ tagline = re.search(r"
([^<]+) ", html).group(1)
+ tools = re.findall(
+ r'
([^<]+) : ([^<]+)',
+ html,
+ )
return tagline, re.findall(r"
([^<]+) ([^<]+)
", html), tools
+def check_canonical(layout: str) -> None:
+ if '
' not in layout:
+ raise SystemExit("pages need a totative.dev canonical")
+
+
+def check_home_h1(html: str) -> None:
+ if re.search(r"^
[^<]+ \s*$", html, re.M) is None:
+ raise SystemExit("home lede must be an h1")
+
+
+def check_404_noindex(layout: str, not_found: str) -> None:
+ branch = re.search(
+ r"\{%\s*if page\.noindex\s*%\}(.*)\{%\s*else\s*%\}(.*)\{%\s*endif\s*%\}",
+ layout,
+ re.S,
+ )
+ if branch is None:
+ raise SystemExit("default layout needs a page.noindex branch")
+ if 'name="robots" content="noindex"' not in branch.group(1):
+ raise SystemExit("noindex branch missing robots meta")
+ if 'rel="canonical"' in branch.group(1):
+ raise SystemExit("noindex branch must not emit canonical")
+ if re.search(r"^noindex:\s*true\s*$", not_found, re.M) is None:
+ raise SystemExit("404.html needs noindex: true")
+
+
def main() -> int:
+ layout = Path("_layouts/default.html").read_text()
+ check_canonical(layout)
+ index = Path("index.html").read_text()
+ check_home_h1(index)
+ check_404_noindex(layout, Path("404.html").read_text())
md = urllib.request.urlopen(PROFILE, timeout=30).read().decode()
- want, have = profile_copy(md), site_copy(Path("index.html").read_text())
+ want, have = profile_copy(md), site_copy(index)
assert want[1], "no cards found in the profile README"
if want == have:
- print(f"site copy matches the profile: tagline, {len(have[1])} cards, {len(have[2])} tools")
+ print(
+ f"site copy matches the profile: tagline, {len(have[1])} cards, {len(have[2])} tools"
+ )
return 0
print(f"profile: {want}\nsite: {have}", file=sys.stderr)
return 1
diff --git a/scripts/check-unpublished.py b/scripts/check-unpublished.py
new file mode 100644
index 0000000..22de7be
--- /dev/null
+++ b/scripts/check-unpublished.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+"""Fail if AGENTS.md or CLAUDE.md would ship with the site."""
+
+from __future__ import annotations
+
+import re
+import sys
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[1]
+NAMES = ("AGENTS.md", "CLAUDE.md")
+
+
+def excluded_paths(config: str) -> list[str]:
+ match = re.search(r"^exclude:\s*\[(.*)\]\s*$", config, re.M)
+ if match is None:
+ raise SystemExit("_config.yml has no exclude list")
+ return [
+ part.strip().strip("'\"") for part in match.group(1).split(",") if part.strip()
+ ]
+
+
+def main() -> int:
+ excluded = excluded_paths((ROOT / "_config.yml").read_text())
+ missing = [name for name in NAMES if name not in excluded]
+ if missing:
+ print("exclude lacks " + ", ".join(missing), file=sys.stderr)
+ return 1
+ site = ROOT / "_site"
+ if site.is_dir():
+ published = [name for name in NAMES if (site / name).is_file()]
+ if published:
+ print("_site contains " + ", ".join(published), file=sys.stderr)
+ return 1
+ return 0
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())