|
5 | 5 | import click |
6 | 6 | from dateutil import parser as dateparser |
7 | 7 | from dateutil.parser import ParserError |
8 | | -from render_engine import Collection |
| 8 | +from render_engine import Collection, Page |
| 9 | +from render_engine.site_map import SiteMap |
9 | 10 | from rich.console import Console |
10 | 11 |
|
11 | 12 | from render_engine_cli.event import ServerEventHandler |
@@ -396,5 +397,42 @@ def templates(module_site: str, theme_name: str, filter_value: str): |
396 | 397 | ) |
397 | 398 |
|
398 | 399 |
|
| 400 | +@app.command |
| 401 | +@click.option( |
| 402 | + "--module-site", |
| 403 | + type=click.STRING, |
| 404 | + # help="The module (python file) and site (the Site object) for your site in the format module:site", |
| 405 | + callback=validate_module_site, |
| 406 | +) |
| 407 | +@click.option( |
| 408 | + "-x", |
| 409 | + "--xml", |
| 410 | + help="Generate site map as XML", |
| 411 | + type=click.BOOL, |
| 412 | + is_flag=True, |
| 413 | + default=False, |
| 414 | +) |
| 415 | +@click.option("-o", "--output", help="File to output site map to.", type=click.Path(exists=False)) |
| 416 | +def sitemap(xml: bool, output: click.File, module_site: str): |
| 417 | + """ |
| 418 | + CLI for generating the site map in HTML (default) or XML to either the console (default) or a file. |
| 419 | + """ |
| 420 | + module, site_name = split_module_site(module_site) |
| 421 | + site = get_site(module, site_name) |
| 422 | + site_map = SiteMap(site.route_list, site.site_vars.get("SITE_URL", "")) |
| 423 | + if xml: |
| 424 | + site.theme_manager.engine.globals.update(site.site_vars) |
| 425 | + site_map_page = Page() |
| 426 | + site_map_page.template = "sitemap.xml" |
| 427 | + site_map_page.site_map = site_map |
| 428 | + content = site_map_page._render_content(site.theme_manager.engine) |
| 429 | + else: |
| 430 | + content = site_map.html |
| 431 | + if output: |
| 432 | + Path(output).write_text(content) |
| 433 | + else: |
| 434 | + print(content) |
| 435 | + |
| 436 | + |
399 | 437 | if __name__ == "__main__": |
400 | 438 | app() |
0 commit comments