From 3eef7a93144b554ab63de8213ee46e10dee1c15c Mon Sep 17 00:00:00 2001 From: popovskik Date: Wed, 5 Aug 2026 18:32:55 +0200 Subject: [PATCH] Add pre-commit hook to auto-sync News/homepage/bot pages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Versioned hook at tools/git-hooks/pre-commit runs build_listings.py and build_botlinks.py on every commit and stages their output, so the News hub, homepage "Latest news", /llms.txt and /links-for-bots/ always reflect the actual Blog/Projects/News content — no manual step. Non-blocking: warns and proceeds if Python or a generator fails. Activated with `git config core.hooksPath tools/git-hooks`. Co-Authored-By: Claude Opus 4.8 (1M context) --- tools/git-hooks/README.md | 22 +++++++++++++++++++++ tools/git-hooks/pre-commit | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 tools/git-hooks/README.md create mode 100755 tools/git-hooks/pre-commit diff --git a/tools/git-hooks/README.md b/tools/git-hooks/README.md new file mode 100644 index 00000000..b8a09cae --- /dev/null +++ b/tools/git-hooks/README.md @@ -0,0 +1,22 @@ +# Git hooks + +Versioned hooks that keep auto-generated files in sync. + +## Activate (once per clone) + +```sh +git config core.hooksPath tools/git-hooks +``` + +That points git at this folder. From then on, every `git commit` runs +`tools/build_listings.py` and `tools/build_botlinks.py` and stages their output, +so the News hub, homepage "Latest news", `/llms.txt` and `/links-for-bots/` stay +in sync with the actual Blog / Projects / News pages. + +The hook never blocks a commit — if Python or a generator fails it just prints a +warning and lets the commit proceed. + +> Note: SEO metadata and the sitemap are **not** regenerated on commit (that is a +> heavier, all-pages pass). When you add a new page, also add its date to +> `ARTICLE_DATES` in `tools/seo_inject.py` and run +> `python tools/seo_inject.py --all --sitemap`. diff --git a/tools/git-hooks/pre-commit b/tools/git-hooks/pre-commit new file mode 100755 index 00000000..d352d667 --- /dev/null +++ b/tools/git-hooks/pre-commit @@ -0,0 +1,39 @@ +#!/bin/sh +# --------------------------------------------------------------------------- +# MSOS pre-commit hook — keeps derived files in sync automatically. +# +# On every commit it regenerates and stages: +# - the News hub grid + homepage "Latest news" (tools/build_listings.py) +# - /llms.txt and /links-for-bots/ (tools/build_botlinks.py) +# so adding a blog post or an event/project flows through to News, the homepage +# and the bot pages without any manual command. +# +# It never blocks a commit: if Python or a generator fails, it warns and lets +# the commit proceed. +# +# Activate once per clone: git config core.hooksPath tools/git-hooks +# --------------------------------------------------------------------------- +set -u + +PY="$(command -v python || command -v python3 || true)" +if [ -z "$PY" ]; then + echo "pre-commit: Python not found — skipping News/bot regeneration." >&2 + exit 0 +fi + +# Run from the repo root regardless of where git invoked the hook. +ROOT="$(git rev-parse --show-toplevel 2>/dev/null || echo .)" +cd "$ROOT" || exit 0 + +"$PY" tools/build_listings.py >/dev/null 2>&1 \ + || echo "pre-commit: build_listings.py failed — News/homepage not refreshed." >&2 +"$PY" tools/build_botlinks.py >/dev/null 2>&1 \ + || echo "pre-commit: build_botlinks.py failed — bot pages not refreshed." >&2 + +# Stage only the generated outputs (no-op if unchanged). +git add -- \ + en/news/index.html mk/news/index.html si/news/index.html \ + en/index.html mk/index.html si/index.html \ + llms.txt links-for-bots >/dev/null 2>&1 || true + +exit 0