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" . }} {{ .Config.Meta.Title }} {{- if .Config.Meta.Description }} {{- end }} - +
diff --git a/embed/templates/500.html.tmpl b/embed/templates/500.html.tmpl index 13d75c7..8363b2d 100644 --- a/embed/templates/500.html.tmpl +++ b/embed/templates/500.html.tmpl @@ -6,12 +6,12 @@ SPDX-License-Identifier: MIT - {{ template "head" }} + {{ template "head" . }} {{ .Config.Meta.Title }} {{- if .Config.Meta.Description }} {{- end }} - +
diff --git a/embed/templates/head.html.tmpl b/embed/templates/head.html.tmpl index 27af2f3..6d72efa 100644 --- a/embed/templates/head.html.tmpl +++ b/embed/templates/head.html.tmpl @@ -2,7 +2,7 @@ Shared HTML tags to put inside tag. Include inside tag, like this: - {{ template "head" }} + {{ template "head" . }} Page Title @@ -13,10 +13,10 @@ SPDX-License-Identifier: MIT - - - + + + {{- end }} diff --git a/embed/templates/repo-blob-ref-html-preview.html.tmpl b/embed/templates/repo-blob-ref-html-preview.html.tmpl index 8862df2..a1959ee 100644 --- a/embed/templates/repo-blob-ref-html-preview.html.tmpl +++ b/embed/templates/repo-blob-ref-html-preview.html.tmpl @@ -6,8 +6,8 @@ SPDX-License-Identifier: MIT - - {{ template "head" }} + + {{ template "head" . }} {{- $path := "" -}} {{- $name := "" -}} {{- range .Path -}} diff --git a/embed/templates/repo-blob-ref.html.tmpl b/embed/templates/repo-blob-ref.html.tmpl index fcea150..6c07c73 100644 --- a/embed/templates/repo-blob-ref.html.tmpl +++ b/embed/templates/repo-blob-ref.html.tmpl @@ -6,8 +6,8 @@ SPDX-License-Identifier: MIT - {{ template "head" }} - + {{ template "head" . }} + {{- $path := "" -}} {{- $name := "" -}} {{- range .Path -}} diff --git a/embed/templates/repo-commit.html.tmpl b/embed/templates/repo-commit.html.tmpl index 361c043..da4871c 100644 --- a/embed/templates/repo-commit.html.tmpl +++ b/embed/templates/repo-commit.html.tmpl @@ -7,13 +7,13 @@ SPDX-License-Identifier: MIT {{ $shorthash := slice .Commit.Hash.String 0 8 }} - {{ template "head" }} - + {{ template "head" . }} + {{ $shorthash }} - {{ .Meta.DisplayName }} - +
diff --git a/embed/templates/repo-list.html.tmpl b/embed/templates/repo-list.html.tmpl index 7f4612f..115e5b7 100644 --- a/embed/templates/repo-list.html.tmpl +++ b/embed/templates/repo-list.html.tmpl @@ -6,13 +6,13 @@ SPDX-License-Identifier: MIT - {{ template "head" }} - + {{ template "head" . }} + {{ .Config.Meta.Title }} {{- if .Config.Meta.Description }} {{- end }} - +
diff --git a/embed/templates/repo-log-ref.html.tmpl b/embed/templates/repo-log-ref.html.tmpl index 4c79c3d..696a221 100644 --- a/embed/templates/repo-log-ref.html.tmpl +++ b/embed/templates/repo-log-ref.html.tmpl @@ -6,13 +6,13 @@ SPDX-License-Identifier: MIT - {{ template "head" }} - + {{ template "head" . }} + Commit history at {{ .Meta.Ref }} - {{ .Meta.DisplayName }} - +
diff --git a/embed/templates/repo-refs.html.tmpl b/embed/templates/repo-refs.html.tmpl index a83fd32..74599f5 100644 --- a/embed/templates/repo-refs.html.tmpl +++ b/embed/templates/repo-refs.html.tmpl @@ -6,8 +6,8 @@ SPDX-License-Identifier: MIT - {{ template "head" }} - + {{ template "head" . }} + Refs - {{ .Meta.DisplayName }} diff --git a/embed/templates/repo-top.html.tmpl b/embed/templates/repo-top.html.tmpl index d274cb5..00e4859 100644 --- a/embed/templates/repo-top.html.tmpl +++ b/embed/templates/repo-top.html.tmpl @@ -6,14 +6,14 @@ SPDX-License-Identifier: MIT - {{ template "head" }} - - + {{ template "head" . }} + + {{ .Meta.DisplayName }} | {{ .Config.Meta.Title }} {{- if .Meta.Description }} {{- end }} - +
diff --git a/embed/templates/repo-tree-ref.html.tmpl b/embed/templates/repo-tree-ref.html.tmpl index 8bde3bc..b41536d 100644 --- a/embed/templates/repo-tree-ref.html.tmpl +++ b/embed/templates/repo-tree-ref.html.tmpl @@ -6,8 +6,8 @@ SPDX-License-Identifier: MIT - {{ template "head" }} - + {{ template "head" . }} + {{- $path := "" -}} {{- range .Path -}} {{- $path = printf "%s/%s" $path . -}} diff --git a/embed/templates/site-footer.html.tmpl b/embed/templates/site-footer.html.tmpl index 9f6c8da..9125d9b 100644 --- a/embed/templates/site-footer.html.tmpl +++ b/embed/templates/site-footer.html.tmpl @@ -15,7 +15,7 @@ SPDX-License-Identifier: MIT {{- end }} - +