From 3cfbe0c89b95971413df7f533c095db050f9ad9a Mon Sep 17 00:00:00 2001 From: David Leonard Date: Fri, 17 May 2024 14:37:05 -0700 Subject: [PATCH 001/382] Allow some branding customization. --- docs/configuration.md | 28 ++++++++++++++++++++++++++++ internal/assets/templates/page.html | 6 ++++-- internal/glance/config.go | 10 +++++++--- internal/glance/glance.go | 14 ++++++++++---- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index e698fdd..40ff0cc 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -3,6 +3,7 @@ - [Intro](#intro) - [Preconfigured page](#preconfigured-page) - [Server](#server) +- [Branding](#branding) - [Theme](#theme) - [Themes](#themes) - [Pages & Columns](#pages--columns) @@ -162,6 +163,33 @@ To be able to point to an asset from your assets path, use the `/assets/` path l icon: /assets/gitea-icon.png ``` +## Branding +You can adjust the various parts of the branding through a top level `branding` property. Example: + +```yaml +branding: + show: true + name: Glance + short-name: G +``` + +### Properties + +| Name | Type | Required | Default | +| ---- | ---- | -------- | ------- | +| show | bool | no | true | +| name | string | no | Glance | +| short-name | string | no | G | + +#### `show` +True will show the glance footer, false will hide it. + +#### `name` +Sets the name presented after the page name in the title. + +#### `short-name` +Sets the name presented before the pages in the header. + ## 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/assets/templates/page.html b/internal/assets/templates/page.html index 61fad9e..c50dfe2 100644 --- a/internal/assets/templates/page.html +++ b/internal/assets/templates/page.html @@ -1,6 +1,6 @@ {{ template "document.html" . }} -{{ define "document-title" }}{{ .Page.Title }} - Glance{{ end }} +{{ define "document-title" }}{{ .Page.Title }} - {{ .App.Config.Branding.Name }}{{ end }} {{ define "document-head-before" }} + + + + + + {{ block "document-head-after" . }}{{ end }} diff --git a/internal/glance/glance.go b/internal/glance/glance.go index 653be75..8520012 100644 --- a/internal/glance/glance.go +++ b/internal/glance/glance.go @@ -41,6 +41,7 @@ type Server struct { Host string `yaml:"host"` Port uint16 `yaml:"port"` AssetsPath string `yaml:"assets-path"` + BaseUrl string `yaml:"base-url"` StartedAt time.Time `yaml:"-"` } @@ -194,10 +195,10 @@ func (a *Application) Serve() error { // TODO: add HTTPS support mux := http.NewServeMux() - mux.HandleFunc("GET /{$}", a.HandlePageRequest) - mux.HandleFunc("GET /{page}", a.HandlePageRequest) - mux.HandleFunc("GET /api/pages/{page}/content/{$}", a.HandlePageContentRequest) - mux.Handle("GET /static/{path...}", http.StripPrefix("/static/", FileServerWithCache(http.FS(assets.PublicFS), 2*time.Hour))) + mux.HandleFunc(fmt.Sprintf("GET %s/{$}", a.Config.Server.BaseUrl), a.HandlePageRequest) + mux.HandleFunc(fmt.Sprintf("GET %s/{page}", a.Config.Server.BaseUrl), a.HandlePageRequest) + mux.HandleFunc(fmt.Sprintf("GET %s/api/pages/{page}/content/{$}", a.Config.Server.BaseUrl), a.HandlePageContentRequest) + mux.Handle(fmt.Sprintf("GET %s/static/{path...}", a.Config.Server.BaseUrl), http.StripPrefix(fmt.Sprintf("%s/static/", a.Config.Server.BaseUrl), FileServerWithCache(http.FS(assets.PublicFS), 2*time.Hour))) if a.Config.Server.AssetsPath != "" { absAssetsPath, err := filepath.Abs(a.Config.Server.AssetsPath) @@ -208,7 +209,7 @@ func (a *Application) Serve() error { slog.Info("Serving assets", "path", absAssetsPath) assetsFS := FileServerWithCache(http.Dir(a.Config.Server.AssetsPath), 2*time.Hour) - mux.Handle("/assets/{path...}", http.StripPrefix("/assets/", assetsFS)) + mux.Handle(fmt.Sprintf("%s/assets/{path...}", a.Config.Server.BaseUrl), http.StripPrefix("/assets/", assetsFS)) } server := http.Server{ From 23d6d411481e1eb10dc7f397691123706f48d4d9 Mon Sep 17 00:00:00 2001 From: CremaLuca Date: Wed, 10 Jul 2024 15:22:58 +0200 Subject: [PATCH 017/382] fix(serve): using paths without base url --- internal/assets/static/main.js | 6 +++--- internal/assets/templates/page.html | 5 +++-- internal/glance/glance.go | 14 +++++++------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/internal/assets/static/main.js b/internal/assets/static/main.js index 9818ecf..5426c29 100644 --- a/internal/assets/static/main.js +++ b/internal/assets/static/main.js @@ -21,10 +21,10 @@ function throttledDebounce(callback, maxDebounceTimes, debounceDelay) { }; -async function fetchPageContent(pageSlug) { +async function fetchPageContent(pageData) { // TODO: handle non 200 status codes/time outs // TODO: add retries - const response = await fetch(`/api/pages/${pageSlug}/content/`); + const response = await fetch(`${pageData.baseUrl}/api/pages/${pageData.slug}/content/`); const content = await response.text(); return content; @@ -336,7 +336,7 @@ function setupCollapsibleGrids() { async function setupPage() { const pageElement = document.getElementById("page"); const pageContentElement = document.getElementById("page-content"); - const pageContent = await fetchPageContent(pageData.slug); + const pageContent = await fetchPageContent(pageData); pageContentElement.innerHTML = pageContent; diff --git a/internal/assets/templates/page.html b/internal/assets/templates/page.html index 98bb111..42e6bb2 100644 --- a/internal/assets/templates/page.html +++ b/internal/assets/templates/page.html @@ -6,6 +6,7 @@ {{ end }} @@ -14,13 +15,13 @@ {{ define "document-head-after" }} {{ template "page-style-overrides.gotmpl" . }} {{ if ne "" .App.Config.Theme.CustomCSSFile }} - + {{ end }} {{ end }} {{ define "navigation-links" }} {{ range .App.Config.Pages }} -{{ .Title }} +{{ .Title }} {{ end }} {{ end }} diff --git a/internal/glance/glance.go b/internal/glance/glance.go index 8520012..dd9e40b 100644 --- a/internal/glance/glance.go +++ b/internal/glance/glance.go @@ -41,7 +41,7 @@ type Server struct { Host string `yaml:"host"` Port uint16 `yaml:"port"` AssetsPath string `yaml:"assets-path"` - BaseUrl string `yaml:"base-url"` + BaseUrl string `yaml:"base-url"` StartedAt time.Time `yaml:"-"` } @@ -195,10 +195,10 @@ func (a *Application) Serve() error { // TODO: add HTTPS support mux := http.NewServeMux() - mux.HandleFunc(fmt.Sprintf("GET %s/{$}", a.Config.Server.BaseUrl), a.HandlePageRequest) - mux.HandleFunc(fmt.Sprintf("GET %s/{page}", a.Config.Server.BaseUrl), a.HandlePageRequest) - mux.HandleFunc(fmt.Sprintf("GET %s/api/pages/{page}/content/{$}", a.Config.Server.BaseUrl), a.HandlePageContentRequest) - mux.Handle(fmt.Sprintf("GET %s/static/{path...}", a.Config.Server.BaseUrl), http.StripPrefix(fmt.Sprintf("%s/static/", a.Config.Server.BaseUrl), FileServerWithCache(http.FS(assets.PublicFS), 2*time.Hour))) + mux.HandleFunc("GET /{$}", a.HandlePageRequest) + mux.HandleFunc("GET /{page}", a.HandlePageRequest) + mux.HandleFunc("GET /api/pages/{page}/content/{$}", a.HandlePageContentRequest) + mux.Handle("GET /static/{path...}", http.StripPrefix("/static/", FileServerWithCache(http.FS(assets.PublicFS), 2*time.Hour))) if a.Config.Server.AssetsPath != "" { absAssetsPath, err := filepath.Abs(a.Config.Server.AssetsPath) @@ -209,7 +209,7 @@ func (a *Application) Serve() error { slog.Info("Serving assets", "path", absAssetsPath) assetsFS := FileServerWithCache(http.Dir(a.Config.Server.AssetsPath), 2*time.Hour) - mux.Handle(fmt.Sprintf("%s/assets/{path...}", a.Config.Server.BaseUrl), http.StripPrefix("/assets/", assetsFS)) + mux.Handle("/assets/{path...}", http.StripPrefix("/assets/", assetsFS)) } server := http.Server{ @@ -219,6 +219,6 @@ func (a *Application) Serve() error { a.Config.Server.StartedAt = time.Now() - slog.Info("Starting server", "host", a.Config.Server.Host, "port", a.Config.Server.Port) + slog.Info("Starting server", "host", a.Config.Server.Host, "port", a.Config.Server.Port, "base url", a.Config.Server.BaseUrl) return server.ListenAndServe() } From e0dee998d434427278fe82ec9dce829cadbba25a Mon Sep 17 00:00:00 2001 From: dvdandroid <6277172+DVDAndroid@users.noreply.github.com> Date: Tue, 23 Jul 2024 23:17:28 +0200 Subject: [PATCH 018/382] Make Twitch avatar clickable --- internal/assets/templates/twitch-channels.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/assets/templates/twitch-channels.html b/internal/assets/templates/twitch-channels.html index f053122..8e23347 100644 --- a/internal/assets/templates/twitch-channels.html +++ b/internal/assets/templates/twitch-channels.html @@ -7,7 +7,9 @@
{{ if .Exists }} - + + + {{ else }} From c9efdc2c16757999e4a0a486858906ad08e18666 Mon Sep 17 00:00:00 2001 From: dvdandroid <6277172+DVDAndroid@users.noreply.github.com> Date: Wed, 24 Jul 2024 21:38:35 +0200 Subject: [PATCH 019/382] Fix incorrect LiveSince if API returned no game (streamer can stream without a category/game associated) --- internal/feed/twitch.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/feed/twitch.go b/internal/feed/twitch.go index 1ce9354..739d7d1 100644 --- a/internal/feed/twitch.go +++ b/internal/feed/twitch.go @@ -204,9 +204,11 @@ func fetchChannelFromTwitchTask(channel string) (TwitchChannel, error) { result.IsLive = true result.ViewersCount = channelShell.UserOrError.Stream.ViewersCount - if streamMetadata.UserOrNull != nil && streamMetadata.UserOrNull.Stream != nil && streamMetadata.UserOrNull.Stream.Game != nil { - result.Category = streamMetadata.UserOrNull.Stream.Game.Name - result.CategorySlug = streamMetadata.UserOrNull.Stream.Game.Slug + if streamMetadata.UserOrNull != nil && streamMetadata.UserOrNull.Stream != nil { + if streamMetadata.UserOrNull.Stream.Game != nil { + result.Category = streamMetadata.UserOrNull.Stream.Game.Name + result.CategorySlug = streamMetadata.UserOrNull.Stream.Game.Slug + } startedAt, err := time.Parse("2006-01-02T15:04:05Z", streamMetadata.UserOrNull.Stream.StartedAt) if err == nil { From 7bc9c704d14b9c844b830a74262b850db05b4640 Mon Sep 17 00:00:00 2001 From: dvdandroid <6277172+DVDAndroid@users.noreply.github.com> Date: Wed, 24 Jul 2024 21:50:00 +0200 Subject: [PATCH 020/382] Don't render "empty" game category --- internal/assets/templates/twitch-channels.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/assets/templates/twitch-channels.html b/internal/assets/templates/twitch-channels.html index f053122..cce60e3 100644 --- a/internal/assets/templates/twitch-channels.html +++ b/internal/assets/templates/twitch-channels.html @@ -18,7 +18,9 @@ {{ .Name }} {{ if .Exists }} {{ if .IsLive }} - {{ .Category }} + {{ if .Category }} + {{ .Category }} + {{ end }}