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

@ -268,6 +268,9 @@ branding:
<p>Powered by <a href="https://github.com/glanceapp/glance">Glance</a></p> <p>Powered by <a href="https://github.com/glanceapp/glance">Glance</a></p>
logo-url: /assets/logo.png logo-url: /assets/logo.png
favicon-url: /assets/logo.png favicon-url: /assets/logo.png
app-name: "My Dashboard"
app-icon-url: "/assets/app-icon.png"
app-bg-color: "#151519"
``` ```
### Properties ### Properties
@ -279,6 +282,9 @@ branding:
| logo-text | string | no | G | | logo-text | string | no | G |
| logo-url | string | no | | | logo-url | string | no | |
| favicon-url | string | no | | | favicon-url | string | no | |
| app-name | string | no | Glance |
| app-icon-url | string | no | |
| app-bg-color | string | no | #151519 |
#### `hide-footer` #### `hide-footer`
Hides the footer when set to `true`. Hides the footer when set to `true`.
@ -295,6 +301,15 @@ Specify a URL to a custom image to use instead of the "G" found in the navigatio
#### `favicon-url` #### `favicon-url`
Specify a URL to a custom image to use for the favicon. Specify a URL to a custom image to use for the favicon.
#### `app-name`
Specify the name of the web app shown in browser tab and PWA. Defaults to "Glance".
#### `app-icon-url`
Specify URL for PWA and browser tab icon (512x512 PNG). Defaults to Glance icon if not set.
#### `app-bg-color`
Specify background color for PWA. Must be a valid CSS color. Defaults to "#151519".
## Theme ## Theme
Theming is done through a top level `theme` property. Values for the colors are in [HSL](https://giggster.com/guide/basics/hue-saturation-lightness/) (hue, saturation, lightness) format. You can use a color picker [like this one](https://hslpicker.com/) to convert colors from other formats to HSL. The values are separated by a space and `%` is not required for any of the numbers. Theming is done through a top level `theme` property. Values for the colors are in [HSL](https://giggster.com/guide/basics/hue-saturation-lightness/) (hue, saturation, lightness) format. You can use a color picker [like this one](https://hslpicker.com/) to convert colors from other formats to HSL. The values are separated by a space and `%` is not required for any of the numbers.

View File

@ -55,6 +55,9 @@ type config struct {
LogoText string `yaml:"logo-text"` LogoText string `yaml:"logo-text"`
LogoURL string `yaml:"logo-url"` LogoURL string `yaml:"logo-url"`
FaviconURL string `yaml:"favicon-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"` } `yaml:"branding"`
Pages []page `yaml:"pages"` Pages []page `yaml:"pages"`

View File

@ -96,6 +96,18 @@ func newApplication(config *config) (*application, error) {
config.Branding.FaviconURL = app.transformUserDefinedAssetPath(config.Branding.FaviconURL) 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) config.Branding.LogoURL = app.transformUserDefinedAssetPath(config.Branding.LogoURL)
return app, nil return app, nil
@ -257,6 +269,26 @@ func (a *application) server() (func() error, func() error) {
w.Write(bundledCSSContents) 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 var absAssetsPath string
if a.Config.Server.AssetsPath != "" { if a.Config.Server.AssetsPath != "" {
absAssetsPath, _ = filepath.Abs(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"
}
]
}