diff --git a/CLAUDE.md b/CLAUDE.md index 0760507..38dab57 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -59,6 +59,8 @@ During development, run directly: `python3 mdcms.py ` | `mdcms build ` | Build `nav.yml` and `search.json` for a registered site. | | `mdcms build --path ` | Build using an explicit path — no registry needed. Intended for CI/CD. | | `mdcms build` | Build using current working directory. Simplest form for GitHub Actions. | +| `mdcms fetch-deps [name]` | Download all external JS/CSS deps to `assets/required/vendors/` and Bunny Fonts to `assets/fonts/`. Patches `index.html` to use local paths — no CDN requests after this. | +| `mdcms fetch-deps --path ` | Same, using an explicit path. | ## PWA config keys diff --git a/mdcms.py b/mdcms.py index 244f56d..af27b05 100644 --- a/mdcms.py +++ b/mdcms.py @@ -812,6 +812,39 @@ def build(name, path_override): click.echo(click.style("Build complete.", fg="green")) +@cli.command("fetch-deps") +@click.argument("name", required=False, default=None) +@click.option("--path", "path_override", default=None, type=click.Path(), + help="Explicit site path (no registry lookup).") +def fetch_deps(name, path_override): + """Download external JS/CSS dependencies and patch index.html for offline use.""" + site_path = resolve_site_path(name, path_override) + if not (site_path / "index.html").exists(): + raise click.ClickException(f"No index.html found at {site_path}") + + click.echo(f"Fetching dependencies for {site_path} ...") + + vendors_dir = site_path / "assets" / "required" / "vendors" + vendors_dir.mkdir(parents=True, exist_ok=True) + + for cdn_url, rel_dest in CDN_DEPS: + dest = site_path / rel_dest + click.echo(f" {rel_dest}") + try: + dest.write_bytes(_http_get(cdn_url)) + except Exception as e: + raise click.ClickException(f"Failed to download {cdn_url}: {e}") + + cfg = read_config(site_path) + local_font_css: list = [] + if cfg.get("theme"): + local_font_css = _fetch_bunny_fonts(site_path, cfg["theme"]) + + _patch_index_html(site_path, local_font_css) + + click.echo(click.style("Done. Site is ready for offline use.", fg="green")) + + # ─── Entry point ───────────────────────────────────────────── def main():