From 2fb91f1b7b98fa7fc2b08949e71a6f46a9ca4e48 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Fri, 28 Aug 2020 19:01:52 +0200 Subject: [PATCH 1/8] implement config dir for subpages --- README.md | 12 ++++++++++-- server.py | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b306fc2..67363fe 100644 --- a/README.md +++ b/README.md @@ -69,8 +69,16 @@ The order is again specified by the alpha-numeric order of the files. You can add new subpages in the *content*-location via a *subpages.json* file denoting an identifier as key and a HTML-template as value, like this: { - "identifiert-1" : "html-template-1.html", - "identifiert-2" : "html-template-2.html" + "identifier-1" : "html-template-1.html", + "identifier-2" : "html-template-2.html" + } + +You can also give identifier complex objects pointing to another config dir which will be parsed by *readJsonDir* and passed to *render_template* as a list of dictionary objects called *"extraConfig"*: + + { + "identifier-1" : { + "template" : "html-template-1.html", + "config-dir" : "config_dir_in_content_dir" } # Contact Page diff --git a/server.py b/server.py index ac8fce2..13b27ac 100755 --- a/server.py +++ b/server.py @@ -46,6 +46,7 @@ WRITE = "w" # subpages IDENTIFIER_PREFIX = "PAGE_" +CONFIG_POSTFIX = "_EXTRA_CONFIG" SUBPAGE_CONFIG_FILE = "subpages.json" SUBPAGE_CONTENT_DIR = "subpages/" @@ -180,7 +181,14 @@ def people(): def content(): identifier = IDENTIFIER_PREFIX + flask.request.args.get("id") if identifier in app.config: - markupText = flask.Markup(flask.render_template(app.config[identifier])) + + # check for extra config # + extraConfigDir = app.config[identifier + CONFIG_POSTFIX] + extraConfig = None + if extraConfigDir: + extraConfig = readJsonDir(os.path.join(app.config[CONTENT_DIR], extraConfigDir)) + + markupText = flask.Markup(flask.render_template(app.config[identifier], extraConfig=extraConfig)) return flask.render_template("default_content.html", conf=app.config, markupText=markupText) else: return (EMPTY_STRING, HTTP_NOT_FOUND) @@ -314,7 +322,13 @@ def init(): # set template paths for identifier in app config # for identifier in subpages.keys(): - app.config[IDENTIFIER_PREFIX + identifier] = subpages[identifier] + if type(subpages[identifier]) == dict: + app.config[IDENTIFIER_PREFIX + identifier] = subpages[identifier]["template"] + configKey = IDENTIFIER_PREFIX + identifier + CONFIG_POSTFIX + app.config[configKey] = subpages[identifier]["config-dir"] + else: + app.config[IDENTIFIER_PREFIX + identifier] = subpages[identifier] + app.config[IDENTIFIER_PREFIX + identifier + CONFIG_POSTFIX] = None # set custom loader to support second template dir # subpageContentDirTmp = os.path.join(app.config["CONTENT_DIR"], SUBPAGE_CONTENT_DIR) From 6d1cd82e88792ef77f64cb88cd1af6a8fce6ff4b Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Fri, 28 Aug 2020 19:03:53 +0200 Subject: [PATCH 2/8] remove obsolete comment --- server.py | 1 - 1 file changed, 1 deletion(-) diff --git a/server.py b/server.py index 13b27ac..a2ebc06 100755 --- a/server.py +++ b/server.py @@ -167,7 +167,6 @@ def impressum(): with open(impressumTextPath) as f: impressumText = flask.Markup(f.read()) - #impressumText = flask.Markup(impressumTextPath) with open(impressumPath) as f: impressumFull = flask.render_template_string(f.read(), conf=app.config, text=impressumText) return flask.render_template("stub.html", content=impressumFull) From 2e0884e060f38ee42f2a8d34e34a48b246c5712f Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Fri, 28 Aug 2020 21:15:13 +0200 Subject: [PATCH 3/8] add wellcome msg config --- example_config.py | 2 ++ templates/index.html | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/example_config.py b/example_config.py index c4d02c7..1918a3e 100644 --- a/example_config.py +++ b/example_config.py @@ -22,6 +22,8 @@ SITE_LOGO_URL = "Site Logo URL" SITE_BASE_URL = "Site Base URL" WALLPAPER_URL = "/picture/example.png" +SITE_WELLCOME_TITLE = "Title on the Wallpaper" +SITE_WELLCOME_SUBTITLE = "Subtitle on the Wallpaper" TEAMSPEAK_SERVER = "teamspeak.com" DISCORD_SERVER = "https://discord.gg/" diff --git a/templates/index.html b/templates/index.html index 2777ade..3dcc687 100644 --- a/templates/index.html +++ b/templates/index.html @@ -19,8 +19,10 @@
-
+
+ {% if "SITE_WELLCOME_TITLE" in conf %}

{{ conf["SITE_WELLCOME_TITLE"] }}

{% endif %} + {% if "SITE_WELLCOME_SUBTITLE" in conf %}

{{ conf["SITE_WELLCOME_SUBTITLE"] }}

{% endif %}
From 85c6328fe83f7fd750ce95963a3840519e1eecb2 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Fri, 28 Aug 2020 21:30:42 +0200 Subject: [PATCH 4/8] CONTENT_DIR must be string --- server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server.py b/server.py index a2ebc06..91e7a5f 100755 --- a/server.py +++ b/server.py @@ -185,7 +185,7 @@ def content(): extraConfigDir = app.config[identifier + CONFIG_POSTFIX] extraConfig = None if extraConfigDir: - extraConfig = readJsonDir(os.path.join(app.config[CONTENT_DIR], extraConfigDir)) + extraConfig = readJsonDir(os.path.join(app.config["CONTENT_DIR"], extraConfigDir)) markupText = flask.Markup(flask.render_template(app.config[identifier], extraConfig=extraConfig)) return flask.render_template("default_content.html", conf=app.config, markupText=markupText) From d232ee37b9136be0fdb0d0603a4bd0b5dbd2a604 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Sat, 29 Aug 2020 13:33:03 +0200 Subject: [PATCH 5/8] allow color config of content --- templates/default_content.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/default_content.html b/templates/default_content.html index b16cfca..f11b328 100644 --- a/templates/default_content.html +++ b/templates/default_content.html @@ -5,7 +5,7 @@ {% include 'head.html' %} - + {% include 'navbar.html' %}
From 522d909ebfc7ea00ac5d377966e3fbbac8fbbda0 Mon Sep 17 00:00:00 2001 From: Yannik Schmidt Date: Sun, 30 Aug 2020 12:41:41 +0200 Subject: [PATCH 6/8] allow additional header content --- example_config.py | 2 ++ templates/head.html | 2 ++ 2 files changed, 4 insertions(+) diff --git a/example_config.py b/example_config.py index 1918a3e..0b18287 100644 --- a/example_config.py +++ b/example_config.py @@ -33,3 +33,5 @@ TWITTER = "https://twitter.com/its_a_sheppy" TWITCH_CHANNEL = "esports_erlangen" TWITCH_PLACEHOLDER_IMG = "placeholder.png" + +ADDITIONAL_HEADER_CONTENT = "" diff --git a/templates/head.html b/templates/head.html index b732b59..d8a868c 100644 --- a/templates/head.html +++ b/templates/head.html @@ -28,6 +28,8 @@ +{{ conf['ADDITIONAL_HEADER_CONTENT'] }} +