feat: Add support for color themes in theme creation

This commit modifies the theme creation process to include support for color themes. It adds a new checkbox field in the theme creation form to indicate whether the theme is a color theme. If the checkbox is selected, the CSS styles for the theme should be provided as a JSON object with the color values. Additionally, the `create-theme.yml` workflow file is updated to include the `THEME_IS_COLOR_THEME` environment variable when building the theme. The `rebuild-themes.py` script is also updated to generate a `chrome.css` file for color themes based on the provided color values in a `colors.json` file.

Fixes #69
This commit is contained in:
Mauro Balades 2024-08-21 16:31:16 +02:00
parent 6aa221874d
commit 01040237ed
4 changed files with 57 additions and 4 deletions

View file

@ -5,6 +5,32 @@ import json
THEMES_FOLDER = './themes'
THEMES_DATA_FILE = './themes.json'
def get_color_css_variable(color):
if color == "primaryColor":
return '--zen-colors-primary'
if color == "secondaryColor":
return '--zen-colors-secondary'
if color == "tertiaryColor":
return '--zen-colors-tertiary'
if color == "colorsBorder":
return '--zen-colors-border'
print(f"Unknown color: {color}")
exit(1)
def write_colors(colors_file, output_file):
with open(colors_file, 'r') as f:
colors = json.load(f)
with open(output_file, 'w') as f:
f.write('/* This is a color theme. */\n')
f.write(':root {\n')
for color in colors:
if color == "isDarkMode":
continue
f.write(f' {get_color_css_variable(color)}: {colors[color]};\n')
if colors["isDarkMode"]:
f.write(' color-scheme: dark !important;\n')
f.write('}\n')
def main():
with open(THEMES_DATA_FILE, 'w') as f:
json.dump({}, f, indent=4)
@ -22,6 +48,10 @@ def main():
themes_data[theme] = theme_data
with open(THEMES_DATA_FILE, 'w') as f:
json.dump(themes_data, f, indent=4)
theme_colors_file = os.path.join(theme_folder, 'colors.json')
if os.path.exists(theme_colors_file):
theme_colors_output = os.path.join(theme_folder, 'chrome.css')
write_colors(theme_colors_file, theme_colors_output)
print(f"Rebuilt theme: {theme}")
print("Rebuilt all themes!")