diff options
| author | grm <grm@eyesin.space> | 2026-09-18 11:22:25 +0300 |
|---|---|---|
| committer | grm <grm@eyesin.space> | 2026-09-18 11:22:25 +0300 |
| commit | ac125593efe689fabd1e48a7023249c8973698b8 (patch) | |
| tree | d7ee62adfd2260427383093ddf9956b2ef672598 /internal/web/handlers_blog.go | |
| parent | ad30b38759dc222a7137598559998acbd0c06740 (diff) | |
| download | blogspace-ac125593efe689fabd1e48a7023249c8973698b8.tar.gz blogspace-ac125593efe689fabd1e48a7023249c8973698b8.tar.bz2 blogspace-ac125593efe689fabd1e48a7023249c8973698b8.zip | |
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A
Diffstat (limited to 'internal/web/handlers_blog.go')
| -rw-r--r-- | internal/web/handlers_blog.go | 12 |
1 files changed, 12 insertions, 0 deletions
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) } |
