forgejo/tasks/custom_themes.yml

64 lines
2.1 KiB
YAML

---
- name: '[THEME] - Create css dir'
file:
path: '{{ forgejo_theme_dir }}/public/assets/css'
state: directory
owner: "{{ forgejo_user }}"
group: "{{ forgejo_group }}"
tags: theme
# First, remove the css files from public folder, then theme repos
- name: "[THEME] - Remove css files from the css folder"
shell:
cmd: find "{{ forgejo_theme_dir }}/{{ item.name }}" -type f -name "*.css" -printf "%f\n" | xargs -I{} rm public/assets/css/{}
chdir: "{{ forgejo_theme_dir }}"
loop: "{{ forgejo_custom_themes }}"
when: item.enable == 'false'
tags: theme
- name: "[THEME] - Remove theme repo"
file:
path: "{{ forgejo_theme_dir }}/{{ item.name }}"
state: absent
owner: "{{ forgejo_user }}"
group: "{{ forgejo_group }}"
loop: "{{ forgejo_custom_themes }}"
when: item.enable == 'false'
tags: theme
# Second, get theme repos and deploy css files in public folder
- name: "[THEME] - Get repo"
git:
repo: "{{ item.repo }}"
dest: "{{ forgejo_theme_dir }}/{{ item.name }}"
force: yes
loop: "{{ forgejo_custom_themes }}"
when: item.enable == 'true'
become: true
become_user: "{{ forgejo_user }}"
tags: theme
- name: "[THEME] - Find css files from different repos and copy them in the public folder"
shell:
cmd: find "{{ forgejo_theme_dir }}" -type f -name "*.css" -not -path "{{ forgejo_theme_dir }}/public/*" | xargs cp -t "{{ forgejo_theme_dir }}/public/assets/css"
chdir: "{{ forgejo_theme_dir }}"
become: true
become_user: "{{ forgejo_user }}"
tags: theme
# Lastly, update app.ini by adding the theme's name list.
- name: "[THEME] - Get and prepare a list for app.ini of css files in public folder, register it"
shell:
cmd: ls "{{ forgejo_theme_dir }}/public/assets/css" | sed -e 's/theme-//g' | sed -e 's/.css//g' | paste -s -d,
chdir: "{{ forgejo_theme_dir }}"
register: theme_name
tags: theme
- name: "[THEME] - Add list of themes in app.ini"
lineinfile:
path: "{{ forgejo_confdir }}"
regexp: '^THEMES'
line: "{{ forgejo_ui_config[0] }},{{ theme_name.stdout }}"
notify: Restart forgejo
tags: theme