.PHONY: help docs-index docs-build docs-serve docs-check slides test

help:
	@echo "Targets:"
	@echo "  docs-index   Regenerate docs/{hardware,services}/index.md from per-item frontmatter"
	@echo "  docs-build   Build the static MkDocs site into ./site (strict)"
	@echo "  docs-serve   Run a live-reload local preview server"
	@echo "  docs-check   Drift-check: regenerate indices, fail if they differ from the committed copies"
	@echo "  slides       Run build-slides.sh (Marp slides)"
	@echo "  test         Run the Python unit tests (pytest)"

docs-index:
	python3 scripts/gen_overview.py --category hardware
	python3 scripts/gen_overview.py --category services
	python3 scripts/gen_rack.py

docs-build:
	mkdocs build --strict

docs-serve:
	mkdocs serve

docs-check:
	python3 scripts/gen_overview.py --category hardware
	python3 scripts/gen_overview.py --category services
	python3 scripts/gen_rack.py
	@git diff --exit-code docs/hardware/index.md docs/services/index.md docs/infrastructure/racks/ \
	  || { \
	    echo; \
	    echo "✗ The generated docs are out of date with the source files."; \
	    echo "  The diff above is what 'make docs-index' just regenerated."; \
	    echo "  This is what CI checks on push. To fix it:"; \
	    echo "    1. run 'make docs-index'"; \
	    echo "    2. commit the changed files (including the generated ones)"; \
	    echo "  Guide: https://docs.makerfloss.eu/guides/editing-hardware-docs/"; \
	    exit 1; \
	  }

slides:
	./build-slides.sh

test:
	pytest -q
