build: simplify Makefile targets and add live-reload preview

Rename site_* targets to bare names (install, fetch_stats, build,
preview). Replace the static preview target with a watchmedo-driven
live-reload loop so file changes trigger automatic rebuilds. Make
the output directory creation idempotent (exist_ok=True) and static
copy incremental (dirs_exist_ok=True) so repeated builds don't wipe
output on each run.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vinta Chen
2026-03-18 18:28:27 +08:00
parent 74bba50785
commit 45391b84e9
2 changed files with 15 additions and 13 deletions

View File

@@ -1,17 +1,21 @@
-include .env -include .env
export export
site_install: install:
uv sync --no-dev uv sync
site_fetch_stats: fetch_stats:
uv run python website/fetch_github_stars.py uv run python website/fetch_github_stars.py
site_build: build:
uv run python website/build.py uv run python website/build.py
site_preview: site_build preview: build
python -m http.server -d website/output/ 8000 @echo "Check the website on http://localhost:8000"
uv run watchmedo shell-command \
site_deploy: site_build --patterns='*.md;*.html;*.css;*.js;*.py' \
@echo "Deploy via GitHub Actions (push to master)" --recursive \
--wait --drop \
--command='uv run python website/build.py' \
README.md website/templates website/static website/data & \
python -m http.server -b 127.0.0.1 -d website/output/ 8000

View File

@@ -220,9 +220,7 @@ def build(repo_root: str) -> None:
) )
site_dir = website / "output" site_dir = website / "output"
if site_dir.exists(): site_dir.mkdir(parents=True, exist_ok=True)
shutil.rmtree(site_dir)
site_dir.mkdir(parents=True)
tpl_index = env.get_template("index.html") tpl_index = env.get_template("index.html")
(site_dir / "index.html").write_text( (site_dir / "index.html").write_text(
@@ -241,7 +239,7 @@ def build(repo_root: str) -> None:
static_src = website / "static" static_src = website / "static"
static_dst = site_dir / "static" static_dst = site_dir / "static"
if static_src.exists(): if static_src.exists():
shutil.copytree(static_src, static_dst) shutil.copytree(static_src, static_dst, dirs_exist_ok=True)
(site_dir / "CNAME").write_text("awesome-python.com\n", encoding="utf-8") (site_dir / "CNAME").write_text("awesome-python.com\n", encoding="utf-8")
print(f"Built single page with {len(categories)} categories + {len(resources)} resources") print(f"Built single page with {len(categories)} categories + {len(resources)} resources")