Skip to content

A self-hosted dashboard that puts all your feeds in one place

Dynamize manifest.json with configurable options

David Pearson333d40ed4f45
diff --git a/docs/configuration.md b/docs/configuration.md
index adb73c4..8ebcb0e 100644
--- a/docs/configuration.md
+++ b/docs/configuration.md
@@ -268,6 +268,9 @@ branding:
<p>Powered by <a href="https://github.com/glanceapp/glance">Glance</a></p>
logo-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
@@ -279,6 +282,9 @@ branding:
| logo-text | string | no | G |
| logo-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`
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`
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
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.
diff --git a/internal/glance/config.go b/internal/glance/config.go
index a63afff..4b9060c 100644
--- a/internal/glance/config.go
+++ b/internal/glance/config.go
@@ -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"`
diff --git a/internal/glance/glance.go b/internal/glance/glance.go
index ab63536..7952de1 100644
--- a/internal/glance/glance.go
+++ b/internal/glance/glance.go
@@ -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)
diff --git a/internal/glance/static/manifest.json b/internal/glance/static/manifest.json
deleted file mode 100644
index 42e8213..0000000
--- a/internal/glance/static/manifest.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "name": "Glance",
- "display": "standalone",
- "background_color": "#151519",
- "scope": "/",
- "start_url": "/",
- "icons": [
- {
- "src": "app-icon.png",
- "type": "image/png",
- "sizes": "512x512"
- }
- ]
-}
diff --git a/internal/glance/templates/manifest.json b/internal/glance/templates/manifest.json
new file mode 100644
index 0000000..a7ccce4
--- /dev/null
+++ b/internal/glance/templates/manifest.json
@@ -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"
+ }
+ ]
+}
\ No newline at end of file