Dynamize manifest.json with configurable options

This commit is contained in:
David Pearson
2025-04-20 10:00:17 -04:00
parent 1cf4f520f8
commit 333d40ed4f
5 changed files with 64 additions and 14 deletions

View File

@@ -55,6 +55,9 @@ type config struct {
LogoText string `yaml:"logo-text"`
LogoURL string `yaml:"logo-url"`
FaviconURL string `yaml:"favicon-url"`
AppName string `yaml:"app-name"`
AppIconURL string `yaml:"app-icon-url"`
AppBgColor string `yaml:"app-bg-color"`
} `yaml:"branding"`
Pages []page `yaml:"pages"`

View File

@@ -96,6 +96,18 @@ func newApplication(config *config) (*application, error) {
config.Branding.FaviconURL = app.transformUserDefinedAssetPath(config.Branding.FaviconURL)
}
if config.Branding.AppName == "" {
config.Branding.AppName = "Glance"
}
if config.Branding.AppIconURL == "" {
config.Branding.AppIconURL = app.AssetPath("app-icon.png")
}
if config.Branding.AppBgColor == "" {
config.Branding.AppBgColor = "#151519"
}
config.Branding.LogoURL = app.transformUserDefinedAssetPath(config.Branding.LogoURL)
return app, nil
@@ -257,6 +269,26 @@ func (a *application) server() (func() error, func() error) {
w.Write(bundledCSSContents)
})
mux.HandleFunc(fmt.Sprintf("GET /static/%s/manifest.json", staticFSHash), func(w http.ResponseWriter, r *http.Request) {
w.Header().Add("Cache-Control", cssBundleCacheControlValue)
w.Header().Add("Content-Type", "application/json")
template, err := template.New("manifest.json").
Funcs(globalTemplateFunctions).
ParseFS(templateFS, "manifest.json")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("Error parsing manifest.json template: %v", err)))
return
}
if err := template.Execute(w, pageTemplateData{App: a}); err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(fmt.Sprintf("Error executing manifest.json template: %v", err)))
return
}
})
var absAssetsPath string
if a.Config.Server.AssetsPath != "" {
absAssetsPath, _ = filepath.Abs(a.Config.Server.AssetsPath)

View File

@@ -1,14 +0,0 @@
{
"name": "Glance",
"display": "standalone",
"background_color": "#151519",
"scope": "/",
"start_url": "/",
"icons": [
{
"src": "app-icon.png",
"type": "image/png",
"sizes": "512x512"
}
]
}

View File

@@ -0,0 +1,14 @@
{
"name": "{{ .App.Config.Branding.AppName }}",
"display": "standalone",
"background_color": "{{ .App.Config.Branding.AppBgColor }}",
"scope": "/",
"start_url": "/",
"icons": [
{
"src": "{{ .App.Config.Branding.AppIconURL }}",
"type": "image/png",
"sizes": "512x512"
}
]
}