jack/jack/commands.py

58 lines
1.4 KiB
Python

import argparse
import logging
import os
import shutil
import tempfile
from jack.models import Article, Section, Site
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))
site = Site(root_directory)
for root, dirs, files in os.walk(root_directory):
base_name = root.replace(root_directory + "/", "")
if "index.md" in files:
with open(os.path.join(root, "index.md")) as md_file:
content = md_file.read()
article = Article(content, base_name)
article.write(root)
site.add(article)
else:
LOGGER.warning(
"{}: No `index.md` or `_index.md` files found in this directory.".format(
root
)
)
site.write()
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)
if __name__ == "__main__":
run("/home/fred/Sources/dev-blog/content/")