aboutsummaryrefslogtreecommitdiff
path: root/make_site.py
blob: 55b8510f5d66e8bcefc3e296128adfd435dd9259 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python3
# coding: utf-8
#
# Copyright (C) 2017, 2018, 2019 GNUnet e.V.
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.  This file is offered as-is,
# without any warranty.
#
# ----
#
# This script runs the jinja2 templating engine on an input template-file
# using the specified locale for gettext translations, and outputs
# the resulting (HTML) ouptut-file.
#
# Note that the gettext files need to be prepared first. This script
# is thus to be invoked via the Makefile.

import jinja2
import sys
from pathlib import Path, PurePath
from inc.site import gen_site
from inc.fileproc import copy_files

env = jinja2.Environment(loader=jinja2.FileSystemLoader(str(PurePath(__file__).parent)),
                         extensions=["jinja2.ext.i18n"],
                         lstrip_blocks=True,
                         trim_blocks=True,
                         undefined=jinja2.StrictUndefined,
                         autoescape=False)

if len(sys.argv) >= 2 and sys.argv[1] == "-vv":
    DEBUG=1
elif len(sys.argv) >= 2 and sys.argv[1] == "-vvv":
    DEBUG=2
elif len(sys.argv) >= 2 and sys.argv[1] == "-vvvv":
    DEBUG=3
else:
    DEBUG=0

def main():
    # rm_rf("rendered")
    x = gen_site(DEBUG)
    conf = x.load_config("www.yml")
    x.gen_abstract(conf, "newsposts", "abstract", "page", 1000)
    if DEBUG:
        print("generating html from jinja2 templates...")
    x.run("template", conf, env)
    if DEBUG >= 2:
        print(Path.cwd())
        _ = Path("rendered")
        for child in _.iterdir():
            print(child)
    if DEBUG >= 2:
        print(Path.cwd())
    if DEBUG:
        print("generating html from jinja2 news templates...")
    x.run("news", conf, env)
    #for lang in conf["langs_full"]:
    #    copy_files("static", conf, lang, "staticfiles", "rendered")
    if DEBUG:
        print("copying directories...")
    x.copy_trees("static")
    x.copy_trees("dist")
    # print("generating rss...")
    # x.generate_rss()
    # print("generating sitemap...")
    # x.generate_sitemap()

if __name__ == "__main__":
    main()