55import argparse
66import markdown
77import json
8- from jinja2 import Environment , FileSystemLoader
98from importlib .metadata import version
9+ from jinja2 import Environment , FileSystemLoader
10+ from pathlib import Path
1011
1112from .builder import Builder
1213from .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"\n Removed all HTML files and feed.json in { output_path } directory." )
0 commit comments