summaryrefslogtreecommitdiff
path: root/make_site.py
diff options
context:
space:
mode:
Diffstat (limited to 'make_site.py')
-rwxr-xr-xmake_site.py108
1 files changed, 40 insertions, 68 deletions
diff --git a/make_site.py b/make_site.py
index d7be569f..4c2605ac 100755
--- a/make_site.py
+++ b/make_site.py
@@ -9,79 +9,51 @@
#
# Note that the gettext files need to be prepared first. This script
# is thus to be invoked via the Makefile.
-import os
-import os.path
-import sys
-import re
-import gettext
import jinja2
-import glob
-import codecs
-import os
-sys.path.append(os.getcwd())
-import i18nfix
+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(os.path.dirname(__file__)),
+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)
-langs_full = {"en": "English",
- "fr": "Français",
- "it": "Italiano",
- "es": "Español",
- "de": "Deutsch",
- "ru": "Ру́сский язы́к",
- "pt": "Português"}
-
-for in_file in glob.glob("template/*.j2"):
- name, ext = re.match(r"(.*)\.([^.]+)$", in_file.rstrip(".j2")).groups()
- tmpl = env.get_template(in_file)
-
- def self_localized(other_locale):
- """
- Return URL for the current page in another locale.
- """
- return "../" + other_locale + "/" + in_file.replace('template/', '').rstrip(".j2")
-
- def url_localized(filename):
- return "../" + locale + "/" + filename
-
- def svg_localized(filename):
- lf = filename + "." + locale + ".svg"
- if "en" == locale or not os.path.isfile (lf):
- return "../" + filename + ".svg"
- else:
- return "../" + lf
-
- def url(x):
- # TODO: look at the app root environment variable
- # TODO: check if file exists
- return "../" + x
-
- for l in glob.glob("locale/*/"):
- locale = os.path.basename(l[:-1])
-
- tr = gettext.translation("messages",
- localedir="locale",
- languages=[locale])
-
- tr.gettext = i18nfix.wrap_gettext(tr.gettext)
-
- env.install_gettext_translations(tr, newstyle=True)
-
- content = tmpl.render(
- docshost="docs.taler.net",
- lang=locale,
- lang_full=langs_full[locale],
- url=url,
- self_localized=self_localized,
- url_localized=url_localized,
- svg_localized=svg_localized,
- filename=name + "." + ext)
- out_name = "./rendered/" + locale + "/" + in_file.replace('template/', '').rstrip(".j2")
- os.makedirs("./rendered/" + locale, exist_ok=True)
- with codecs.open(out_name, "w", encoding='utf-8') as f:
- f.write(content)
+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():
+ x = gen_site(DEBUG)
+ conf = x.load_config("www.yml")
+ x.gen_abstract(conf, "newsposts", "abstract", "page", 1000)
+ x.gen_newspost_content(conf, "newsposts", "content", "page", "en")
+ x.gen_rss("inc", conf, env)
+ 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)
+ if DEBUG:
+ print("copying directories...")
+ x.copy_trees("static")
+ x.copy_trees("dist")
+
+if __name__ == "__main__":
+ main()