about summary refs log tree commit diff stats
path: root/internal
diff options
context:
space:
mode:
authorAlan Pearce2024-06-08 20:34:37 +0200
committerAlan Pearce2024-06-08 20:42:48 +0200
commit408aed03d3454330120475ca53838a2f4fe28ea3 (patch)
tree78d0bb27634154a4ac956c851ea12b71db9ac6b9 /internal
parentd40c0e188a7fe1b36887f59c4a9958faa81b3d44 (diff)
downloadsearchix-408aed03d3454330120475ca53838a2f4fe28ea3.tar.lz
searchix-408aed03d3454330120475ca53838a2f4fe28ea3.tar.zst
searchix-408aed03d3454330120475ca53838a2f4fe28ea3.zip
feat: display results in a table, showing details on click
Diffstat (limited to 'internal')
-rw-r--r--internal/server/templates.go15
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)