From 408aed03d3454330120475ca53838a2f4fe28ea3 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Sat, 8 Jun 2024 20:34:37 +0200 Subject: feat: display results in a table, showing details on click --- internal/server/templates.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'internal/server/templates.go') diff --git a/internal/server/templates.go b/internal/server/templates.go index 8967599..38ff5d4 100644 --- a/internal/server/templates.go +++ b/internal/server/templates.go @@ -7,6 +7,7 @@ import ( "io/fs" "log/slog" "path" + "regexp" "searchix/frontend" "searchix/internal/config" "searchix/internal/nix" @@ -19,10 +20,20 @@ import ( type TemplateCollection map[string]*template.Template -var md = goldmark.New( - goldmark.WithExtensions(extension.NewLinkify()), +var ( + md = goldmark.New( + goldmark.WithExtensions(extension.NewLinkify()), + ) + firstSentenceRegexp = regexp.MustCompile(`^.*?\.[[:space:]]`) ) var templateFuncs = template.FuncMap{ + "firstSentence": func(input nix.Markdown) nix.Markdown { + if fs := firstSentenceRegexp.FindString(string(input)); fs != "" { + return nix.Markdown(fs) + } + + return input + }, "markdown": func(input nix.Markdown) template.HTML { var out strings.Builder err := md.Convert([]byte(input), &out) -- cgit 1.4.1