Skip to content

Commit

Permalink
Move favicon mods out of folder and rename folder.
Browse files Browse the repository at this point in the history
Add favicon files to the themes.json file
  • Loading branch information
GilbN committed Sep 15, 2024
1 parent 1787cc9 commit 675e4be
Show file tree
Hide file tree
Showing 86 changed files with 28 additions and 17 deletions.
23 changes: 14 additions & 9 deletions docker-mods/sonarr/root/etc/cont-init.d/98-themepark
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ if [[ -z ${TP_THEME} ]]; then
TP_THEME='organizr'
fi

# Function to download files for a given addon
download_favicon_files() {
local addon=$1
local urls=$(echo "${TP_SCHEME}://${TP_DOMAIN}/themes.json" | jq -r ".addons.sonarr[\"$addon\"].files[]")
for url in $urls; do
wget -P "${APP_ICON_FILEPATH}" "$url"
printf 'Downloaded favicon: %s\n' "$url"
done
}

# Adding stylesheets
if ! grep -q "${TP_DOMAIN}/css/base" "${APP_FILEPATH}"; then
echo '---------------------------'
Expand All @@ -63,16 +73,11 @@ if ! grep -q "${TP_DOMAIN}/css/base" "${APP_FILEPATH}"; then
if [[ -n ${TP_ADDON} ]]; then
for addon in $(echo "$TP_ADDON" | tr "|" " "); do
sheets="${sheets} <link rel='stylesheet' href='${url_base}/css/addons/sonarr/${addon}/${addon}.css'>"

#if TP_ADDON is one that changes the logo, add the corresponding favicon
#find favicon folder name based on addon name
favicon_dir="${url_base}/css/addons/sonarr/favicon/$(echo "${addon}" | sed 's/-logo//g; s/-text//g')"
#if favicon folder exists, copy content to the app favicon folder
if [ -d "$favicon_dir" ]; then
cp "${favicon_dir}/." "${APP_ICON_FILEPATH}"
echo "Added favicon."
# If the addon variable has "favicon" in it, download all the favicon files from the themes.json file.
if [[ ${addon} == *"favicon"* ]]; then
echo 'Downloading favicon files...'
download_favicon_files "$addon"
fi

printf 'Added custom addon: %s\n\n' "${addon}"
done
fi
Expand Down
22 changes: 14 additions & 8 deletions themes.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ def create_addons_json() -> str:
}
)
else:
if len([f for f in files if not f.endswith('.css')]) >= 1:
ADDONS["addons"][app][addon].update({
"files": [f"{scheme}://{DOMAIN}/css/addons/{app}/{addon}/{file}?sha={get_md5_hash(join(getcwd(),'css','addons',app,addon,file))}" for file in files]
}
)
ADDONS["addons"][app].update({
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"
}
Expand All @@ -63,8 +68,9 @@ def create_addons_json() -> str:
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={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"]
}
"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"],
"files": [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"]
},
}
)
return dumps(ADDONS, sort_keys=True)
Expand Down Expand Up @@ -153,22 +159,22 @@ def create_css(theme, theme_type="standard"):
for theme in community_themes:
create_css(theme,theme_type="community")

env_domain = env.get('TP_DOMAIN')
scheme = env.get('TP_SCHEME','https') if env.get('TP_SCHEME') else 'https'

if __name__ == "__main__":
app_folders = [name for name in listdir('./css/base') if isdir(join('./css/base', name))]
themes = [name for name in listdir('./css/theme-options') if isfile(join('./css/theme-options', name))]
docker_mods = [name for name in listdir('./docker-mods')] if isdir('./docker-mods') else []
community_themes = [name for name in listdir('./css/community-theme-options') if isfile(join('./css/community-theme-options', name))]
develop = True if isdir(".git") and subprocess.check_output(["git", "symbolic-ref", "--short", "HEAD"]).decode('ascii').strip() == "develop" else False
if env_domain:
DOMAIN = env_domain
branch: str | None = subprocess.check_output(["git", "symbolic-ref", "--short", "HEAD"]).decode('ascii').strip() if isdir(".git") else None

if env.get('TP_DOMAIN'):
DOMAIN = env.get('TP_DOMAIN')
else:
with open("CNAME", "rt", closefd=True) as cname:
CNAME = cname.readline()
DOMAIN = CNAME if not develop else f"develop.{CNAME}"
DOMAIN = f"{branch}.{CNAME}" if branch else CNAME
apps = loads(create_json(app_folders=app_folders, themes=themes, community_themes=community_themes, docker_mods=docker_mods))
with open("themes.json", "w") as outfile:
dump(apps, outfile, indent=2, sort_keys=True)
create_theme_options()
#create_theme_options()

0 comments on commit 675e4be

Please sign in to comment.