diff options
| author | grm <grm@eyesin.space> | 2026-09-17 16:42:15 +0300 |
|---|---|---|
| committer | grm <grm@eyesin.space> | 2026-09-17 16:42:15 +0300 |
| commit | d0601f06c080a8eb8d781fdd0e3338cd7ed42690 (patch) | |
| tree | 1931e4312ee2db15dfd0a99583c8ebadf0393e2b /internal/web/web_test.go | |
| parent | 4a6f987bf7f9d73e9dd33d225fd2d73e9bf69a88 (diff) | |
| download | blogspace-d0601f06c080a8eb8d781fdd0e3338cd7ed42690.tar.gz blogspace-d0601f06c080a8eb8d781fdd0e3338cd7ed42690.tar.bz2 blogspace-d0601f06c080a8eb8d781fdd0e3338cd7ed42690.zip | |
Add post summaries, featured images and a page outro
Recreating gizmolab.net as a blog showed three things the design system
could not express, all of them ordinary blog features:
- Listings can show a summary and a "Read more" link instead of the whole
post (theme.list_style). The summary is the source up to <!--more-->;
without the marker a Markdown post is cut at a block boundary after 70
words (never inside a code fence) and an HTML post is shown whole, since
cutting hand-written markup blind would leave tags open. Computed at
render time (Post.Excerpt/HasMore), nothing new is stored.
- A post can carry a featured image (posts.image, a library file that is
unset when the file is deleted): a thumbnail floated beside the entry on
listings, and on the post page above or below the text, or not at all,
as theme.post_image says. The picker is the design page's imagepick; its
library panel moves out of design.html into partials/imagelib.html so
both forms share it — which also removes a stale pickAction call the
design form's click handler would have hit.
- A page can have a closing text after its posts (pages.outro_md/html), in
the intro's format: the per-page counterpart of the blog-wide "after the
posts" module, for a home page that ends in a site map or a widget. The
editor partial takes formatof to share another editor's Format row, and
its upload field is now <name>_file so two editors fit in one form.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A
Diffstat (limited to 'internal/web/web_test.go')
| -rw-r--r-- | internal/web/web_test.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/internal/web/web_test.go b/internal/web/web_test.go index aa9b78e..a13697c 100644 --- a/internal/web/web_test.go +++ b/internal/web/web_test.go @@ -635,3 +635,48 @@ func TestNormalizeSection(t *testing.T) { t.Errorf("half-valid placement: %+v", sec) } } + +func TestPostSummary(t *testing.T) { + md := func(s string) *store.Post { + return &store.Post{Format: store.FormatMarkdown, BodyMD: s, BodyHTML: renderBody(store.FormatMarkdown, s)} + } + // the marker wins, whatever the length + p := md("first\n\n<!--more-->\n\nsecond") + if html, more := postSummary(p); !more || !strings.Contains(html, "first") || strings.Contains(html, "second") { + t.Errorf("marker: got %q, %v", html, more) + } + // short posts are shown whole + if html, more := postSummary(md("just a line")); more || html != p.BodyHTML && !strings.Contains(html, "just a line") { + t.Errorf("short: got %q, %v", html, more) + } + // a long one is cut at a block boundary after summaryWords words + long := strings.Repeat("word ", 50) + "\n\n" + strings.Repeat("word ", 50) + "\n\nlast block" + if html, more := postSummary(md(long)); !more || strings.Contains(html, "last block") || strings.Count(html, "word") != 100 { + t.Errorf("auto cut: got %d words, more=%v", strings.Count(html, "word"), more) + } + // never inside a code fence + fenced := "intro\n\n```\n" + strings.Repeat("code ", 80) + "\n\nstill code\n```\n\nafter" + if html, more := postSummary(md(fenced)); !more || !strings.Contains(html, "still code") || strings.Contains(html, "after") { + t.Errorf("fence: got %q, %v", html, more) + } + // HTML posts are only cut at the marker + h := &store.Post{Format: store.FormatHTML, BodyMD: "<div>" + strings.Repeat("w ", 200) + "</div>"} + h.BodyHTML = h.BodyMD + if html, more := postSummary(h); more || html != h.BodyHTML { + t.Errorf("html: cut without a marker") + } + h.BodyMD = "<p>a</p><!--more--><p>b</p>" + if html, more := postSummary(h); !more || html != "<p>a</p>" { + t.Errorf("html marker: got %q, %v", html, more) + } + // fillExcerpts follows the theme + posts := []store.Post{*md(long)} + fillExcerpts(Theme{ListStyle: "full"}, posts) + if posts[0].HasMore || posts[0].Excerpt != posts[0].BodyHTML { + t.Error("full: excerpt should be the whole body") + } + fillExcerpts(Theme{ListStyle: "summary"}, posts) + if !posts[0].HasMore { + t.Error("summary: expected a cut") + } +} |
