diff --git a/README.md b/README.md index 9148353..5e63e72 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,23 @@ Source code and build scripts for [chaostreff.ch](https://chaostreff.ch/) +## Production Deployment + +```shell-session +$ python3 -m virtualenv venv +$ . venv/bin/activate +(venv) $ pip install -r requirements.txt +(venv) $ ./build.py +``` + +Then deploy the contents of `out/` to the webroot. + +To make the site really usable, the following features should be configured: +* A proxying service for SpaceAPI endpoints (since some of them don't set CORS headers) +* Automatic redirection to the correct language subpage based on the `Accept-Language` header + +An example configuration for Apache httpd can be found in the `httpd.conf` file. + ## Local Development Setup ```shell-session @@ -15,17 +32,6 @@ $ . venv/bin/activate run.py includes a SpaceAPI proxy to work around missing CORS headers. -## Production Deployment - -```shell-session -$ python3 -m virtualenv venv -$ . venv/bin/activate -(venv) $ pip install -r requirements.txt -(venv) $ ./build.py -``` - -Then deploy the contents of `out/` to the webroot. - ## License With exception of the sources listed below, this project is licensed under the [MIT License](LICENSE). diff --git a/build.py b/build.py index b6b4ce8..807bd92 100755 --- a/build.py +++ b/build.py @@ -12,11 +12,19 @@ with open('config.yml', 'r') as f: os.makedirs('out', exist_ok = True) shutil.copytree('static', 'out/static', dirs_exist_ok=True) +env = jinja2.Environment(loader=jinja2.FileSystemLoader('static-src')) +env.globals.update(config['jinja_environment']) +env.globals['languages'] = config['languages'] +for fname in os.listdir('static-src'): + tmpl = env.get_template(fname) + with open(os.path.join('out', fname), 'w') as of: + of.write(tmpl.render()) + for lang in config['languages'].keys(): with open(f'l10n/{lang}.yml', 'r') as l: l10n = yaml.safe_load(l) - env = jinja2.Environment(loader=jinja2.FileSystemLoader("src")) + env = jinja2.Environment(loader=jinja2.FileSystemLoader('src')) env.globals.update(config['jinja_environment']) env.globals.update(l10n) env.globals['languages'] = config['languages'] diff --git a/httpd.conf b/httpd.conf new file mode 100644 index 0000000..f96112a --- /dev/null +++ b/httpd.conf @@ -0,0 +1,13 @@ + +# Redirect to language-specific index based on Accept-Language header +AddHandler type-map .var +DirectoryIndex index.var index.html +Redirect /index.de.html /de/ +Redirect /index.fr.html /fr/ +Redirect /index.it.html /it/ +Redirect /index.en.html /en/ + +# SpaceAPI proxy service workaround for missing CORS headers +SSLProxyEngine on +RewriteEngine on +RewriteRule /spaceapi/([^/]+)/([^/]+)(/.*+)$ $1://$2/$3 [P,L] \ No newline at end of file diff --git a/static-src/index.var b/static-src/index.var new file mode 100644 index 0000000..2a3b26c --- /dev/null +++ b/static-src/index.var @@ -0,0 +1,7 @@ +URI: index; vary="language" + +{% for language in languages %} +URI: index.{{ language }}.html +Content-Type: text/html +Content-Language: {{ language }} +{% endfor %} diff --git a/src/sitemap.xml b/static-src/sitemap.xml similarity index 100% rename from src/sitemap.xml rename to static-src/sitemap.xml