diff --git a/jack/commands.py b/jack/commands.py new file mode 100644 index 0000000..241b76f --- /dev/null +++ b/jack/commands.py @@ -0,0 +1,48 @@ +import argparse +import logging +import os +import shutil +import tempfile + +from .models import Article + + +LOGGER = logging.getLogger(__name__) + + +def generate_site(input_path): + temp_directory = tempfile.mkdtemp() + root_directory = os.path.join(temp_directory, "jack") + shutil.copytree(input_path, root_directory) + + LOGGER.info("Processing static content to {}".format(root_directory)) + + for root, dirs, files in os.walk(root_directory): + if "index.md" in files: + # print(root.replace(root_directory, "")) + + with open(os.path.join(root, "index.md")) as md_file: + content = md_file.read() + + article = Article(content, None, None) + article.write(os.path.join(root, "index.html")) + else: + LOGGER.warning( + "{}: No `index.md` file found in this directory. You might want to add one.".format( + root + ) + ) + + +def run(args=None): + """Copy the content located at `input_path` + + Convert this content to statically managed. + """ + parser = argparse.ArgumentParser(description="Static Html Generation") + parser.add_argument( + "source", type=str, help="The path to the content that will be used as source" + ) + + args = parser.parse_args() + generate_site(args.source) diff --git a/jack/models.py b/jack/models.py index bcc79c0..0963e86 100644 --- a/jack/models.py +++ b/jack/models.py @@ -47,6 +47,10 @@ class Article: def to_prose(self): return self.html + def write(self, output_path): + with open(output_path, "w") as output_file: + output_file.write(self.to_prose()) + class Section: def __init__(self, key, path=None): diff --git a/pyproject.toml b/pyproject.toml index c3179c5..971c665 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,9 @@ pytest = "^7.2.0" black = "^22.12.0" pytest-cov = "^4.0.0" +[tool.poetry.scripts] +jack = "jack.commands:run" + [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api"