From 58643f38bdd62dc538a03865b1f81eb77d957779 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Tue, 31 Dec 2024 14:56:37 +0100 Subject: feat: show scores in results table in dev mode --- internal/components/combined.templ | 9 +++++++++ internal/components/dev.templ | 18 ++++++++++++++++++ internal/components/options.templ | 13 +++++++++++-- internal/components/packages.templ | 13 +++++++++++-- internal/components/page.templ | 7 ++++++- 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 internal/components/dev.templ (limited to 'internal/components') diff --git a/internal/components/combined.templ b/internal/components/combined.templ index eeacdb5..3beddcd 100644 --- a/internal/components/combined.templ +++ b/internal/components/combined.templ @@ -1,6 +1,7 @@ package components import ( + "go.alanpearce.eu/searchix/internal/config" "go.alanpearce.eu/searchix/internal/index" "go.alanpearce.eu/searchix/internal/nix" ) @@ -11,6 +12,9 @@ templ Combined(result *index.Result) { Attribute Description + if config.DevMode { + Score + } @@ -31,6 +35,11 @@ templ Combined(result *index.Result) { } } + if config.DevMode { + + @score(hit) + + } } diff --git a/internal/components/dev.templ b/internal/components/dev.templ new file mode 100644 index 0000000..a03eb4b --- /dev/null +++ b/internal/components/dev.templ @@ -0,0 +1,18 @@ +package components + +import ( + "go.alanpearce.eu/searchix/internal/index" + "strconv" +) + +templ score(h index.DocumentMatch) { + + { strconv.FormatFloat(h.Score, 'f', 2, 64) } + + + +
+			{ h.Expl.String() }
+		
+
+} diff --git a/internal/components/options.templ b/internal/components/options.templ index 8e31132..097f66f 100644 --- a/internal/components/options.templ +++ b/internal/components/options.templ @@ -1,6 +1,7 @@ package components import ( + "go.alanpearce.eu/searchix/internal/config" "go.alanpearce.eu/searchix/internal/index" "go.alanpearce.eu/searchix/internal/nix" ) @@ -11,19 +12,22 @@ templ Options(result *index.Result) { Title Description + if config.DevMode { + Score + } for _, hit := range result.Hits { if m := convertMatch[nix.Option](hit.Data); m != nil { - @optionRow(*m) + @optionRow(hit, *m) } } } -templ optionRow(o nix.Option) { +templ optionRow(hit index.DocumentMatch, o nix.Option) { @openDialogLink(o.Name) @@ -32,5 +36,10 @@ templ optionRow(o nix.Option) { @markdown(firstSentence(o.Description)) + if config.DevMode { + + @score(hit) + + } } diff --git a/internal/components/packages.templ b/internal/components/packages.templ index b90fcd5..6e14026 100644 --- a/internal/components/packages.templ +++ b/internal/components/packages.templ @@ -1,6 +1,7 @@ package components import ( + "go.alanpearce.eu/searchix/internal/config" "go.alanpearce.eu/searchix/internal/index" "go.alanpearce.eu/searchix/internal/nix" ) @@ -12,19 +13,22 @@ templ Packages(result *index.Result) { Attribute Name Description + if config.DevMode { + Score + } for _, hit := range result.Hits { if m := convertMatch[nix.Package](hit.Data); m != nil { - @packageRow(*m) + @packageRow(hit, *m) } } } -templ packageRow(p nix.Package) { +templ packageRow(hit index.DocumentMatch, p nix.Package) { @openDialogLink(p.Attribute) @@ -35,5 +39,10 @@ templ packageRow(p nix.Package) { { p.Description } + if config.DevMode { + + @score(hit) + + } } diff --git a/internal/components/page.templ b/internal/components/page.templ index b6c9a82..127d1ba 100644 --- a/internal/components/page.templ +++ b/internal/components/page.templ @@ -15,7 +15,12 @@ templ Page(tdata TemplateData) { - Searchix + + Searchix + if config.DevMode { + (Dev) + } + for _, sheet := range tdata.Assets.Stylesheets { } -- cgit 1.4.1