diff options
author | Alan Pearce | 2024-06-08 20:34:37 +0200 |
---|---|---|
committer | Alan Pearce | 2024-06-08 20:42:48 +0200 |
commit | 408aed03d3454330120475ca53838a2f4fe28ea3 (patch) | |
tree | 78d0bb27634154a4ac956c851ea12b71db9ac6b9 /internal/server/templates.go | |
parent | d40c0e188a7fe1b36887f59c4a9958faa81b3d44 (diff) | |
download | searchix-408aed03d3454330120475ca53838a2f4fe28ea3.tar.lz searchix-408aed03d3454330120475ca53838a2f4fe28ea3.tar.zst searchix-408aed03d3454330120475ca53838a2f4fe28ea3.zip |
feat: display results in a table, showing details on click
Diffstat (limited to 'internal/server/templates.go')
-rw-r--r-- | internal/server/templates.go | 15 |
1 files changed, 13 insertions, 2 deletions
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) |