From 45391b84e9d13c1c9039f67b683cbcec6b492714 Mon Sep 17 00:00:00 2001 From: Vinta Chen Date: Wed, 18 Mar 2026 18:28:27 +0800 Subject: [PATCH] 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 --- Makefile | 22 +++++++++++++--------- website/build.py | 6 ++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 8cb7005e..c2aa6809 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,21 @@ -include .env export -site_install: - uv sync --no-dev +install: + uv sync -site_fetch_stats: +fetch_stats: uv run python website/fetch_github_stars.py -site_build: +build: uv run python website/build.py -site_preview: site_build - python -m http.server -d website/output/ 8000 - -site_deploy: site_build - @echo "Deploy via GitHub Actions (push to master)" +preview: build + @echo "Check the website on http://localhost:8000" + uv run watchmedo shell-command \ + --patterns='*.md;*.html;*.css;*.js;*.py' \ + --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 diff --git a/website/build.py b/website/build.py index 129817ae..186026e7 100644 --- a/website/build.py +++ b/website/build.py @@ -220,9 +220,7 @@ def build(repo_root: str) -> None: ) site_dir = website / "output" - if site_dir.exists(): - shutil.rmtree(site_dir) - site_dir.mkdir(parents=True) + site_dir.mkdir(parents=True, exist_ok=True) tpl_index = env.get_template("index.html") (site_dir / "index.html").write_text( @@ -241,7 +239,7 @@ def build(repo_root: str) -> None: static_src = website / "static" static_dst = site_dir / "static" 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") print(f"Built single page with {len(categories)} categories + {len(resources)} resources")