diff --git a/.air.toml b/.air.toml index cc3f138355465c9d2d12f319b72e1dd7747cca97..1ae991dd5d20916f5f0a6f4dfedc1a7a07d6a7ff 100644 --- a/.air.toml +++ b/.air.toml @@ -7,7 +7,7 @@ tmp_dir = "tmp" [build] bin = "./tmp/willow" - cmd = "go build -o ./tmp/willow ./cmd" + cmd = "go build -o ./tmp/willow -ldflags \"-X main.version=`git describe --long 2>/dev/null | sed 's/\\([^-]*-g\\)/r\\1/;s/-/./g'`\" ./cmd" delay = 1000 exclude_dir = ["assets", "tmp", "vendor", "testdata", "data", "website"] exclude_file = [] diff --git a/ws/static/dashboard.html.tmpl b/ws/static/dashboard.html.tmpl new file mode 100644 index 0000000000000000000000000000000000000000..a431605124dfd3ac7eac9f68ce7528e5d3cd9afa --- /dev/null +++ b/ws/static/dashboard.html.tmpl @@ -0,0 +1,59 @@ +{{- template "head" }} +{{- template "header" }} +
+
+
+ + {{- range .Projects -}} + {{- if ne .Running (index .Releases 0).Tag -}} +

Outdated projects

+ {{- break -}} + {{- end -}} + {{- end -}} + {{- range .Projects -}} + {{- if ne .Running (index .Releases 0).Tag -}} +
+

{{ .Name }}   Delete?

+

You've selected {{ .Running }}. Modify?

+

Latest: {{ (index .Releases 0).Tag }}

+

View release notes

+
+ {{- end -}} + {{- end -}} + + + {{- range .Projects -}} + {{- if eq .Running (index .Releases 0).Tag -}} +

Up-to-date projects

+ {{- break -}} + {{- end -}} + {{- end -}} + {{- range .Projects -}} + {{- if eq .Running (index .Releases 0).Tag -}} +
+

{{ .Name }}   Delete?

+

You've selected {{ .Running }}. Modify?

+
+ {{- end -}} + {{- end -}} +
+
+

Release notes

+ {{- range .Projects -}} +
+

{{ .Name }}: release notes for {{ (index .Releases 0).Tag }}

+ {{- if eq .Forge "github" "gitea" "forgejo" -}} + {{- (index .Releases 0).Content -}} + {{- else -}} +
+                        {{- (index .Releases 0).Content -}}
+                        
+ {{- end -}} +

Back to project

+ +
+ {{- end -}} +
+
+
+{{- template "footer" .Version }} diff --git a/ws/static/home.html.license b/ws/static/dashboard.html.tmpl.license similarity index 100% rename from ws/static/home.html.license rename to ws/static/dashboard.html.tmpl.license diff --git a/ws/static/footer.html.tmpl b/ws/static/footer.html.tmpl new file mode 100644 index 0000000000000000000000000000000000000000..4e8e38fb8b80797bd551efeada4063d1cac3832b --- /dev/null +++ b/ws/static/footer.html.tmpl @@ -0,0 +1,9 @@ +{{- define "footer" }} + + + +{{- end -}} diff --git a/ws/static/login.html.license b/ws/static/footer.html.tmpl.license similarity index 100% rename from ws/static/login.html.license rename to ws/static/footer.html.tmpl.license diff --git a/ws/static/login.html b/ws/static/head.html.tmpl similarity index 58% rename from ws/static/login.html rename to ws/static/head.html.tmpl index 4840cc7ddf203a228c0f69316f89e57ae4124b95..b7ac084eceebad36929328cb949addba697da309 100644 --- a/ws/static/login.html +++ b/ws/static/head.html.tmpl @@ -1,3 +1,4 @@ +{{- define "head" }} @@ -19,19 +20,5 @@ - -

Willow

-
-
- - -
-
- - -
- -
-

Source code

- - + +{{- end -}} diff --git a/ws/static/new.html.license b/ws/static/head.html.tmpl.license similarity index 100% rename from ws/static/new.html.license rename to ws/static/head.html.tmpl.license diff --git a/ws/static/header.html.tmpl b/ws/static/header.html.tmpl new file mode 100644 index 0000000000000000000000000000000000000000..14cea1476681cf2343186ae5765def63e09e5c6a --- /dev/null +++ b/ws/static/header.html.tmpl @@ -0,0 +1,11 @@ +{{- define "header" }} +
+
+

Willow

