diff options
| author | grm <grm@eyesin.space> | 2026-09-15 23:12:51 +0300 |
|---|---|---|
| committer | grm <grm@eyesin.space> | 2026-09-15 23:12:51 +0300 |
| commit | 2c85ca1a46ddf4652f8fffc53d6bcfbe32b2b4ff (patch) | |
| tree | ecd5efd574b7d7463e4b2c4361c1994c4f28f561 /internal/slug | |
| parent | 55732bdfc25933bab26220ccd82fe5e172d9e673 (diff) | |
| download | blogspace-2c85ca1a46ddf4652f8fffc53d6bcfbe32b2b4ff.tar.gz blogspace-2c85ca1a46ddf4652f8fffc53d6bcfbe32b2b4ff.tar.bz2 blogspace-2c85ca1a46ddf4652f8fffc53d6bcfbe32b2b4ff.zip | |
Add post tags, with a tag page and two side-column modules
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/<slug>,
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A
Diffstat (limited to 'internal/slug')
| -rw-r--r-- | internal/slug/slug.go | 12 | ||||
| -rw-r--r-- | internal/slug/slug_test.go | 9 |
2 files changed, 18 insertions, 3 deletions
diff --git a/internal/slug/slug.go b/internal/slug/slug.go index a3c99a4..197160c 100644 --- a/internal/slug/slug.go +++ b/internal/slug/slug.go @@ -27,6 +27,15 @@ var greek = strings.NewReplacer( // Make returns a slug for s; falls back to "untitled" when nothing usable remains. func Make(s string) string { + if s = Clean(s); s == "" { + return "untitled" + } + return s +} + +// Clean is Make without the fallback: "" when nothing usable remains, so a +// caller can reject the input (a tag) rather than name it "untitled". +func Clean(s string) string { if t, _, err := transform.String(stripMarks, s); err == nil { s = t } @@ -36,9 +45,6 @@ func Make(s string) string { if len(s) > 80 { s = strings.Trim(s[:80], "-") } - if s == "" { - return "untitled" - } return s } diff --git a/internal/slug/slug_test.go b/internal/slug/slug_test.go index 9953f34..59e2a75 100644 --- a/internal/slug/slug_test.go +++ b/internal/slug/slug_test.go @@ -20,6 +20,15 @@ func TestMake(t *testing.T) { } } +func TestClean(t *testing.T) { + cases := map[string]string{"!!!": "", "": "", "Ντομάτες": "ntomates", "Go ": "go"} + for in, want := range cases { + if got := Clean(in); got != want { + t.Errorf("Clean(%q) = %q, want %q", in, got, want) + } + } +} + func TestValid(t *testing.T) { for _, ok := range []string{"a", "abc-def", "a1-b2"} { if !Valid(ok) { |
