49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
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)
|