From 37f3a2d5a80124d7be897a748e6f1476c62909f0 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Wed, 26 Feb 2020 08:40:25 +0200 Subject: [PATCH] Add support for themes to riot-web --- .gitignore | 1 + CHANGELOG.md | 9 ++++ docs/configuring-playbook-riot-web.md | 11 +++++ roles/matrix-riot-web/defaults/main.yml | 15 ++++++ roles/matrix-riot-web/tasks/main.yml | 6 +++ .../tasks/prepare_riot_web_themes.yml | 48 +++++++++++++++++++ .../matrix-riot-web/templates/config.json.j2 | 3 ++ 7 files changed, 93 insertions(+) create mode 100644 roles/matrix-riot-web/tasks/prepare_riot_web_themes.yml diff --git a/.gitignore b/.gitignore index d373e2580..e3f61b55f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /inventory/* !/inventory/.gitkeep !/inventory/host_vars/.gitkeep +/roles/*/files/scratchpad diff --git a/CHANGELOG.md b/CHANGELOG.md index 53ee3295a..32153869d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# 2020-02-26 + +## Riot-web themes are here + +The playbook now makes it easy to install custom riot-web themes. + +To learn more, take a look at our [riot-web documentation on Themes](docs/configuring-playbook-riot-web.md#themes). + + # 2020-02-24 ## Customize the server name in Riot's login page diff --git a/docs/configuring-playbook-riot-web.md b/docs/configuring-playbook-riot-web.md index af8e21751..119073081 100644 --- a/docs/configuring-playbook-riot-web.md +++ b/docs/configuring-playbook-riot-web.md @@ -27,3 +27,14 @@ Alternatively, **if there is no pre-defined variable** for a riot-web setting yo - or, you can **extend and override the default configuration** ([`config.json.j2`](../roles/matrix-riot-web/templates/config.json.j2)) by making use of the `matrix_riot_web_configuration_extension_json_` variable. You can find information about this in [`roles/matrix-riot-web/defaults/main.yml`](../roles/matrix-riot-web/defaults/main.yml). - or, if extending the configuration is still not powerful enough for your needs, you can **override the configuration completely** using `matrix_riot_web_configuration_default` (or `matrix_riot_web_configuration`). You can find information about this in [`roles/matrix-riot-web/defaults/main.yml`](../roles/matrix-riot-web/defaults/main.yml). + + +## Themes + +To change the look of riot-web, you can define your own themes manually by using the `matrix_riot_web_settingDefaults_custom_themes` setting. + +Or better yet, you can automatically pull it all themes provided by the [aaronraimist/riot-web-themes](https://github.com/aaronraimist/riot-web-themes) project by simply flipping a flag (`matrix_riot_web_themes_enabled: true`). + +If you make your own theme, we encourage you to submit it to the **aaronraimist/riot-web-themes** project, so that the whole community could easily enjoy it. + +Note that for a custom theme to work well, all riot-web/riot-desktop instances that you use must have the same theme installed. diff --git a/roles/matrix-riot-web/defaults/main.yml b/roles/matrix-riot-web/defaults/main.yml index cec6c8eac..f4d1c2331 100644 --- a/roles/matrix-riot-web/defaults/main.yml +++ b/roles/matrix-riot-web/defaults/main.yml @@ -45,6 +45,21 @@ matrix_riot_web_registration_enabled: false # Controls whether Riot shows the presence features matrix_riot_web_enable_presence_by_hs_url: ~ +# Controls whether custom riot-web themes will be installed. +# When enabled, all themes found in the `matrix_riot_web_themes_repository_url` repository +# will be installed and enabled automatically. +matrix_riot_web_themes_enabled: false +matrix_riot_web_themes_repository_url: https://github.com/aaronraimist/riot-web-themes + +# Controls the `settingsDefault.custom_themes` setting of the riot-web configuration. +# You can use this setting to define custom themes. +# +# Also, look at `matrix_riot_web_themes_enabled` for a way to pull in a bunch of custom themes automatically. +# If you define your own themes here and set `matrix_riot_web_themes_enabled: true`, your themes will be preserved as well. +# +# Note that for a custom theme to work well, all riot-web/riot-desktop instances that you use must have the same theme installed. +matrix_riot_web_settingDefaults_custom_themes: [] + # Default riot-web configuration template which covers the generic use case. # You can customize it by controlling the various variables inside it. # diff --git a/roles/matrix-riot-web/tasks/main.yml b/roles/matrix-riot-web/tasks/main.yml index 5792517e3..a5b4aff59 100644 --- a/roles/matrix-riot-web/tasks/main.yml +++ b/roles/matrix-riot-web/tasks/main.yml @@ -8,6 +8,12 @@ - setup-all - setup-riot-web +- import_tasks: "{{ role_path }}/tasks/prepare_riot_web_themes.yml" + when: run_setup|bool + tags: + - setup-all + - setup-riot-web + - import_tasks: "{{ role_path }}/tasks/setup_riot_web.yml" when: run_setup|bool tags: diff --git a/roles/matrix-riot-web/tasks/prepare_riot_web_themes.yml b/roles/matrix-riot-web/tasks/prepare_riot_web_themes.yml new file mode 100644 index 000000000..4171db3a4 --- /dev/null +++ b/roles/matrix-riot-web/tasks/prepare_riot_web_themes.yml @@ -0,0 +1,48 @@ +--- + +# +# Tasks related to setting up riot-web themes +# + +- block: + - name: Ensure riot-web themes repository is pulled + git: + repo: "{{ matrix_riot_web_themes_repository_url }}" + dest: "{{ role_path }}/files/scratchpad/riot-web-themes" + + - name: Find all riot-web theme files + find: + paths: "{{ role_path }}/files/scratchpad/riot-web-themes" + patterns: "*.json" + recurse: true + register: matrix_riot_web_theme_file_list + + - name: Read riot-web theme + slurp: + path: "{{ item.path }}" + register: "matrix_riot_web_theme_file_contents" + with_items: "{{ matrix_riot_web_theme_file_list.files }}" + + - name: Load riot-web theme + set_fact: + matrix_riot_web_settingDefaults_custom_themes: "{{ matrix_riot_web_settingDefaults_custom_themes + [item['content'] | b64decode | from_json] }}" + with_items: "{{ matrix_riot_web_theme_file_contents.results }}" + + run_once: true + delegate_to: 127.0.0.1 + become: false + when: matrix_riot_web_themes_enabled|bool + + +# # +# # Tasks related to getting rid of riot-web themes (if it was previously enabled) +# # + +- name: Ensure riot-web themes repository is removed + file: + path: "{{ role_path }}/files/scratchpad/riot-web-themes" + state: absent + run_once: true + delegate_to: 127.0.0.1 + become: false + when: "not matrix_riot_web_themes_enabled|bool" diff --git a/roles/matrix-riot-web/templates/config.json.j2 b/roles/matrix-riot-web/templates/config.json.j2 index 16a0cf4cf..635c06f51 100644 --- a/roles/matrix-riot-web/templates/config.json.j2 +++ b/roles/matrix-riot-web/templates/config.json.j2 @@ -8,6 +8,9 @@ "base_url": {{ matrix_riot_web_default_is_url|string|to_json }} } }, + "settingDefaults": { + "custom_themes": {{ matrix_riot_web_settingDefaults_custom_themes|to_json }} + }, "disable_custom_urls": {{ matrix_riot_web_disable_custom_urls|to_json }}, "disable_guests": {{ matrix_riot_web_disable_guests|to_json }}, "brand": {{ matrix_riot_web_brand|to_json }},