Skip to content

Added a config to load JavaScript similar to CSS with Cache Busting #551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion internal/glance/config.go
Original file line number Diff line number Diff line change
@@ -34,7 +34,13 @@ type config struct {
} `yaml:"server"`

Document struct {
Head template.HTML `yaml:"head"`
Head template.HTML `yaml:"head"`
CustomJSFile string `yaml:"custom-js-file"`
CustomJSFiles []struct {
Src string `yaml:"src"`
Defer bool `yaml:"defer"`
Async bool `yaml:"async"`
} `yaml:"custom-js-files"`
} `yaml:"document"`

Theme struct {
@@ -47,6 +53,7 @@ type config struct {
ContrastMultiplier float32 `yaml:"contrast-multiplier"`
TextSaturationMultiplier float32 `yaml:"text-saturation-multiplier"`
CustomCSSFile string `yaml:"custom-css-file"`
CustomCSSFiles []string `yaml:"custom-css-files"`
} `yaml:"theme"`

Branding struct {
13 changes: 13 additions & 0 deletions internal/glance/templates/page.html
Original file line number Diff line number Diff line change
@@ -18,9 +18,22 @@

{{ if ne "" .App.Config.Theme.CustomCSSFile }}
<link rel="stylesheet" href="{{ .App.Config.Theme.CustomCSSFile }}?v={{ .App.CreatedAt.Unix }}">
{{ else }}
{{ range .App.Config.Theme.CustomCSSFiles }}
<link rel="stylesheet" href="{{ . }}?v={{ $.App.CreatedAt.Unix }}">
{{ end }}
{{ end }}

{{ if ne "" .App.Config.Document.Head }}{{ .App.Config.Document.Head }}{{ end }}

{{ if ne "" .App.Config.Document.CustomJSFile }}
<script src="{{ .App.Config.Document.CustomJSFile }}?v={{ .App.CreatedAt.Unix }}"></script>
{{ else }}
{{ range .App.Config.Document.CustomJSFiles }}
<script src="{{ .Src }}?v={{ $.App.CreatedAt.Unix }}" {{ if .Async }} async{{ else if .Defer }} defer{{ end }}></script>
{{ end }}
{{ end }}

{{ end }}

{{ define "navigation-links" }}