Add new site generator
This commit is contained in:
parent
dd7260eab1
commit
5488273e70
1 changed files with 20 additions and 6 deletions
|
@ -1,12 +1,26 @@
|
|||
from staticjinja import Site
|
||||
import jinja2
|
||||
from datetime import datetime as dt
|
||||
import pathlib
|
||||
|
||||
date_str = dt.now().strftime("%Y-%m-%d")
|
||||
output_path = pathlib.Path("out")
|
||||
input_path = pathlib.Path("templates")
|
||||
|
||||
jenv = jinja2.Environment(
|
||||
loader=jinja2.FileSystemLoader(input_path),
|
||||
autoescape=True, trim_blocks=True, lstrip_blocks=True,
|
||||
keep_trailing_newline=False)
|
||||
|
||||
def render_template(template_name, output_name, **kwargs):
|
||||
template = jenv.get_template(template_name)
|
||||
with open(output_path / output_name, "w") as out_file:
|
||||
out_file.write(template.render(**kwargs))
|
||||
|
||||
if __name__ == "__main__":
|
||||
site = Site.make_site(env_globals={
|
||||
'date': dt.now().strftime("%Y-%m-%d")
|
||||
})
|
||||
# enable automatic reloading
|
||||
site.render(use_reloader=True)
|
||||
render_template("blog.html", "blog.html", date=date_str)
|
||||
render_template("faq.html", "faq.html", date=date_str)
|
||||
render_template("index.html", "index.html", date=date_str)
|
||||
render_template("licenses.html", "licenses.html", date=date_str)
|
||||
render_template("links.html", "links.html", date=date_str)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue