From 150608e016fe9c8c2e8a5af645db50acc1d85fe1 Mon Sep 17 00:00:00 2001 From: smdyv <88971341+smdyv@users.noreply.github.com> Date: Thu, 13 Jul 2023 17:06:57 +0200 Subject: [PATCH] Use simple templating for static processing --- process-static | 2 ++ process-templates.py | 26 +++++++++++++++ static/404.html | 31 ++--------------- .../attestation-compatibility-guide.html | 31 ++--------------- static/articles/grapheneos-servers.html | 31 ++--------------- static/articles/index.html | 33 +++---------------- static/articles/server-traffic-shaping.html | 31 ++--------------- ...sitewide-advertising-industry-opt-out.html | 31 ++--------------- static/build.html | 33 +++---------------- static/camera-privacy-policy.html | 31 ++--------------- static/contact.html | 33 +++---------------- static/donate.html | 33 +++---------------- static/faq.html | 33 +++---------------- static/features.html | 33 +++---------------- static/history/copperheados.html | 31 ++--------------- static/history/index.html | 33 +++---------------- static/history/legacy-changelog.html | 31 ++--------------- static/index.html | 33 +++---------------- static/install/cli.html | 31 ++--------------- static/install/index.html | 33 +++---------------- static/install/web.html | 31 ++--------------- static/pdfviewer-privacy-policy.html | 31 ++--------------- static/releases.html | 33 +++---------------- static/source.html | 33 +++---------------- static/usage.html | 33 +++---------------- templates/footer.html | 11 +++++++ templates/header.html | 18 ++++++++++ 27 files changed, 127 insertions(+), 667 deletions(-) create mode 100644 process-templates.py create mode 100644 templates/footer.html create mode 100644 templates/header.html diff --git a/process-static b/process-static index c3176328..7979c854 100755 --- a/process-static +++ b/process-static @@ -31,6 +31,8 @@ cp -a nginx nginx-tmp rm -rf static-tmp cp -a static static-tmp +python3 process-templates.py static-tmp + for file in static-tmp/**/*.@(json|webmanifest); do json_verify < "$file" >/dev/null json_reformat -m < "$file" | sponge "$file" diff --git a/process-templates.py b/process-templates.py new file mode 100644 index 00000000..703acc74 --- /dev/null +++ b/process-templates.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +from jinja2 import FileSystemLoader, Environment +import os +import sys + +ROOT_DIR = sys.argv[1] +TEMPLATE_PATH_LIST = [ROOT_DIR, "templates/"] + +loader = FileSystemLoader(searchpath=TEMPLATE_PATH_LIST) +environment = Environment(loader=loader, autoescape=True) + +template_file_list = [] +for dirpath, dirnames, filenames in os.walk(ROOT_DIR): + for filename in filenames: + if filename.endswith(".html"): + template_file_list.append( + (os.path.join(dirpath, filename)).split(sep=os.path.sep, maxsplit=1)[1] + ) + +for template_file in template_file_list: + template = environment.get_template(template_file) + rendered_template = template.render() + path = os.path.join(ROOT_DIR, template_file) + with open(path, mode="w") as f: + f.write(rendered_template) diff --git a/static/404.html b/static/404.html index 83b3f8c1..b5127d1d 100644 --- a/static/404.html +++ b/static/404.html @@ -28,40 +28,13 @@ -
- -
+ {% include "header.html" %}

Page not found

The requested page does not exist. If you think this is a mistake, please report an issue.

- + {% include "footer.html" %} diff --git a/static/articles/attestation-compatibility-guide.html b/static/articles/attestation-compatibility-guide.html index 16c6c61a..8c80b69e 100644 --- a/static/articles/attestation-compatibility-guide.html +++ b/static/articles/attestation-compatibility-guide.html @@ -30,24 +30,7 @@ -
- -
+ {% include "header.html" %}

Attestation compatibility guide

@@ -129,16 +112,6 @@ app security model but substantially reinforces it, so it cannot be justified with reasoning based on security, anti-fraud, etc.

- + {% include "footer.html" %} diff --git a/static/articles/grapheneos-servers.html b/static/articles/grapheneos-servers.html index 3003c69e..f73de69e 100644 --- a/static/articles/grapheneos-servers.html +++ b/static/articles/grapheneos-servers.html @@ -31,24 +31,7 @@ [[js|/js/redirect.js]] -
- -
+ {% include "header.html" %}

GrapheneOS servers

@@ -714,16 +697,6 @@
- + {% include "footer.html" %} diff --git a/static/articles/index.html b/static/articles/index.html index d4f4b26b..4864d355 100644 --- a/static/articles/index.html +++ b/static/articles/index.html @@ -30,24 +30,9 @@ -
- -
+ {% with current_page="articles" %} + {% include "header.html" %} + {% endwith %}

Articles

@@ -76,16 +61,6 @@
  • Sitewide advertising industry opt-out — Using ads.txt / app-ads.txt to disallow buying or selling ads for a domain.
  • - + {% include "footer.html" %} diff --git a/static/articles/server-traffic-shaping.html b/static/articles/server-traffic-shaping.html index 654d6e8f..f38dac95 100644 --- a/static/articles/server-traffic-shaping.html +++ b/static/articles/server-traffic-shaping.html @@ -30,24 +30,7 @@ -
    - -
    + {% include "header.html" %}

    Server traffic shaping

    @@ -257,16 +240,6 @@ PriorityQueueingPreset=besteffort streams.

    - + {% include "footer.html" %} diff --git a/static/articles/sitewide-advertising-industry-opt-out.html b/static/articles/sitewide-advertising-industry-opt-out.html index c49e6ce8..387e67e0 100644 --- a/static/articles/sitewide-advertising-industry-opt-out.html +++ b/static/articles/sitewide-advertising-industry-opt-out.html @@ -30,24 +30,7 @@ -
    - -
    + {% include "header.html" %}

    Sitewide advertising industry opt-out

    @@ -77,16 +60,6 @@ of ad fraud for the advertising industry, but they do offer value for domain owners to protect their reputation and discourage adware.

    - + {% include "footer.html" %} diff --git a/static/build.html b/static/build.html index be782bc8..84e83bc3 100644 --- a/static/build.html +++ b/static/build.html @@ -31,24 +31,9 @@ [[js|/js/redirect.js]] -
    - -
    + {% with current_page="build" %} + {% include "header.html" %} + {% endwith %}

    Build

    @@ -1487,16 +1472,6 @@ rm android-cts-media-1.5.zip
    - + {% include "footer.html" %} diff --git a/static/camera-privacy-policy.html b/static/camera-privacy-policy.html index 82192034..cec39b40 100644 --- a/static/camera-privacy-policy.html +++ b/static/camera-privacy-policy.html @@ -30,24 +30,7 @@ -
    - -
    + {% include "header.html" %}

    Camera privacy policy

    @@ -78,16 +61,6 @@

    Unlike nearly any other QR/barcode scanning apps, QR/barcode scanning does not open the resulting URL automatically.

    - + {% include "footer.html" %} diff --git a/static/contact.html b/static/contact.html index b2233d3b..e7d573c2 100644 --- a/static/contact.html +++ b/static/contact.html @@ -30,24 +30,9 @@ -
    - -
    + {% with current_page="contact" %} + {% include "header.html" %} + {% endwith %}

    Contact

    @@ -215,17 +200,7 @@
    - + {% include "footer.html" %}