Add a command line to start site generation
This commit is contained in:
parent
762dc07a16
commit
1e7676f107
|
@ -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)
|
|
@ -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):
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue