From 2c85ca1a46ddf4652f8fffc53d6bcfbe32b2b4ff Mon Sep 17 00:00:00 2001 From: grm Date: Tue, 15 Sep 2026 23:12:51 +0300 Subject: Add post tags, with a tag page and two side-column modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Posts can now carry tags, set on the post form as a checklist of the blog's existing tags plus a comma-separated box for new ones (no JS). A tag is a name and a unique slug, so "Go" and "go" are one tag and Greek tags get readable URLs; tags no post uses any more are deleted. On the blog, tags appear under the post date and link to /tag/, which lists the published posts from every page, paginated like a page. Two new layout modules show them: a Tags list (with counts, by use) and a Tag cloud (alphabetical, sized by use). Both are only fetched when a visible module needs them. The article loop and pager move to a shared postlist partial; while there, the pager stops adding a trailing slash — /news/?p=2 was a 404 because a {page} wildcard never matches one. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A --- internal/web/templates/blog/page.html | 15 +-------------- internal/web/templates/blog/post.html | 1 + internal/web/templates/blog/tag.html | 5 +++++ internal/web/templates/dashboard/module_form.html | 9 +++++++-- internal/web/templates/dashboard/post_form.html | 5 +++++ internal/web/templates/dashboard/posts.html | 2 +- internal/web/templates/layouts/blog.html | 6 ++++++ internal/web/templates/partials/postlist.html | 22 ++++++++++++++++++++++ 8 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 internal/web/templates/blog/tag.html create mode 100644 internal/web/templates/partials/postlist.html (limited to 'internal/web/templates') diff --git a/internal/web/templates/blog/page.html b/internal/web/templates/blog/page.html index ac6a609..99403ef 100644 --- a/internal/web/templates/blog/page.html +++ b/internal/web/templates/blog/page.html @@ -2,18 +2,5 @@ {{define "content"}} {{if not .Data.page.IsHome}}

{{.Data.page.Title}}

{{end}} {{if .Data.page.IntroHTML}}
{{html .Data.page.IntroHTML}}
{{end}} -{{range .Data.posts}} -
-

{{.Title}}

- {{if $.Data.theme.ShowDates}}{{end}} -
{{html .BodyHTML}}
-
-{{else}}{{if not .Data.page.IntroHTML}}

{{t "Nothing here yet."}}

{{end}}{{end}} -{{if gt .Data.lastPage 1}} -
- {{if gt .Data.pageNum 1}}← {{t "Newer"}}{{end}} - {{tf "Page %d of %d" .Data.pageNum .Data.lastPage}} - {{if lt .Data.pageNum .Data.lastPage}}{{t "Older"}} →{{end}} -
-{{end}} +{{if or .Data.posts .Data.page.IntroHTML}}{{template "postlist" .}}{{else}}

{{t "Nothing here yet."}}

{{end}} {{end}} diff --git a/internal/web/templates/blog/post.html b/internal/web/templates/blog/post.html index d14f22a..a3b0375 100644 --- a/internal/web/templates/blog/post.html +++ b/internal/web/templates/blog/post.html @@ -3,6 +3,7 @@

{{.Data.post.Title}}

+ {{template "posttags" .Data.post.Tags}}
{{html .Data.post.BodyHTML}}
{{end}} diff --git a/internal/web/templates/blog/tag.html b/internal/web/templates/blog/tag.html new file mode 100644 index 0000000..fd3aa13 --- /dev/null +++ b/internal/web/templates/blog/tag.html @@ -0,0 +1,5 @@ +{{define "title"}}{{tf "Tagged “%s”" .Data.tag.Name}} · {{.Blog.Title}}{{end}} +{{define "content"}} +

{{tf "Tagged “%s”" .Data.tag.Name}}

+{{template "postlist" .}} +{{end}} diff --git a/internal/web/templates/dashboard/module_form.html b/internal/web/templates/dashboard/module_form.html index 0cd27fa..8b28f2e 100644 --- a/internal/web/templates/dashboard/module_form.html +++ b/internal/web/templates/dashboard/module_form.html @@ -5,8 +5,8 @@

{{.Data.name}} {{tf "in the %s" (lower .Data.area)}}

- {{if or (eq $m.Kind "recent") (eq $m.Kind "archive") (eq $m.Kind "sitemap") (and (eq $m.Kind "html") (or (eq $m.Area "left") (eq $m.Area "right") (eq $m.Area "footer")))}} - + {{if or (eq $m.Kind "recent") (eq $m.Kind "archive") (eq $m.Kind "sitemap") (eq $m.Kind "tags") (eq $m.Kind "tagcloud") (and (eq $m.Kind "html") (or (eq $m.Area "left") (eq $m.Area "right") (eq $m.Area "footer")))}} + {{end}} {{if eq $m.Kind "recent"}}
@@ -15,6 +15,11 @@

