mirror of
https://github.com/gilbN/theme.park.git
synced 2024-11-05 02:32:37 +01:00
1.13.8 (#496)
* Bad interpreter error associated with the NPM release of 2.9.21 (#486) * Fix Pi-Hole network details table colors (#489) * Grafana 9.5.1 element support (#492) Adding support for only a few elements in latest version of Grafana * Added uptime kuma card css (#494) * Use hashlib instead of git shas * Fix Latest manifest if logic --------- Co-authored-by: goodbyepavlyi 3 <pavlyi.off@gmail.com> Co-authored-by: Samuel Bartík <63553146+sambartik@users.noreply.github.com> Co-authored-by: rg9400 <39887349+rg9400@users.noreply.github.com> Co-authored-by: Henry Whitaker <36062479+henrywhitaker3@users.noreply.github.com>
This commit is contained in:
parent
cefd0f0502
commit
2b32a2a4ee
2
.github/workflows/docker-build.yml
vendored
2
.github/workflows/docker-build.yml
vendored
@ -136,7 +136,7 @@ jobs:
|
||||
docker manifest create ${IMAGE}:${TAG} ${AMD64} ${ARM64} ${ARMV7}
|
||||
docker manifest push ${IMAGE}:${TAG}
|
||||
- name: Latest manifest
|
||||
if: ${{ github.event.release.target_commitish == 'master' }} || ${{ github.event.inputs.branch == 'master' }}
|
||||
if: github.event.release.target_commitish == 'master' || github.event.inputs.branch == 'master'
|
||||
env:
|
||||
DOCKER_CLI_EXPERIMENTAL: enabled
|
||||
run: |
|
||||
|
59
themes.py
59
themes.py
@ -1,13 +1,14 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
from os import defpath, listdir, environ as env, chdir
|
||||
from os import defpath, listdir, environ as env, chdir, getcwd
|
||||
from os.path import isdir, isfile, join, dirname, abspath
|
||||
from json import dump, dumps, loads, load
|
||||
import subprocess
|
||||
from hashlib import md5
|
||||
|
||||
chdir(dirname(abspath(__file__))) # Set working dir
|
||||
|
||||
def get_shas(output):
|
||||
def get_shas(output) -> dict[str, str]:
|
||||
"""Returns a dict of CSS files and SHAs"""
|
||||
output_lines = output.splitlines() if output else []
|
||||
sha_dict = {}
|
||||
@ -19,9 +20,17 @@ def get_shas(output):
|
||||
return(sha_dict)
|
||||
|
||||
|
||||
def create_addons_json():
|
||||
addon_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/addons/*.css"]) if isdir(".git") else []
|
||||
SHAS = get_shas(addon_shas)
|
||||
def get_md5_hash(file_path) -> str:
|
||||
"""Returns the MD5 hash of a file"""
|
||||
md5_hash = md5()
|
||||
with open(file_path, "rb") as f:
|
||||
for byte_block in iter(lambda: f.read(4096), b""):
|
||||
md5_hash.update(byte_block)
|
||||
return md5_hash.hexdigest()
|
||||
|
||||
def create_addons_json() -> str:
|
||||
#addon_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/addons/*.css"]) if isdir(".git") else []
|
||||
#SHAS = get_shas(addon_shas)
|
||||
ADDONS = {"addons": {}}
|
||||
addon_root = './css/addons'
|
||||
addon_folders = [name for name in listdir(
|
||||
@ -38,12 +47,12 @@ def create_addons_json():
|
||||
f"{addon_root}/{app}/{addon}") if isfile(join(f"{addon_root}/{app}/{addon}", file))]
|
||||
if len([f for f in files if f.endswith('.css')]) > 1:
|
||||
ADDONS["addons"][app][addon].update({
|
||||
"css": [f"{scheme}://{DOMAIN}/css/addons/{app}/{addon}/{file}?sha={SHAS.get(file)}" for file in files if file.split(".")[1] == "css"]
|
||||
"css": [f"{scheme}://{DOMAIN}/css/addons/{app}/{addon}/{file}?sha={get_md5_hash(join(getcwd(),'css','addons',app,addon,file))}" for file in files if file.split(".")[1] == "css"]
|
||||
}
|
||||
)
|
||||
else:
|
||||
ADDONS["addons"][app].update({
|
||||
addon: f"{scheme}://{DOMAIN}/css/addons/{app}/{addon}/{file}?sha={SHAS.get(file)}" for file in files if file.split(".")[1] == "css"
|
||||
addon: f"{scheme}://{DOMAIN}/css/addons/{app}/{addon}/{file}?sha={get_md5_hash(join(getcwd(),'css','addons',app,addon,file))}" for file in files if file.split(".")[1] == "css"
|
||||
}
|
||||
)
|
||||
extra_dirs = [dir for dir in listdir(
|
||||
@ -54,7 +63,7 @@ def create_addons_json():
|
||||
f"{addon_root}/{app}/{addon}/{dir}") if isfile(join(f"{addon_root}/{app}/{addon}/{dir}", file))]
|
||||
ADDONS["addons"][app][addon].update({
|
||||
dir: {
|
||||
"css": [f"{scheme}://{DOMAIN}/css/addons/{app}/{addon}/{dir}/{extra_file}?sha={SHAS.get(extra_file)}" for extra_file in extra_dir_files if extra_file.split(".")[1] == "css"]
|
||||
"css": [f"{scheme}://{DOMAIN}/css/addons/{app}/{addon}/{dir}/{extra_file}?sha={get_md5_hash(join(getcwd(),'css','addons',app,addon,dir,extra_file))}" for extra_file in extra_dir_files if extra_file.split(".")[1] == "css"]
|
||||
}
|
||||
}
|
||||
)
|
||||
@ -64,18 +73,18 @@ def create_addons_json():
|
||||
def create_json(app_folders: list = None, themes: list = None, community_themes: list = None ,docker_mods: list = None, no_sub_folders=False) -> str:
|
||||
if no_sub_folders:
|
||||
THEMES_DICT = {}
|
||||
theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/theme-options/*.css"]) if isdir(".git") else []
|
||||
community_theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/community-theme-options/*.css"]) if isdir(".git") else []
|
||||
THEME_SHAS = get_shas(theme_shas)
|
||||
COMMUNITY_THEME_SHAS = get_shas(community_theme_shas)
|
||||
#theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/theme-options/*.css"]) if isdir(".git") else []
|
||||
#community_theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/community-theme-options/*.css"]) if isdir(".git") else []
|
||||
#THEME_SHAS = get_shas(theme_shas)
|
||||
#COMMUNITY_THEME_SHAS = get_shas(community_theme_shas)
|
||||
THEMES = {
|
||||
theme.split(".")[0].capitalize(): {
|
||||
"url": f"{scheme}://{DOMAIN}/css/theme-options/{theme}?sha={THEME_SHAS.get(theme)}"
|
||||
"url": f"{scheme}://{DOMAIN}/css/theme-options/{theme}?sha={get_md5_hash(join(getcwd(),'css','theme-options', theme))}"
|
||||
}for theme in themes if themes
|
||||
}
|
||||
COMMUNITY_THEMES = {
|
||||
theme.split(".")[0].capitalize(): {
|
||||
"url": f"{scheme}://{DOMAIN}/css/community-theme-options/{theme}?sha={COMMUNITY_THEME_SHAS.get(theme)}"
|
||||
"url": f"{scheme}://{DOMAIN}/css/community-theme-options/{theme}?sha={get_md5_hash(join(getcwd(),'css','community-theme-options', theme))}"
|
||||
}for theme in community_themes if community_themes
|
||||
}
|
||||
THEMES_DICT.update(dict(sorted({
|
||||
@ -93,12 +102,12 @@ def create_json(app_folders: list = None, themes: list = None, community_themes:
|
||||
else:
|
||||
ADDONS = loads(create_addons_json())
|
||||
APPS = {}
|
||||
app_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/base/*base.css"]) if isdir(".git") else []
|
||||
SHAS = get_shas(app_shas)
|
||||
#app_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/base/*base.css"]) if isdir(".git") else []
|
||||
#SHAS = get_shas(app_shas)
|
||||
APPS.update(dict(sorted({
|
||||
"applications": {
|
||||
app: {
|
||||
"base_css": f"{scheme}://{DOMAIN}/css/base/{app}/{app}-base.css?sha={SHAS.get(f'{app}-base.css')}",
|
||||
"base_css": f"{scheme}://{DOMAIN}/css/base/{app}/{app}-base.css?sha={get_md5_hash(join('css','base', app, f'{app}-base.css'))}",
|
||||
"addons": ADDONS["addons"][app] if app in ADDONS["addons"] else {}
|
||||
} for app in app_folders if not isfile(f'./css/base/{app}/.deprecated')
|
||||
}
|
||||
@ -106,7 +115,7 @@ def create_json(app_folders: list = None, themes: list = None, community_themes:
|
||||
APPS.update(dict(sorted({
|
||||
"deprecated": {
|
||||
app: {
|
||||
"base_css": f"{scheme}://{DOMAIN}/css/base/{app}/{app}-base.css?sha={SHAS.get(f'{app}-base.css')}",
|
||||
"base_css": f"{scheme}://{DOMAIN}/css/base/{app}/{app}-base.css?sha={get_md5_hash(join('css','base', app, f'{app}-base.css'))}",
|
||||
"addons": ADDONS["addons"][app] if app in ADDONS["addons"] else {}
|
||||
} for app in app_folders if isfile(f'./css/base/{app}/.deprecated')
|
||||
}
|
||||
@ -122,16 +131,16 @@ def create_json(app_folders: list = None, themes: list = None, community_themes:
|
||||
return dumps(APPS)
|
||||
|
||||
def create_theme_options() -> None:
|
||||
app_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/base/*base.css"]) if isdir(".git") else []
|
||||
theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/theme-options/*.css"]) if isdir(".git") else []
|
||||
community_theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/community-theme-options/*.css"]) if isdir(".git") else []
|
||||
THEME_SHAS = get_shas(theme_shas)
|
||||
COMMUNITY_THEME_SHAS = get_shas(community_theme_shas)
|
||||
APP_SHAS = get_shas(app_shas)
|
||||
#app_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/base/*base.css"]) if isdir(".git") else []
|
||||
#theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/theme-options/*.css"]) if isdir(".git") else []
|
||||
#community_theme_shas = subprocess.check_output(["git", "ls-files", "-s", "./css/community-theme-options/*.css"]) if isdir(".git") else []
|
||||
#THEME_SHAS = get_shas(theme_shas)
|
||||
#COMMUNITY_THEME_SHAS = get_shas(community_theme_shas)
|
||||
#APP_SHAS = get_shas(app_shas)
|
||||
def create_css(theme, theme_type="standard"):
|
||||
folder = "./css/base"
|
||||
with open(f"{folder}/{app}/{theme.lower()}.css", "w") as create_app:
|
||||
content = f'@import url("/css/base/{app}/{app}-base.css?sha={APP_SHAS.get(f"{app}-base.css")}");\n@import url("/css/{"theme-options" if theme_type=="standard" else "community-theme-options"}/{theme.lower()}.css?sha={THEME_SHAS.get(f"{theme.lower()}.css") if theme_type=="standard" else COMMUNITY_THEME_SHAS.get(f"{theme.lower()}.css")}");'
|
||||
content = f'@import url("/css/base/{app}/{app}-base.css?sha={get_md5_hash(join(getcwd(),"css","base",app,f"{app}-base.css"))}");\n@import url("/css/{"theme-options" if theme_type=="standard" else "community-theme-options"}/{theme.lower()}.css?sha={get_md5_hash(join(getcwd(),"css","theme-options",f"{theme.lower()}.css")) if theme_type=="standard" else get_md5_hash(join(getcwd(),"css","community-theme-options",f"{theme.lower()}.css"))}");'
|
||||
create_app.write(content)
|
||||
with open("themes.json") as themes:
|
||||
data = load(themes)
|
||||
|
Loading…
Reference in New Issue
Block a user