dashboard / erock/git-pr / restructure web assets #72 rss

open · opened on 2025-08-11T12:17:33Z by jolheiser
Help
checkout latest patchset:
ssh pr.pico.sh print pr-72 | git am -3
checkout any patchset in a patch request:
ssh pr.pico.sh print ps-X | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 72
add review to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add --review 72
accept PR:
ssh pr.pico.sh pr accept 72
close PR:
ssh pr.pico.sh pr close 72

Logs

jolheiser created pr with ps-143 on 2025-08-11T12:17:33Z

Patchsets

ps-143 by jolheiser on 2025-08-11T12:17:33Z

restructure web assets

- Move component (non-page) assets into a components sub-directory
  - This makes parsing all of them simpler without needing to add to the list in-code
- Move pages into their own subdirectory
  - Allows simplifying their name and distinguishes which files are the "actual" pages
- Move parsing to vars
  - Cleans up some overhead by not having to parse the templates on *every* page load while also simplifying the callsite

Signed-off-by: jolheiser <git@jolheiser.com>
tmpl/components/patchset.html link
+0 -0
1
2
3
4
diff --git a/tmpl/patchset.html b/tmpl/components/patchset.html
similarity index 100%
rename from tmpl/patchset.html
rename to tmpl/components/patchset.html
tmpl/components/pr-header.html link
+0 -0
1
2
3
4
diff --git a/tmpl/pr-header.html b/tmpl/components/pr-header.html
similarity index 100%
rename from tmpl/pr-header.html
rename to tmpl/components/pr-header.html
tmpl/components/pr-list-item.html link
+0 -0
1
2
3
4
diff --git a/tmpl/pr-list-item.html b/tmpl/components/pr-list-item.html
similarity index 100%
rename from tmpl/pr-list-item.html
rename to tmpl/components/pr-list-item.html
tmpl/components/pr-status.html link
+0 -0
1
2
3
4
diff --git a/tmpl/pr-status.html b/tmpl/components/pr-status.html
similarity index 100%
rename from tmpl/pr-status.html
rename to tmpl/components/pr-status.html
tmpl/components/pr-table.html link
+0 -0
1
2
3
4
diff --git a/tmpl/pr-table.html b/tmpl/components/pr-table.html
similarity index 100%
rename from tmpl/pr-table.html
rename to tmpl/components/pr-table.html
tmpl/components/range-diff.html link
+0 -0
1
2
3
4
diff --git a/tmpl/range-diff.html b/tmpl/components/range-diff.html
similarity index 100%
rename from tmpl/range-diff.html
rename to tmpl/components/range-diff.html
tmpl/components/user-pill.html link
+0 -0
1
2
3
4
diff --git a/tmpl/user-pill.html b/tmpl/components/user-pill.html
similarity index 100%
rename from tmpl/user-pill.html
rename to tmpl/components/user-pill.html
tmpl/pages/index.html link
+0 -0
1
2
3
4
diff --git a/tmpl/index.html b/tmpl/pages/index.html
similarity index 100%
rename from tmpl/index.html
rename to tmpl/pages/index.html
tmpl/pages/pr.html link
+0 -0
1
2
3
4
diff --git a/tmpl/pr-detail.html b/tmpl/pages/pr.html
similarity index 100%
rename from tmpl/pr-detail.html
rename to tmpl/pages/pr.html
tmpl/pages/repo.html link
+0 -0
1
2
3
4
diff --git a/tmpl/repo-detail.html b/tmpl/pages/repo.html
similarity index 100%
rename from tmpl/repo-detail.html
rename to tmpl/pages/repo.html
tmpl/pages/user.html link
+0 -0
1
2
3
4
diff --git a/tmpl/user-detail.html b/tmpl/pages/user.html
similarity index 100%
rename from tmpl/user-detail.html
rename to tmpl/pages/user.html
web.go link
+27 -31
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
diff --git a/web.go b/web.go
index a6da13b..468847c 100644
--- a/web.go
+++ b/web.go
@@ -27,8 +27,29 @@ import (
 	"github.com/gorilla/feeds"
 )
 
