Skip to content

armgit / xerj

Public Imported from GitHub
0

AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.

fix(seo): stop the hub pages dating themselves from their own commit (#973)

xerj-org20afe0181519
diff --git a/landing/compare/index.html b/landing/compare/index.html
index f3b1c04d8..16e8ba1ad 100644
--- a/landing/compare/index.html
+++ b/landing/compare/index.html
@@ -63,7 +63,7 @@
"url": "https://xerj.org/compare/",
"image": "https://xerj.org/og/xerj-card.png",
"inLanguage": "en",
- "dateModified": "2026-09-19",
+ "dateModified": "2026-08-23",
"isPartOf": {
"@id": "https://xerj.org/#website"
},
diff --git a/scripts/seo/build_articles.py b/scripts/seo/build_articles.py
index 4940fd60d..49719d767 100644
--- a/scripts/seo/build_articles.py
+++ b/scripts/seo/build_articles.py
@@ -811,12 +811,19 @@ def render_hub(category: str, articles: list[article_data.Article],
context: BuildContext) -> str:
rel = f"{category}/index.html"
meta = dict(pagedata.entry(rel))
- target = context.landing / rel
- if target.exists():
- modified = context.dates.last_modified(target)
- published = context.dates.first_published(target)
+ # A hub's dates come from the articles it lists, never from the hub file
+ # itself: reading the generated file's own git date makes the output depend
+ # on the commit that wrote it, so committing a regenerated hub changes the
+ # value it should have had. Every merge that touches the file on a later
+ # date then re-stales it and `--check` fails on main (that is #942's red
+ # gate, and #972's re-red one commit later). Article pages never had the
+ # problem because they date from their content source.
+ listed = [a for a in articles if a.category == category]
+ if listed:
+ modified = max(article_modified(a, context) for a in listed)
+ published = min(a.published for a in listed if a.published) or modified
else:
- modified = published = dt.date.today().isoformat()
+ modified = published = dt.datetime.now(dt.timezone.utc).date().isoformat()
block = seo_head.build_block(rel, meta["title"], meta["description"],
published, modified, meta)
groups: dict[str, list[article_data.Article]] = collections.defaultdict(list)
diff --git a/scripts/seo/fix_heads.py b/scripts/seo/fix_heads.py
index b30a56e4f..7ed22d8ea 100755
--- a/scripts/seo/fix_heads.py
+++ b/scripts/seo/fix_heads.py
@@ -141,6 +141,15 @@ def transform(rel: str, src: str, dates: urlmap.DateSource,
source_path = pathlib.Path(meta["_source_path"]) if meta.get("_source_path") else path
published = meta.get("published") or dates.first_published(path)
modified = meta.get("updated") or dates.last_modified(source_path)
+ # A page with no content source (the answers/ and compare/ hubs) would
+ # otherwise be dated from its own git history: writing the regenerated file
+ # changes the date the next run computes, so `--check` fails on main the
+ # first time a merge touches the file on a later date. build_articles.py
+ # dates those hubs from the articles they list; keep what it wrote.
+ if not meta.get("_source_path"):
+ kept = _existing_ld_dates(src)
+ published = kept.get("datePublished", published)
+ modified = kept.get("dateModified", modified)
block = build_block(rel, title, desc, published, modified, meta)
head = head.rstrip("\n \t") + "\n" + block + "\n"
@@ -155,6 +164,16 @@ def transform(rel: str, src: str, dates: urlmap.DateSource,
return out
+
+def _existing_ld_dates(src: str) -> dict[str, str]:
+ """datePublished/dateModified already in the page's JSON-LD, if any."""
+ out: dict[str, str] = {}
+ for key in ("datePublished", "dateModified"):
+ m = re.search(r'"%s"\s*:\s*"(\d{4}-\d{2}-\d{2})"' % key, src)
+ if m:
+ out[key] = m.group(1)
+ return out
+
def main(argv: list[str] | None = None) -> int:
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
ap.add_argument("--write", action="store_true", help="rewrite files in place")
diff --git a/scripts/seo/gen_sitemap.py b/scripts/seo/gen_sitemap.py
index 6da47cdec..6299e4718 100755
--- a/scripts/seo/gen_sitemap.py
+++ b/scripts/seo/gen_sitemap.py
@@ -56,7 +56,10 @@ def build(root: pathlib.Path, dates: urlmap.DateSource) -> str:
rows.append((urlmap.deployed_url(rel), dates.last_modified(root / rel)))
rows.sort()
- today = dt.date.today().isoformat()
+ # UTC, like the dates themselves: dt.date.today() is the runner's local
+ # date, so this clamp used to rewrite a legitimate date on one machine and
+ # not on another.
+ today = dt.datetime.now(dt.timezone.utc).date().isoformat()
out = ['<?xml version="1.0" encoding="UTF-8"?>',
f'<urlset xmlns="{SITEMAP_NS}">']
for loc, lastmod in rows:
diff --git a/scripts/seo/seo_lint.py b/scripts/seo/seo_lint.py
index 2f02ed308..a322dd9cc 100755
--- a/scripts/seo/seo_lint.py
+++ b/scripts/seo/seo_lint.py
@@ -941,7 +941,7 @@ def _head_of(src: str) -> str:
def _today() -> str:
import datetime
- return datetime.date.today().isoformat()
+ return datetime.datetime.now(datetime.timezone.utc).date().isoformat()
def main(argv: list[str] | None = None) -> int:
diff --git a/scripts/seo/urlmap.py b/scripts/seo/urlmap.py
index d1b0f6313..f609d0f2f 100755
--- a/scripts/seo/urlmap.py
+++ b/scripts/seo/urlmap.py
@@ -32,6 +32,7 @@ Primary sources
from __future__ import annotations
import datetime as _dt
+import os
import pathlib
import re
import subprocess
@@ -301,12 +302,20 @@ class DateSource:
def _git_date(self, path: pathlib.Path, first: bool = False) -> str | None:
if not self.git_ok:
return None
- cmd = ["git", "-C", str(self.repo_root), "log", "--format=%cs"]
+ # %cs renders the committer date in the COMMIT's own timezone, so a
+ # commit made at 22:34 UTC from a +02:00 machine reads 2026-09-20 here
+ # and 2026-09-19 on a UTC CI runner — the generated files then differ
+ # by machine and `--check` fails for hours every evening. Dates are
+ # UTC everywhere instead.
+ cmd = ["git", "-C", str(self.repo_root), "log",
+ "--date=format-local:%Y-%m-%d", "--format=%cd"]
if not first:
cmd.append("-1")
cmd += ["--", str(path)]
+ env = {**os.environ, "TZ": "UTC"}
try:
- r = subprocess.run(cmd, capture_output=True, text=True, timeout=30)
+ r = subprocess.run(cmd, capture_output=True, text=True, timeout=30,
+ env=env)
except (OSError, subprocess.SubprocessError):
return None
if r.returncode != 0: