Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/glance/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type config struct {
LogoText string `yaml:"logo-text"`
LogoURL string `yaml:"logo-url"`
FaviconURL string `yaml:"favicon-url"`
PwaText string `yaml:"pwa-text"`
} `yaml:"branding"`

Pages []page `yaml:"pages"`
Expand Down
35 changes: 35 additions & 0 deletions internal/glance/glance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package glance
import (
"bytes"
"context"
"encoding/json"
"fmt"
"html/template"
"log"
Expand Down Expand Up @@ -228,6 +229,7 @@ func (a *application) server() (func() error, func() error) {
w.WriteHeader(http.StatusOK)
})

mux.HandleFunc(fmt.Sprintf("GET /static/%s/manifest.json", staticFSHash), a.handleManifestRequest)
mux.Handle(
fmt.Sprintf("GET /static/%s/{path...}", staticFSHash),
http.StripPrefix("/static/"+staticFSHash, fileServerWithCache(http.FS(staticFS), 24*time.Hour)),
Expand Down Expand Up @@ -267,3 +269,36 @@ func (a *application) server() (func() error, func() error) {

return start, stop
}

func (a *application) handleManifestRequest(w http.ResponseWriter, r *http.Request) {
manifest := map[string]interface{}{
"name": func() string {
if a.Config.Branding.PwaText != "" {
return a.Config.Branding.PwaText
}
return "Glance"
}(),
"short_name": a.Config.Branding.PwaText,
"display": "standalone",
"background_color": "#151519",
"scope": "/",
"start_url": "/",
"icons": []map[string]string{
{
"src": func() string {
if a.Config.Branding.FaviconURL != "" {
return a.transformUserDefinedAssetPath(a.Config.Branding.FaviconURL)
}
return a.AssetPath("app-icon.png")
}(),
"type": "image/png",
"sizes": "512x512",
"purpose": "any maskable",
},
},
}

w.Header().Set("Content-Type", "application/json")
w.Header().Set("Cache-Control", "public, max-age=3600")
json.NewEncoder(w).Encode(manifest)
}
4 changes: 2 additions & 2 deletions internal/glance/templates/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="Glance">
<meta name="apple-mobile-web-app-title" content="{{ if .App.Config.Branding.PwaText }}{{ .App.Config.Branding.PwaText }}{{ else }}Glance{{ end }}">
<meta name="theme-color" content="{{ if ne nil .App.Config.Theme.BackgroundColor }}{{ .App.Config.Theme.BackgroundColor }}{{ else }}hsl(240, 8%, 9%){{ end }}">
<link rel="apple-touch-icon" sizes="512x512" href="{{ .App.AssetPath "app-icon.png" }}">
<link rel="apple-touch-icon" sizes="512x512" href="{{ if .App.Config.Branding.FaviconURL }}{{ .App.Config.Branding.FaviconURL }}{{ else }}{{ .App.AssetPath "app-icon.png" }}{{ end }}">
<link rel="manifest" href="{{ .App.AssetPath "manifest.json" }}">
<link rel="icon" type="image/png" href="{{ .App.Config.Branding.FaviconURL }}" />
<link rel="stylesheet" href="{{ .App.AssetPath "main.css" }}">
Expand Down