-//go:embed tmpl/*
-var tmplFS embed.FS
+var (
+	//go:embed tmpl/*
+	tmplFS    embed.FS
+	indexTmpl = getTemplate("index.html")
+	prTmpl    = getTemplate("pr.html")
+	userTmpl  = getTemplate("user.html")
+	repoTmpl  = getTemplate("repo.html")
+)
+
+func getTemplate(page string) *template.Template {
+	tmpl, err := template.New("").Funcs(template.FuncMap{
+		"sha": shaFn,
+	}).ParseFS(
+		tmplFS,
+		filepath.Join("tmpl", "pages", page),
+		filepath.Join("tmpl", "components", "*.html"),
+		filepath.Join("tmpl", "base.html"),
+	)
+	if err != nil {
+		panic(err)
+	}
+	return tmpl.Lookup(page)
+}
 
 //go:embed static/*
 var embedStaticFS embed.FS
@@ -83,27 +104,6 @@ func shaFn(sha string) string {
 	return truncateSha(sha)
 }
 
-func getTemplate(file string) *template.Template {
-	tmpl, err := template.New("").Funcs(template.FuncMap{
-		"sha": shaFn,
-	}).ParseFS(
-		tmplFS,
-		filepath.Join("tmpl", file),
-		filepath.Join("tmpl", "user-pill.html"),
-		filepath.Join("tmpl", "patchset.html"),
-		filepath.Join("tmpl", "range-diff.html"),
-		filepath.Join("tmpl", "pr-header.html"),
-		filepath.Join("tmpl", "pr-list-item.html"),
-		filepath.Join("tmpl", "pr-table.html"),
-		filepath.Join("tmpl", "pr-status.html"),
-		filepath.Join("tmpl", "base.html"),
-	)
-	if err != nil {
-		panic(err)
-	}
-	return tmpl
-}
-
 type LinkData struct {
 	Url  template.URL
 	Text string
@@ -323,8 +323,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
 	}
 
 	w.Header().Set("content-type", "text/html")
-	tmpl := getTemplate("index.html")
-	err = tmpl.ExecuteTemplate(w, "index.html", PrTableData{
+	err = indexTmpl.Execute(w, PrTableData{
 		NumOpen:     numOpen,
 		NumAccepted: numAccepted,
 		NumClosed:   numClosed,
@@ -422,8 +421,7 @@ func userDetailHandler(w http.ResponseWriter, r *http.Request) {
 	}
 
 	w.Header().Set("content-type", "text/html")
-	tmpl := getTemplate("user-detail.html")
-	err = tmpl.ExecuteTemplate(w, "user-detail.html", UserDetailData{
+	err = userTmpl.Execute(w, UserDetailData{
 		Prs:         prdata,
 		NumOpen:     numOpen,
 		NumAccepted: numAccepted,
@@ -498,8 +496,7 @@ func repoDetailHandler(w http.ResponseWriter, r *http.Request) {
 	}
 
 	w.Header().Set("content-type", "text/html")
-	tmpl := getTemplate("repo-detail.html")
-	err = tmpl.ExecuteTemplate(w, "repo-detail.html", RepoDetailData{
+	err = repoTmpl.Execute(w, RepoDetailData{
 		Name:        repo.Name,
 		UserID:      user.ID,
 		Username:    userName,
@@ -772,7 +769,6 @@ func createPrDetail(page string) http.HandlerFunc {
 		}
 
 		w.Header().Set("content-type", "text/html")
-		tmpl := getTemplate("pr-detail.html")
 		pk, err := web.Backend.PubkeyToPublicKey(user.Pubkey)
 		if err != nil {
 			web.Logger.Error("cannot parse pubkey for pr user", "err", err)
@@ -840,7 +836,7 @@ func createPrDetail(page string) http.HandlerFunc {
 
 		repoNs := web.Backend.CreateRepoNs(repoOwner.Name, repo.Name)
 		url := fmt.Sprintf("/r/%s/%s", repoOwner.Name, repo.Name)
-		err = tmpl.ExecuteTemplate(w, "pr-detail.html", PrDetailData{
+		err = prTmpl.Execute(w, PrDetailData{
 			Page: "pr",
 			Repo: LinkData{
 				Url:  template.URL(url),