Skip to content

Commit 468a200

Browse files
committed
Add a clean command
1 parent d54550f commit 468a200

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/genja/main.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import argparse
66
import markdown
77
import json
8-
from jinja2 import Environment, FileSystemLoader
98
from importlib.metadata import version
9+
from jinja2 import Environment, FileSystemLoader
10+
from pathlib import Path
1011

1112
from .builder import Builder
1213
from .server import run_server
@@ -18,8 +19,8 @@ def main():
1819
"""
1920

2021
# Command line arguments
21-
parser = argparse.ArgumentParser(description="Static site generator for GitHub Pages.")
22-
parser.add_argument("command", choices=["build", "serve"], help="build or serve website")
22+
parser = argparse.ArgumentParser(description="Genja static site generator for GitHub Pages")
23+
parser.add_argument("command", choices=["build", "serve", "clean"], help="genja commands")
2324
parser.add_argument("-v", "--version", action="version", version=version("genja"))
2425
args = parser.parse_args()
2526

@@ -47,6 +48,17 @@ def main():
4748
builder.build_index(index_template, pages)
4849
builder.build_feed(feed_template, feeds)
4950

50-
# Run a local server and open browser if run command is `serve`
51+
# Run a local server and open web browser
5152
if args.command == "serve":
5253
run_server(config)
54+
55+
# Clean up (remove) all HTML files and the feed.json file in output directory
56+
if args.command == "clean":
57+
output_path = Path(config["output_dir"])
58+
59+
Path(output_path / "feed.json").unlink()
60+
61+
for html_file in output_path.glob("**/*.html"):
62+
html_file.unlink()
63+
64+
print(f"\nRemoved all HTML files and feed.json in {output_path} directory.")

0 commit comments

Comments
 (0)