Fix icon handling
All checks were successful
Build and Push Docker Image / prepare (push) Successful in 1m11s

This commit is contained in:
Florian Hoss 2025-01-31 13:09:38 +01:00
parent e20b2843dd
commit 638289b8a4
Signed by: flohoss
GPG key ID: 3F35C7F6E6F66F6B
2 changed files with 14 additions and 10 deletions

View file

@ -145,9 +145,9 @@ func handleLocalIcons(title, ext string) (string, string) {
filePathLight := strings.Replace(title, ext, "-light"+ext, 1) filePathLight := strings.Replace(title, ext, "-light"+ext, 1)
_, err = os.Stat(filePathLight) _, err = os.Stat(filePathLight)
if os.IsNotExist(err) { if os.IsNotExist(err) {
return filePath, "" return "/" + strings.TrimPrefix(filePath, storageFolder), ""
} }
return "/" + filePath, "/" + filePathLight return "/" + strings.TrimPrefix(filePath, storageFolder), "/" + strings.TrimPrefix(filePathLight, storageFolder)
} }
func (bs *BookmarkService) parseBookmarks() { func (bs *BookmarkService) parseBookmarks() {

View file

@ -10,8 +10,8 @@ func placeHolder(app services.Application) string {
return strings.ToUpper(app.Name[:1]) return strings.ToUpper(app.Name[:1])
} }
func displayLight(app services.Application) bool { func noIcon(app services.Application) bool {
return app.Icon != "" return app.Icon == ""
} }
func displayDark(app services.Application) bool { func displayDark(app services.Application) bool {
@ -19,6 +19,10 @@ func displayDark(app services.Application) bool {
} }
var bgTemplate = template.Must(template.New("bgTemplate").Parse( var bgTemplate = template.Must(template.New("bgTemplate").Parse(
`<div class="w-8 h-8 bg-cover bg-center" style="background-image: url('{{ .Path }}')"></div>`,
))
var bgTemplateLight = template.Must(template.New("bgTemplate").Parse(
`<div class="w-8 h-8 dark:hidden bg-cover bg-center" style="background-image: url('{{ .Path }}')"></div>`, `<div class="w-8 h-8 dark:hidden bg-cover bg-center" style="background-image: url('{{ .Path }}')"></div>`,
)) ))
@ -32,17 +36,17 @@ type Icon struct {
templ Application(application services.Application) { templ Application(application services.Application) {
<a href={ templ.URL(application.URL) } class="flex items-center hover-effect"> <a href={ templ.URL(application.URL) } class="flex items-center hover-effect">
if displayLight(application) { if displayDark(application) {
@templ.FromGoHTML(bgTemplate, Icon{Path: application.Icon}) @templ.FromGoHTML(bgTemplateLight, Icon{Path: application.Icon})
} else { @templ.FromGoHTML(bgTemplateDark, Icon{Path: application.IconLight})
} else if noIcon(application) {
<div class="avatar placeholder"> <div class="avatar placeholder">
<div class="bg-primary text-primary-content w-8 rounded-full"> <div class="bg-primary text-primary-content w-8 rounded-full">
<span class="text-xl">{ placeHolder(application) }</span> <span class="text-xl">{ placeHolder(application) }</span>
</div> </div>
</div> </div>
} } else {
if displayDark(application) { @templ.FromGoHTML(bgTemplate, Icon{Path: application.Icon})
@templ.FromGoHTML(bgTemplateDark, Icon{Path: application.IconLight})
} }
<div class="uppercase truncate ml-2">{ application.Name }</div> <div class="uppercase truncate ml-2">{ application.Name }</div>
</a> </a>