You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.0 KiB
34 lines
1.0 KiB
2 years ago
|
from jinja2 import Environment, FileSystemLoader, select_autoescape
|
||
|
import os
|
||
|
from pathlib import Path
|
||
|
import shutil
|
||
|
import argparse
|
||
|
|
||
|
parser = argparse.ArgumentParser()
|
||
|
parser.add_argument("destination", help="where to put the rendered site")
|
||
|
args = parser.parse_args()
|
||
|
|
||
|
root_folder = Path(__file__).parent
|
||
|
source = root_folder / "source"
|
||
|
finals = root_folder / "finalized"
|
||
|
if args.destination:
|
||
|
finals = args.destination()
|
||
|
|
||
|
env = Environment(
|
||
|
loader=FileSystemLoader(source),
|
||
|
autoescape=select_autoescape())
|
||
|
|
||
|
# clear out the folder finalized
|
||
|
|
||
|
shutil.copytree(source, finals)
|
||
|
|
||
|
# walk the source directory and make all the corresponding files into finalized
|
||
|
for path_to_file in (source / "articles").glob("*"):
|
||
|
rel_path = path_to_file.relative_to(source)
|
||
|
|
||
|
if ".article.html" in str(path_to_file):
|
||
|
with open(finals / rel_path, "w") as output:
|
||
|
article_template = env.get_template("articles/article.template.html")
|
||
|
output.write(article_template.render(title="Article", target=str(path_to_file.relative_to(source))))
|
||
|
|