+ +
+
+{{- end -}} diff --git a/ws/static/select-release.html.license b/ws/static/header.html.tmpl.license similarity index 100% rename from ws/static/select-release.html.license rename to ws/static/header.html.tmpl.license diff --git a/ws/static/home.html b/ws/static/home.html deleted file mode 100644 index 6086e72d4e8b2bba590ef61e8c16ddb7f1741d85..0000000000000000000000000000000000000000 --- a/ws/static/home.html +++ /dev/null @@ -1,96 +0,0 @@ - - - - Willow - - - - - - - - - - - - - - - - - - -
-
-
-

Willow

- -
-
-
-
-
- - {{- range .Projects -}} - {{- if ne .Running (index .Releases 0).Tag -}} -

Outdated projects

- {{- break -}} - {{- end -}} - {{- end -}} - {{- range .Projects -}} - {{- if ne .Running (index .Releases 0).Tag -}} -
-

{{ .Name }}   Delete?

-

You've selected {{ .Running }}. Modify?

-

Latest: {{ (index .Releases 0).Tag }}

-

View release notes

-
- {{- end -}} - {{- end -}} - - - {{- range .Projects -}} - {{- if eq .Running (index .Releases 0).Tag -}} -

Up-to-date projects

- {{- break -}} - {{- end -}} - {{- end -}} - {{- range .Projects -}} - {{- if eq .Running (index .Releases 0).Tag -}} -
-

{{ .Name }}   Delete?

-

You've selected {{ .Running }}. Modify?

-
- {{- end -}} - {{- end -}} -
-
-

Release notes

- {{- range .Projects -}} -
-

{{ .Name }}: release notes for {{ (index .Releases 0).Tag }}

- {{- if eq .Forge "github" "gitea" "forgejo" -}} - {{- (index .Releases 0).Content -}} - {{- else -}} -
-                    {{- (index .Releases 0).Content -}}
-                    
- {{- end -}} -

Back to project

- -
- {{- end -}} -
-
-
- -
- - diff --git a/ws/static/login.html.tmpl b/ws/static/login.html.tmpl new file mode 100644 index 0000000000000000000000000000000000000000..ad68c8a4ab081f7b29c5505d1b67316944fcb25f --- /dev/null +++ b/ws/static/login.html.tmpl @@ -0,0 +1,20 @@ +{{- template "head" -}} +
+
+

Willow

+
+
+
+
+
+ + +
+
+ + +
+ +
+
+{{- template "footer" .Version -}} diff --git a/ws/static/login.html.tmpl.license b/ws/static/login.html.tmpl.license new file mode 100644 index 0000000000000000000000000000000000000000..f0b540a20dddb509a79479562bebe1726202a387 --- /dev/null +++ b/ws/static/login.html.tmpl.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: Amolith + +SPDX-License-Identifier: Apache-2.0 diff --git a/ws/static/new.html b/ws/static/new.html.tmpl similarity index 61% rename from ws/static/new.html rename to ws/static/new.html.tmpl index f16fc005fbefb2537f9405857a99f9aac6d13c1d..9fcd18212411a54ff7ba1c0b346b0d45a1a40e88 100644 --- a/ws/static/new.html +++ b/ws/static/new.html.tmpl @@ -1,26 +1,7 @@ - - - - Willow - - - - - - - - - - - - - - - - - - -

Willow

+{{- template "head" }} +{{- template "header" }} +
+

Track a new project

@@ -51,5 +32,5 @@
- - +
+{{- template "footer" .Version }} diff --git a/ws/static/new.html.tmpl.license b/ws/static/new.html.tmpl.license new file mode 100644 index 0000000000000000000000000000000000000000..f0b540a20dddb509a79479562bebe1726202a387 --- /dev/null +++ b/ws/static/new.html.tmpl.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: Amolith + +SPDX-License-Identifier: Apache-2.0 diff --git a/ws/static/select-release.html b/ws/static/select-release.html.tmpl similarity index 65% rename from ws/static/select-release.html rename to ws/static/select-release.html.tmpl index 2603d8a54d850ee9b20a3f699f28e19aa478ca0e..ab9069ca4760da06422528eb2ab049b57b4d84ba 100644 --- a/ws/static/select-release.html +++ b/ws/static/select-release.html.tmpl @@ -1,26 +1,7 @@ - - - - Willow - - - - - - - - - - - - - - - - - - -

Willow

+{{- template "head" }} +{{- template "header" }} +{{- with .Project }} +

Which release of {{ .Name }} are you currently running?

