aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas HABEGGER <andreas.habegger@bfh.ch>2023-11-20 11:24:48 +0100
committerAndreas HABEGGER <andreas.habegger@bfh.ch>2023-11-20 11:24:48 +0100
commit72771f14dfe85a6444cb48f6cdfce1abc5473f51 (patch)
tree63721cec2d14e5f0afeec523b6d27e482ee55593
parent218f02cfc0453a0d4cc067ba9256123a675040ce (diff)
parent1d496cd5b009d8d420176b00831c4bbd717a4a09 (diff)
downloadwww_shared-72771f14dfe85a6444cb48f6cdfce1abc5473f51.tar.gz
www_shared-72771f14dfe85a6444cb48f6cdfce1abc5473f51.zip
MC: YAML multifile reader for translations and configuration properties
-rw-r--r--README10
-rwxr-xr-xlist-languages16
-rw-r--r--sitegen/site.py13
3 files changed, 34 insertions, 5 deletions
diff --git a/README b/README
index d9650ce..04b2e19 100644
--- a/README
+++ b/README
@@ -18,6 +18,16 @@ of one website, ie this affects both websites and if in doubt
18should be tested against both as soon as both websites have 18should be tested against both as soon as both websites have
19been switched to this code. 19been switched to this code.
20 20
21Note
22----
23YAML files are used for both translations and the Site Builder as
24content properties. The collection hierarchy is as follows
25 * First, the file "properties.yml" in the top directory is read.
26 * Second, all YAML files are collected in a directory called "properties.d".
27 * Third, the collected files are fed into the build system as a dictionary.
28Note that the name is controlled by a variable PROPERTIES_YML. The name of
29the file is linked to the name of the directory.
30
21Dependencies 31Dependencies
22------------ 32------------
23 33
diff --git a/list-languages b/list-languages
index 9df48ac..c1379d2 100755
--- a/list-languages
+++ b/list-languages
@@ -1,8 +1,18 @@
1#!/usr/bin/env python3 1#!/usr/bin/env python3
2 2
3from ruamel.yaml import YAML
4from pathlib import Path 3from pathlib import Path
4from ruamel.yaml import YAML
5
6PROPERTIES_YML = "properties.yml"
7
8# NOTE : read-in properties.yml and afterwards all *.yml in properties.d
9properties = {}
5yaml = YAML(typ="safe") 10yaml = YAML(typ="safe")
6config = yaml.load(Path("www.yml")) 11yaml.preserve_quotes = True
7langs = config["langs_full"] 12properties.update(yaml.load(Path(PROPERTIES_YML)))
13properties_dir = PROPERTIES_YML.removesuffix('.yml') + '.d'
14for filepath in Path(properties_dir).glob('*.yml'):
15 properties.update(yaml.load(filepath))
16
17langs = properties["langs_full"]
8print(" ".join(langs)) 18print(" ".join(langs))
diff --git a/sitegen/site.py b/sitegen/site.py
index e2b20c0..6139d1c 100644
--- a/sitegen/site.py
+++ b/sitegen/site.py
@@ -34,6 +34,8 @@ import sitegen.i18nfix as i18nfix
34from sitegen.timeutil import time_rfc822, time_now, conv_date_rfc822 34from sitegen.timeutil import time_rfc822, time_now, conv_date_rfc822
35 35
36 36
37PROPERTIES_YML = "properties.yml"
38
37def html2text(html_str): 39def html2text(html_str):
38 class extractText(html.parser.HTMLParser): 40 class extractText(html.parser.HTMLParser):
39 def __init__(self): 41 def __init__(self):
@@ -195,9 +197,16 @@ class SiteGenerator:
195 env.filters["extract_body"] = extract_body 197 env.filters["extract_body"] = extract_body
196 env.newstyle_gettext = True 198 env.newstyle_gettext = True
197 self.env = env 199 self.env = env
200 # NOTE : read-in properties.yml and afterwards all *.yml in properties.d
201 properties = {}
198 yaml = YAML(typ="safe") 202 yaml = YAML(typ="safe")
199 site_configfile = self.root / "www.yml" 203 yaml.preserve_quotes = True
200 self.config = yaml.load(site_configfile) 204 properties.update(yaml.load(self.root/PROPERTIES_YML))
205 properties_dir = PROPERTIES_YML.removesuffix('.yml') + '.d'
206 for filepath in Path(self.root/properties_dir).glob('*.yml'):
207 properties.update(yaml.load(filepath))
208 self.config = properties
209
201 self.baseurl = os.environ.get("BASEURL") 210 self.baseurl = os.environ.get("BASEURL")
202 if not self.baseurl: 211 if not self.baseurl:
203 self.baseurl = self.config["siteconf"].get("baseurl") 212 self.baseurl = self.config["siteconf"].get("baseurl")