# Run `make help` for the list.
PY ?= python3
VENV := .venv
BIN := $(VENV)/bin
COOLDOWN_DAYS ?= 7

.PHONY: help install preview build lock

help:
	@echo "make install   create .venv from the pinned, hashed requirements.txt"
	@echo "make preview   preview the blog at http://127.0.0.1:8000, on this machine only"
	@echo "make build     strict build into site/, as CI does"
	@echo "make lock      re-pin requirements.in, skipping releases newer than $(COOLDOWN_DAYS) days (needs uv)"

$(BIN)/zensical: requirements.txt
	$(PY) -m venv $(VENV)
	$(BIN)/pip install --quiet --require-hashes --no-deps -r requirements.txt
	@touch $@

install: $(BIN)/zensical

# 127.0.0.1: the preview server is reachable from this machine only, not from the network.
preview: install
	$(BIN)/zensical serve -a 127.0.0.1:8000

build: install
	$(BIN)/zensical build --strict --clean

lock:
	uv pip compile requirements.in --python-version 3.12 --generate-hashes --universal \
		--exclude-newer $$($(PY) -c 'import datetime as d; print(d.date.today() - d.timedelta(days=$(COOLDOWN_DAYS)))') \
		-o requirements.txt
