git-pr
created pr with
72.1
added 72.2
-: ------- > 1: 9b6aea8 lgtm
1: 5dafb29 = 2: 9b6aea8 restructure web assets
cmds
checkout latest patchset:
ssh pr.pico.sh print 72 | git am -3checkout any patchset in a patch request:
ssh pr.pico.sh print 72.[rev] | git am -3add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 72
Patchset
72.2
restructure web assets
jolheiser
2025-08-11T12:12:40Z- 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>
Semantic diff summary
1 added,
4 modified,
0 signature changed,
0 removed
across 1 analyzed file
(11 files skipped: unsupported file type)
+0
-0
tmpl/components/patchset.html
#
+0
-0
tmpl/components/pr-header.html
#
+0
-0
tmpl/components/pr-list-item.html
#
+0
-0
tmpl/components/pr-status.html
#
+0
-0
tmpl/components/pr-table.html
#
+0
-0
tmpl/components/range-diff.html
#
+0
-0
tmpl/components/user-pill.html
#
+0
-0
tmpl/pages/index.html
#
+0
-0
tmpl/pages/pr.html
#
+0
-0
tmpl/pages/repo.html
#
+0
-0
tmpl/pages/user.html
#
+27
-31
web.go
#
| ... | ... | @@ -27,8 +27,29 @@ import ( | |
| 27 | 27 | "github.com/gorilla/feeds" | |
| 28 | 28 | ) | |
| 29 | 29 | ||
| 30 | - | //go:embed tmpl/* | |
| 31 | - | var tmplFS embed.FS | |
| 30 | + | var ( | |
| 31 | + | //go:embed tmpl/* | |
| 32 | + | tmplFS embed.FS | |
| 33 | + | indexTmpl = getTemplate("index.html") | |
| 34 | + | prTmpl = getTemplate("pr.html") | |
| 35 | + | userTmpl = getTemplate("user.html") | |
| 36 | + | repoTmpl = getTemplate("repo.html") | |
| 37 | + | ) | |
| 38 | + | ||
| 39 | + | func getTemplate(page string) *template.Template { | |
| 40 | + | tmpl, err := template.New("").Funcs(template.FuncMap{ | |
| 41 | + | "sha": shaFn, | |
| 42 | + | }).ParseFS( | |
| 43 | + | tmplFS, | |
| 44 | + | filepath.Join("tmpl", "pages", page), | |
| 45 | + | filepath.Join("tmpl", "components", "*.html"), | |
| 46 | + | filepath.Join("tmpl", "base.html"), | |
| 47 | + | ) | |
| 48 | + | if err != nil { | |
| 49 | + | panic(err) | |
| 50 | + | } | |
| 51 | + | return tmpl.Lookup(page) | |
| 52 | + | } | |
| 32 | 53 | ||
| 33 | 54 | //go:embed static/* | |
| 34 | 55 | var embedStaticFS embed.FS |
| ... | ... | @@ -83,27 +104,6 @@ func shaFn(sha string) string { | |
| 83 | 104 | return truncateSha(sha) | |
| 84 | 105 | } | |
| 85 | 106 | ||
| 86 | - | func getTemplate(file string) *template.Template { | |
| 87 | - | tmpl, err := template.New("").Funcs(template.FuncMap{ | |
| 88 | - | "sha": shaFn, | |
| 89 | - | }).ParseFS( | |
| 90 | - | tmplFS, | |
| 91 | - | filepath.Join("tmpl", file), | |
| 92 | - | filepath.Join("tmpl", "user-pill.html"), | |
| 93 | - | filepath.Join("tmpl", "patchset.html"), | |
| 94 | - | filepath.Join("tmpl", "range-diff.html"), | |
| 95 | - | filepath.Join("tmpl", "pr-header.html"), | |
| 96 | - | filepath.Join("tmpl", "pr-list-item.html"), | |
| 97 | - | filepath.Join("tmpl", "pr-table.html"), | |
| 98 | - | filepath.Join("tmpl", "pr-status.html"), | |
| 99 | - | filepath.Join("tmpl", "base.html"), | |
| 100 | - | ) | |
| 101 | - | if err != nil { | |
| 102 | - | panic(err) | |
| 103 | - | } | |
| 104 | - | return tmpl | |
| 105 | - | } | |
| 106 | - | ||
| 107 | 107 | type LinkData struct { | |
| 108 | 108 | Url template.URL | |
| 109 | 109 | Text string |
| ... | ... | @@ -323,8 +323,7 @@ func indexHandler(w http.ResponseWriter, r *http.Request) { | |
| 323 | 323 | } | |
| 324 | 324 | ||
| 325 | 325 | w.Header().Set("content-type", "text/html") | |
| 326 | - | tmpl := getTemplate("index.html") | |
| 327 | - | err = tmpl.ExecuteTemplate(w, "index.html", PrTableData{ | |
| 326 | + | err = indexTmpl.Execute(w, PrTableData{ | |
| 328 | 327 | NumOpen: numOpen, | |
| 329 | 328 | NumAccepted: numAccepted, | |
| 330 | 329 | NumClosed: numClosed, |
| ... | ... | @@ -422,8 +421,7 @@ func userDetailHandler(w http.ResponseWriter, r *http.Request) { | |
| 422 | 421 | } | |
| 423 | 422 | ||
| 424 | 423 | w.Header().Set("content-type", "text/html") | |
| 425 | - | tmpl := getTemplate("user-detail.html") | |
| 426 | - | err = tmpl.ExecuteTemplate(w, "user-detail.html", UserDetailData{ | |
| 424 | + | err = userTmpl.Execute(w, UserDetailData{ | |
| 427 | 425 | Prs: prdata, | |
| 428 | 426 | NumOpen: numOpen, | |
| 429 | 427 | NumAccepted: numAccepted, |
| ... | ... | @@ -498,8 +496,7 @@ func repoDetailHandler(w http.ResponseWriter, r *http.Request) { | |
| 498 | 496 | } | |
| 499 | 497 | ||
| 500 | 498 | w.Header().Set("content-type", "text/html") | |
| 501 | - | tmpl := getTemplate("repo-detail.html") | |
| 502 | - | err = tmpl.ExecuteTemplate(w, "repo-detail.html", RepoDetailData{ | |
| 499 | + | err = repoTmpl.Execute(w, RepoDetailData{ | |
| 503 | 500 | Name: repo.Name, | |
| 504 | 501 | UserID: user.ID, | |
| 505 | 502 | Username: userName, |
| ... | ... | @@ -772,7 +769,6 @@ func createPrDetail(page string) http.HandlerFunc { | |
| 772 | 769 | } | |
| 773 | 770 | ||
| 774 | 771 | w.Header().Set("content-type", "text/html") | |
| 775 | - | tmpl := getTemplate("pr-detail.html") | |
| 776 | 772 | pk, err := web.Backend.PubkeyToPublicKey(user.Pubkey) | |
| 777 | 773 | if err != nil { | |
| 778 | 774 | web.Logger.Error("cannot parse pubkey for pr user", "err", err) |
| ... | ... | @@ -840,7 +836,7 @@ func createPrDetail(page string) http.HandlerFunc { | |
| 840 | 836 | ||
| 841 | 837 | repoNs := web.Backend.CreateRepoNs(repoOwner.Name, repo.Name) | |
| 842 | 838 | url := fmt.Sprintf("/r/%s/%s", repoOwner.Name, repo.Name) | |
| 843 | - | err = tmpl.ExecuteTemplate(w, "pr-detail.html", PrDetailData{ | |
| 839 | + | err = prTmpl.Execute(w, PrDetailData{ | |
| 844 | 840 | Page: "pr", | |
| 845 | 841 | Repo: LinkData{ | |
| 846 | 842 | Url: template.URL(url), |