{{t "Every published post grouped by year and month, newest first. Years and months fold open and shut; the latest year starts open."}}

{{else if eq $m.Kind "sitemap"}}

{{t "Links to every page of your blog."}}

+ {{else if eq $m.Kind "tags"}} +
+

{{t "Your tags with the number of posts in each, most used first. Only published posts count."}}

+ {{else if eq $m.Kind "tagcloud"}} +

{{t "Every tag in alphabetical order, bigger the more posts use it."}}

{{else if eq $m.Kind "html"}} diff --git a/internal/web/templates/dashboard/post_form.html b/internal/web/templates/dashboard/post_form.html index 9f188f7..fd47615 100644 --- a/internal/web/templates/dashboard/post_form.html +++ b/internal/web/templates/dashboard/post_form.html @@ -14,6 +14,11 @@ + {{if .Data.allTags}}

{{t "Tags"}}

+
{{range .Data.allTags}}{{end}}
{{end}} + +

{{t "Tags on hidden posts are not shown on the blog; a tag nobody uses disappears."}}

{{template "editor" (dict "name" "body" "value" .Data.post.BodyMD "rows" 24 "tall" true "upload" (print "/b/" .Blog.Subdomain "/files/upload") "preview" (print "/b/" .Blog.Subdomain "/preview") "csrf" .CSRF)}} diff --git a/internal/web/templates/dashboard/posts.html b/internal/web/templates/dashboard/posts.html index 3a99a31..983fbae 100644 --- a/internal/web/templates/dashboard/posts.html +++ b/internal/web/templates/dashboard/posts.html @@ -17,7 +17,7 @@ {{range .Data.posts}} - + diff --git a/internal/web/templates/layouts/blog.html b/internal/web/templates/layouts/blog.html index f73f729..cf00272 100644 --- a/internal/web/templates/layouts/blog.html +++ b/internal/web/templates/layouts/blog.html @@ -70,6 +70,12 @@ {{end}} {{else}}

{{t "No posts yet."}}

{{end}} +{{- else if eq $m.Kind "tags"}}
{{template "modtitle" $m}} +
    {{range $i, $t := $r.Data.tags}}{{if or (eq $m.Count 0) (lt $i $m.Count)}}
  • {{$t.Name}} ({{$t.Count}})
  • {{end}}{{else}}
  • {{t "No tags yet."}}
  • {{end}}
+
+{{- else if eq $m.Kind "tagcloud"}}
{{template "modtitle" $m}} +

{{range $r.Data.tagcloud}}{{.Name}} {{else}}{{t "No tags yet."}}{{end}}

+
{{- else if eq $m.Kind "html"}}{{if not $m.Body}}{{else if or (eq $m.Area "above") (eq $m.Area "below")}}
{{html $m.Body}}
{{else}}
{{template "modtitle" $m}}{{html $m.Body}}
{{end}} {{- else if eq $m.Kind "rss"}}

{{t "RSS feed"}}

diff --git a/internal/web/templates/partials/postlist.html b/internal/web/templates/partials/postlist.html new file mode 100644 index 0000000..01e1037 --- /dev/null +++ b/internal/web/templates/partials/postlist.html @@ -0,0 +1,22 @@ +{{/* The article list and pager shared by a page and a tag listing. Expects + .Data.posts, .Data.pageNum, .Data.lastPage and .Data.base (the listing's + own path, which ?p=N is appended to). */}} +{{define "postlist"}} +{{range .Data.posts}} +
+

{{.Title}}

+ {{if $.Data.theme.ShowDates}}{{end}} + {{template "posttags" .Tags}} +
{{html .BodyHTML}}
+
+{{end}} +{{if gt .Data.lastPage 1}} +
+ {{if gt .Data.pageNum 1}}← {{t "Newer"}}{{end}} + {{tf "Page %d of %d" .Data.pageNum .Data.lastPage}} + {{if lt .Data.pageNum .Data.lastPage}}{{t "Older"}} →{{end}} +
+{{end}} +{{end}} + +{{define "posttags"}}{{if .}}{{end}}{{end}} -- cgit v1.2.3
{{t "Title"}}{{t "Page"}}{{t "Date"}}
{{.Title}}{{if not .Published}} {{t "hidden"}}{{end}}{{.Title}}{{if not .Published}} {{t "hidden"}}{{end}}{{if .Tags}}
{{range $i, $t := .Tags}}{{if $i}}, {{end}}{{$t.Name}}{{end}}
{{end}}
{{.PageTitle}} {{date .CreatedAt}} {{t "view"}} ↗ · {{t "delete"}}