@@ -52,5 +33,6 @@ {{- if or (eq $forge "github") -}} Some RSS feeds (notably GitHub's) include a limited number of releases. If you don't see your version, please change the forge type to "Other". {{- end -}} - - +
+{{- end }} +{{- template "footer" .Version -}} diff --git a/ws/static/select-release.html.tmpl.license b/ws/static/select-release.html.tmpl.license new file mode 100644 index 0000000000000000000000000000000000000000..f0b540a20dddb509a79479562bebe1726202a387 --- /dev/null +++ b/ws/static/select-release.html.tmpl.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: Amolith + +SPDX-License-Identifier: Apache-2.0 diff --git a/ws/static/styles.css b/ws/static/styles.css index 5ed0ff74960c3b0c75b69758fab23539dba195e7..968951b0e23af81829ea00f3323d6ddee393a3c3 100644 --- a/ws/static/styles.css +++ b/ws/static/styles.css @@ -53,34 +53,34 @@ a:visited { } /* Grid layout */ -.container { +body { width: auto; min-height: 100vh; } @supports (display: grid) { - .container { + body { display: grid; grid-template-rows: [header] auto [main] 1fr [footer] auto; } - .container > header, - .container > main, - .container > footer { + body > header, + body > main, + body > footer { display: grid; grid-template-columns: [page-start] minmax(1em, 1fr) [content] minmax(240px, 100ch) [page-end] minmax(1em, 1fr); } - .container > main { + body > main { grid-template-rows: [top-gutter] 1em [content] 1fr [bottom-gutter] 1em; } - .container > footer { + body > footer { grid-template-rows: [top-gutter] 2em [content] 1fr [bottom-gutter] 0.5em; } - .container > header { + body > header { grid-template-rows: [top-gutter] 0.5em [content] 1fr [bottom-gutter] 0.5em; } @@ -164,7 +164,7 @@ a:visited { .old-wrapper { /* used on non-home pages */ max-width: 500px; - margin: auto auto; + margin: 0 auto; } header .wrapper { diff --git a/ws/ws.go b/ws/ws.go index 6ac2f64f77843367d7f812b3b1cb2ba91cde51ef..1014dc3bdad9130cfb2ccdc5f17f68af4a900e58 100644 --- a/ws/ws.go +++ b/ws/ws.go @@ -52,17 +52,15 @@ func (h Handler) RootHandler(w http.ResponseWriter, r *http.Request) { return } - type stuff struct { + data := struct { Version string Projects []project.Project - } - - data := stuff{ + }{ Version: *h.Version, Projects: projectsWithReleases, } - tmpl := template.Must(template.ParseFS(fs, "static/home.html")) + tmpl := template.Must(template.ParseFS(fs, "static/dashboard.html.tmpl", "static/head.html.tmpl", "static/header.html.tmpl", "static/footer.html.tmpl")) if err := tmpl.Execute(w, data); err != nil { fmt.Println(err) } @@ -77,8 +75,9 @@ func (h Handler) NewHandler(w http.ResponseWriter, r *http.Request) { action := bmStrict.Sanitize(params.Get("action")) if r.Method == http.MethodGet { if action == "" { - tmpl := template.Must(template.ParseFS(fs, "static/new.html")) - if err := tmpl.Execute(w, nil); err != nil { + data := struct{ Version string }{Version: *h.Version} + tmpl := template.Must(template.ParseFS(fs, "static/new.html.tmpl", "static/head.html.tmpl", "static/header.html.tmpl", "static/footer.html.tmpl")) + if err := tmpl.Execute(w, data); err != nil { fmt.Println(err) } } else if action != "delete" { @@ -139,8 +138,16 @@ func (h Handler) NewHandler(w http.ResponseWriter, r *http.Request) { return } - tmpl := template.Must(template.ParseFS(fs, "static/select-release.html")) - if err := tmpl.Execute(w, proj); err != nil { + data := struct { + Version string + Project project.Project + }{ + Version: *h.Version, + Project: proj, + } + + tmpl := template.Must(template.ParseFS(fs, "static/select-release.html.tmpl", "static/head.html.tmpl", "static/header.html.tmpl", "static/footer.html.tmpl")) + if err := tmpl.Execute(w, data); err != nil { fmt.Println(err) } } else if action == "delete" { @@ -198,12 +205,13 @@ func (h Handler) LoginHandler(w http.ResponseWriter, r *http.Request) { return } - login, err := fs.ReadFile("static/login.html") - if err != nil { - fmt.Println("Error reading login.html:", err) + data := struct { + Version string + }{ + Version: *h.Version, } - - if _, err := io.WriteString(w, string(login)); err != nil { + tmpl := template.Must(template.ParseFS(fs, "static/login.html.tmpl", "static/head.html.tmpl", "static/footer.html.tmpl")) + if err := tmpl.Execute(w, data); err != nil { fmt.Println(err) } } @@ -318,7 +326,7 @@ func StaticHandler(writer http.ResponseWriter, request *http.Request) { if err != nil { fmt.Println(err) } - if _, err = io.WriteString(writer, string(home)); err != nil { + if _, err = io.Writer.Write(writer, home); err != nil { fmt.Println(err) } }