From ac125593efe689fabd1e48a7023249c8973698b8 Mon Sep 17 00:00:00 2001 From: grm Date: Fri, 18 Sep 2026 11:22:25 +0300 Subject: Add switches to keep announcements off a page or off post pages Announcements showed on every public page. Now each page has a "Show announcements on this page" checkbox (pages.show_notices, on by default) that covers the page and its posts, and the Design tab's Content section has "Show announcements on post pages" (theme.post_notices, on by default) for bloggers who want notices only on listings, not while reading a post. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A --- internal/web/handlers_blog.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'internal/web/handlers_blog.go') diff --git a/internal/web/handlers_blog.go b/internal/web/handlers_blog.go index c26adfa..c1afedb 100644 --- a/internal/web/handlers_blog.go +++ b/internal/web/handlers_blog.go @@ -63,6 +63,10 @@ func (s *Server) blogView(r *http.Request) (map[string]any, error) { return v, nil } +// noNotices stands in for the placed announcements on pages that hide them +// (typed, so the layout's index lookups still work). +var noNotices = map[string][]store.Section{} + // pageNum reads the ?p= of a paginated listing (1 when absent or silly). func pageNum(r *http.Request) int { n, _ := strconv.Atoi(r.URL.Query().Get("p")) @@ -109,6 +113,9 @@ func (s *Server) renderPage(w http.ResponseWriter, r *http.Request, page *store. last := (total + per - 1) / per fillExcerpts(v["theme"].(Theme), posts) v["page"], v["posts"], v["pageNum"], v["lastPage"] = page, posts, n, last + if !page.ShowNotices { + v["notices"] = noNotices + } // The pager appends ?p=N to base: no trailing slash, which /{page} would not match. v["base"] = "/" + page.Slug if page.IsHome { @@ -195,6 +202,11 @@ func (s *Server) handleBlogPost(w http.ResponseWriter, r *http.Request) { return } v["page"], v["post"] = page, post + // A post shows the announcements only when its page does and the theme + // wants them on posts at all. + if !page.ShowNotices || !v["theme"].(Theme).PostNotices { + v["notices"] = noNotices + } s.render(w, r, "blog/post.html", v) } -- cgit v1.2.3