Last active
December 4, 2017 12:46
-
-
Save iMilnb/b09f45e112b226b97a36 to your computer and use it in GitHub Desktop.
Minimalistic jinja2-based page generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import markdown | |
import yaml | |
import os | |
from jinja2 import Environment, FileSystemLoader | |
with open(sys.argv[2], 'r') as f: | |
content = yaml.safe_load(f.read()) | |
for k in content: | |
if k.startswith('md_'): | |
content[k] = markdown.markdown(content[k]) | |
tpath = os.path.join(os.getcwd(), 'templates') | |
env = Environment(loader=FileSystemLoader(tpath)) | |
template = env.get_template(sys.argv[1]) | |
print(template.render(content)) | |
# example usage | |
# | |
# $ cat templates/foo.html | |
# <h1>{{ non_markdown_entry }}</h1> | |
# {{ md_items }} | |
# $ cat content/foo.yaml | |
# non_markdown_entry: 'Hey!' | |
# md_items: | | |
# * item 1 | |
# * item 2 | |
# $ python this_script.py foo.html content/foo.yaml >bar.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment