diff --git a/deadsands/pyproject.toml b/deadsands/pyproject.toml index fe9b45d..79e90b0 100644 --- a/deadsands/pyproject.toml +++ b/deadsands/pyproject.toml @@ -29,7 +29,7 @@ pelican-yaml-metadata = { git = "https://github.com/pR0Ps/pelican-yaml-metadata. dnd-npcs = { git = "https://github.com/evilchili/dnd-npcs", branch = 'main' } elethis-cipher= { git = "https://github.com/evilchili/elethis-cipher", branch = 'main' } #dnd-rolltable = { git = "https://github.com/evilchili/dnd-rolltable", branch = 'main' } -dnd-rolltable = { file = "../../dnd-rolltable/dist/dnd_rolltable-1.1.5-py3-none-any.whl" } +dnd-rolltable = { file = "../../dnd-rolltable/dist/dnd_rolltable-1.1.9-py3-none-any.whl" } [tool.poetry.scripts] site = "site_tools.cli:app" diff --git a/deadsands/site_tools/cli.py b/deadsands/site_tools/cli.py index d017780..65da8d7 100644 --- a/deadsands/site_tools/cli.py +++ b/deadsands/site_tools/cli.py @@ -17,6 +17,7 @@ from pelican import main as pelican_main from time import sleep from site_tools.content_manager import create +from rolltable.tables import RollTable CONFIG = { @@ -103,7 +104,7 @@ def watch() -> None: print(f"Watching {import_path}. CTRL+C to exit.") while True: watcher.examine() - sleep(1) + sleep(5) @app.command() @@ -158,6 +159,44 @@ def publish() -> None: )) +@app.command() +def restock(source: str = typer.Argument( + ..., + help='The source file for the store.' + ), + frequency: str = typer.Option( + 'default', + help='use the specified frequency from the source file'), + die: int = typer.Option( + 20, + help='The size of the die for which to create a table'), + template_dir: str = typer.Argument( + CONFIG['templates_path'], + help="Override the default location for markdown templates.", + ) +) -> None: + + rt = RollTable( + [Path(source).read_text()], + frequency=frequency, + die=die, + hide_rolls=True + ) + store = rt.datasources[0].metadata['store'] + + click.edit(filename=create( + content_type='post', + title=store['title'], + template_dir=template_dir, + category='stores', + template='store', + extra_context=dict( + inventory=rt.as_markdown, + **store + ) + )) + + @app.command() def new( content_type: ContentType = typer.Argument( diff --git a/deadsands/site_tools/content_manager.py b/deadsands/site_tools/content_manager.py index 2866326..7a4eb6b 100644 --- a/deadsands/site_tools/content_manager.py +++ b/deadsands/site_tools/content_manager.py @@ -7,7 +7,8 @@ from site_tools import SETTINGS def create(content_type: str, title: str, template_dir: str, - category: str = None, template: str = None) -> str: + category: str = None, source: str = None, template: str = None, + extra_context: dict = {}) -> str: """ Return the path to a new source file. """ @@ -41,6 +42,7 @@ def create(content_type: str, title: str, template_dir: str, 'title': title, 'tags': content_type, 'date': datetime.datetime.now(), - 'filename': str(relpath / target_filename) + 'filename': str(relpath / target_filename), + **extra_context }) return dest