Skip to content

Commit 954f8f5

Browse files
committed
web: add per-project nav HTML support
Add a nav_html column to the project table so that each project can display custom HTML elements in the navigation bar. The per-project HTML is rendered after the global nav HTML when viewing project-scoped pages (patch list, patch detail, cover detail, bundles, todo, project detail). Introduce a projectPageCtx() helper that wraps pageCtx() and sets the project-specific nav HTML, keeping the change minimal across handlers. Signed-off-by: Robin Jarry <robin@jarry.cc>
1 parent e370b09 commit 954f8f5

9 files changed

Lines changed: 24 additions & 12 deletions

File tree

‎pkg/db/migrations/0001_initial_schema.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ type project0001 struct {
8888
UseTags bool `bun:"use_tags,notnull"`
8989
ShowDependencies bool `bun:"show_dependencies,notnull"`
9090
AutoSupersede bool `bun:"auto_supersede,notnull"`
91+
NavHTML string `bun:"nav_html"`
9192
}
9293

9394
type projectMaintainer0001 struct {

‎pkg/db/models.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ type Project struct {
9191
UseTags bool `bun:"use_tags,notnull" json:"-"`
9292
ShowDependencies bool `bun:"show_dependencies,notnull" json:"show_dependencies,omitempty"`
9393
AutoSupersede bool `bun:"auto_supersede,notnull" json:"-"`
94+
NavHTML string `bun:"nav_html" json:"-"`
9495

9596
APIURL string `bun:"-" json:"url,omitempty"`
9697
Maintainers []User `bun:"-" json:"maintainers"`

‎pkg/web/bundles.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ func (h *webHandler) BundleList(w http.ResponseWriter, r *http.Request) {
4545
func (h *webHandler) ProjectBundleList(w http.ResponseWriter, r *http.Request) {
4646
ctx := r.Context()
4747
q := db.GetQueries(ctx)
48-
pc := h.pageCtx(r)
4948
linkname := chi.URLParam(r, "linkname")
5049

5150
project, err := q.GetProjectByLinkname(linkname)
5251
if err != nil {
5352
notFoundPage(w)
5453
return
5554
}
55+
pc := h.projectPageCtx(r, project)
5656

5757
sq := q.DB.NewSelect().Model((*db.Bundle)(nil)).
5858
ColumnExpr("*, (SELECT count(*) FROM bundle_patch WHERE bundle_id = bundle.id) AS patch_count").

‎pkg/web/covers.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (h *webHandler) CoverDetailPage(w http.ResponseWriter, r *http.Request) {
7777
comments, _ := q.ListCoverComments(cover.ID)
7878

7979
data := coverDetailData{
80-
PC: h.pageCtx(r),
80+
PC: h.projectPageCtx(r, project),
8181
Project: *project,
8282
Cover: cover,
8383
Comments: comments,

‎pkg/web/layout.templ‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ type breadcrumb struct {
1313
}
1414

1515
type pageContext struct {
16-
User *db.User
17-
CSRFToken string
18-
Version string
19-
CustomCSS bool
20-
NavHTML string
21-
FooterHTML string
16+
User *db.User
17+
CSRFToken string
18+
Version string
19+
CustomCSS bool
20+
NavHTML string
21+
ProjectNavHTML string
22+
FooterHTML string
2223
}
2324

2425
templ layout(title string, crumbs []breadcrumb, pc pageContext) {
@@ -65,6 +66,9 @@ templ layout(title string, crumbs []breadcrumb, pc pageContext) {
6566
if pc.NavHTML != "" {
6667
@templ.Raw(pc.NavHTML)
6768
}
69+
if pc.ProjectNavHTML != "" {
70+
@templ.Raw(pc.ProjectNavHTML)
71+
}
6872
</header>
6973
<main>
7074
{ children... }

‎pkg/web/patches.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (h *webHandler) PatchList(w http.ResponseWriter, r *http.Request) {
119119
delegates, _ := q.ListProjectMaintainers(project.ID)
120120

121121
data := patchListData{
122-
PC: h.pageCtx(r),
122+
PC: h.projectPageCtx(r, project),
123123
Project: *project,
124124
Patches: patches,
125125
Filters: filters,
@@ -391,7 +391,7 @@ func (h *webHandler) PatchDetailPage(w http.ResponseWriter, r *http.Request) {
391391
}
392392

393393
data := patchDetailData{
394-
PC: h.pageCtx(r),
394+
PC: h.projectPageCtx(r, project),
395395
Project: *project,
396396
Patch: patch,
397397
Comments: comments,

‎pkg/web/projects.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ func (h *webHandler) ProjectDetail(w http.ResponseWriter, r *http.Request) {
4646
Where("archived = ?", false).
4747
Count(q.Ctx)
4848

49-
projectDetailPage(h.pageCtx(r), *project, maintainers, nPatches).Render(ctx, w)
49+
projectDetailPage(h.projectPageCtx(r, project), *project, maintainers, nPatches).Render(ctx, w)
5050
}

‎pkg/web/todo.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ func (h *webHandler) todoList(w http.ResponseWriter, r *http.Request) {
5959
ctx := r.Context()
6060
q := db.GetQueries(ctx)
6161
user := getWebUser(r)
62-
pc := h.pageCtx(r)
6362
linkname := chi.URLParam(r, "linkname")
6463

6564
project, err := q.GetProjectByLinkname(linkname)
6665
if err != nil {
6766
notFoundPage(w)
6867
return
6968
}
69+
pc := h.projectPageCtx(r, project)
7070

7171
var patches []db.Patch
7272
q.DB.NewSelect().Model(&patches).

‎pkg/web/web.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,12 @@ func (h *webHandler) pageCtx(r *http.Request) pageContext {
294294
}
295295
}
296296

297+
func (h *webHandler) projectPageCtx(r *http.Request, p *db.Project) pageContext {
298+
pc := h.pageCtx(r)
299+
pc.ProjectNavHTML = p.NavHTML
300+
return pc
301+
}
302+
297303
func notFoundPage(w http.ResponseWriter) {
298304
w.WriteHeader(http.StatusNotFound)
299305
_, _ = w.Write([]byte("Not found"))

0 commit comments

Comments
 (0)