Skip to content

Commit 7e1d747

Browse files
committed
fix footer source link for untagged head commits
1 parent 3cd5d45 commit 7e1d747

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

internal/frontend/create.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type SSRHandler struct {
2929
func NewHandler(cfg *config.Config) (*SSRHandler, error) {
3030
basePageConfig := &BasePageConfig{
3131
Version: version.Version,
32+
Commit: version.Commit,
3233
RootURL: cfg.RootURL,
3334
}
3435
if cfg.RootPath != "" {

internal/frontend/http.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ func init() {
3030
// BasePageConfig is data that all pages require to function correctly, no matter
3131
// whether error page or lobby page.
3232
type BasePageConfig struct {
33-
// Version is the source code version of this build.
33+
// Version is the tagged source code version of this build. Can be empty for dev
34+
// builds. Untagged commits will be of format `tag-N-gSHA`.
3435
Version string `json:"version"`
36+
// Commit that was deployed, if we didn't deploy a concrete tag.
37+
Commit string `json:"commit"`
3538
// RootPath is the path directly after the domain and before the
3639
// scribble.rs paths. For example if you host scribblers on painting.com
3740
// but already host a different website, then your API paths might have to

internal/frontend/templates/footer.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
{{define "footer"}}
22
{{if eq .Version "dev"}}
33
<a class="footer-item" href="https://github.com/scribble-rs/scribble.rs" target="_blank">{{.Version}}</a>
4+
{{else if ne .Commit ""}}
5+
<a class="footer-item" href="https://github.com/scribble-rs/scribble.rs/commit/{{.Commit}}"
6+
target="_blank">{{.Version}}</a>
47
{{else}}
58
<a class="footer-item" href="https://github.com/scribble-rs/scribble.rs/releases/tag/{{.Version}}"
69
target="_blank">{{.Version}}</a>

internal/version/version.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,29 @@
22
// scearios, it will default to "dev".
33
package version
44

5+
import (
6+
"fmt"
7+
"regexp"
8+
)
9+
510
// Version of the application.
6-
var Version = "dev"
11+
var (
12+
Version = "dev"
13+
Commit = ""
14+
)
15+
16+
func init() {
17+
// We expect to get a "dirt git tag" when deploying a test version that
18+
// we did not yet finalize. We'll take it apart to allow the frontend
19+
// to put the correct link to the repository.
20+
21+
if Version != "dev" {
22+
// version-commit_count_after_version-hash
23+
hashRegex := regexp.MustCompile("v.+?(?:-\\d+?-g(.+?)(?:$|-))")
24+
match := hashRegex.FindStringSubmatch(Version)
25+
fmt.Println(match, len(match))
26+
if len(match) == 2 {
27+
Commit = match[1]
28+
}
29+
}
30+
}

0 commit comments

Comments
 (0)