diff options
| author | grm <grm@eyesin.space> | 2026-09-16 00:00:57 +0300 |
|---|---|---|
| committer | grm <grm@eyesin.space> | 2026-09-16 00:00:57 +0300 |
| commit | 839343a3108734a15e331b542a20ed9c77ef582b (patch) | |
| tree | a6aabc8719c16398bf1ccd874a7efe865b364a9e /internal/web/templates/layouts | |
| parent | 628dcb814ece6335667e2b719049728aa161d8c9 (diff) | |
| download | blogspace-839343a3108734a15e331b542a20ed9c77ef582b.tar.gz blogspace-839343a3108734a15e331b542a20ed9c77ef582b.tar.bz2 blogspace-839343a3108734a15e331b542a20ed9c77ef582b.zip | |
Add a search box module and a search page
Readers had no way to find a post. The new "search" module goes in the
header (a bar under the nav) or a side column (a box with a heading) and
is a plain GET form to /search, so it works without JavaScript. The
results page lists the published posts of every page whose title or
Markdown body matches the query — case-insensitive, each word literal,
spaces meaning "anything in between", in order — as title, date and a
short snippet with the match marked, 20 per page.
modules.kind is a CHECK constraint, so a migration widens it; "search"
becomes a reserved page slug so the literal route keeps winning over
/{page}. moduleHasSettings now takes the module: a header search box
has no heading, hence nothing to edit.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sd8UPWrvyYCLj97JexNw3A
Diffstat (limited to 'internal/web/templates/layouts')
| -rw-r--r-- | internal/web/templates/layouts/blog.html | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/internal/web/templates/layouts/blog.html b/internal/web/templates/layouts/blog.html index cf00272..3e854f6 100644 --- a/internal/web/templates/layouts/blog.html +++ b/internal/web/templates/layouts/blog.html @@ -76,6 +76,8 @@ {{- else if eq $m.Kind "tagcloud"}}<div class="mod mod-tagcloud">{{template "modtitle" $m}} <p class="tagcloud">{{range $r.Data.tagcloud}}<a class="tc-{{.Size}}" href="/tag/{{.Slug}}" title="{{.Count}}">{{.Name}}</a> {{else}}<span class="muted">{{t "No tags yet."}}</span>{{end}}</p> </div> +{{- else if eq $m.Kind "search"}}{{if eq $m.Area "header"}}<div class="site-search"><div class="wrap search-inner">{{template "searchform" $r}}</div></div> +{{else}}<div class="mod mod-search">{{template "modtitle" $m}}{{template "searchform" $r}}</div>{{end}} {{- else if eq $m.Kind "html"}}{{if not $m.Body}}{{else if or (eq $m.Area "above") (eq $m.Area "below")}}<div class="custom-html custom-html-{{$m.Area}}">{{html $m.Body}}</div> {{else}}<div class="mod mod-html">{{template "modtitle" $m}}{{html $m.Body}}</div>{{end}} {{- else if eq $m.Kind "rss"}}<p class="mod mod-rss small"><a href="/feed.xml">{{t "RSS feed"}}</a></p> @@ -85,6 +87,10 @@ </div> {{- end}}{{end}} +{{/* The search box: a plain GET form, so it works without JavaScript. .Data.q + only exists on the search page, hence the with. */}} +{{define "searchform"}}<form method="get" action="/search" class="search-form"><input type="search" name="q"{{with .Data.q}} value="{{.}}"{{end}} placeholder="{{t "Search…"}}" size="18"> <button type="submit">{{t "Search"}}</button></form>{{end}} + {{define "modtitle"}}{{if .Title}}<h3 class="mod-title">{{.Title}}</h3>{{end}}{{end}} {{define "menulinks"}}{{range .Data.menu}}<a href="{{.Href}}"{{if and .PageID $.Data.page (eq $.Data.page.ID (deref64 .PageID))}} class="active"{{end}}>{{.Text}}</a> |
