diff --git a/config/config.go b/config/config.go index 65475c2..e1e87bd 100644 --- a/config/config.go +++ b/config/config.go @@ -3,12 +3,15 @@ package config import ( "fmt" "math" + "net/url" "os" "path/filepath" "gopkg.in/yaml.v3" ) +var staticDirRevision string + type Config struct { Repo struct { ScanPath string `yaml:"scanPath"` @@ -48,6 +51,11 @@ type Config struct { Port uint `yaml:"port"` } `yaml:"server"` + // StaticDirRevision represents version / revision of "Dirs.Static" (or the + // "embed/static" directory if the option is unset.) HTML templates uses + // this string for browser-cache bust. + StaticDirRevision string `yaml:"staticDirRevision"` + filepath string } @@ -61,6 +69,7 @@ func NewWithDefaults() *Config { } c.Meta.Title = "Repositories" + c.StaticDirRevision = staticDirRevision return &c } @@ -122,6 +131,8 @@ func (c *Config) Resolve(cwd string) error { return fmt.Errorf("server.port should be in 0 < x <= %d range", math.MaxUint16) } + c.StaticDirRevision = url.QueryEscape(c.StaticDirRevision) + return nil } diff --git a/default.nix b/default.nix index d74e28d..03bce99 100644 --- a/default.nix +++ b/default.nix @@ -6,7 +6,7 @@ lib, git, }: -buildGoModule { +buildGoModule (finalAttrs: { name = "legit"; version = "1.0.0"; @@ -28,6 +28,7 @@ buildGoModule { # git binary from nixpkgs links against libs under "/nix/store/.../lib" "-X main.additionalAccessDirs=/nix/store" "-X github.com/pocka/legit/git/exe.gitPath=${lib.getExe git}" + "-X github.com/pocka/legit/config.staticDirRevision=v${finalAttrs.version}-embed" ]; # Test scripts invoke system "git" command. @@ -36,4 +37,4 @@ buildGoModule { meta = { mainProgram = "legit"; }; -} +}) diff --git a/embed/templates/404.html.tmpl b/embed/templates/404.html.tmpl index d5e3271..0854bb3 100644 --- a/embed/templates/404.html.tmpl +++ b/embed/templates/404.html.tmpl @@ -6,12 +6,12 @@ SPDX-License-Identifier: MIT
- {{ template "head" }} + {{ template "head" . }}