diff options
Diffstat (limited to 'internal/components')
-rw-r--r-- | internal/components/combined.templ | 38 | ||||
-rw-r--r-- | internal/components/data.go | 3 | ||||
-rw-r--r-- | internal/components/page.templ | 26 | ||||
-rw-r--r-- | internal/components/results.templ | 19 |
4 files changed, 76 insertions, 10 deletions
diff --git a/internal/components/combined.templ b/internal/components/combined.templ new file mode 100644 index 0000000..eeacdb5 --- /dev/null +++ b/internal/components/combined.templ @@ -0,0 +1,38 @@ +package components + +import ( + "go.alanpearce.eu/searchix/internal/index" + "go.alanpearce.eu/searchix/internal/nix" +) + +templ Combined(result *index.Result) { + <table> + <thead> + <tr> + <th scope="col">Attribute</th> + <th scope="col">Description</th> + </tr> + </thead> + <tbody> + for _, hit := range result.Hits { + <tr> + <td> + @openCombinedDialogLink(nix.GetKey(hit.Data)) + </td> + <td> + switch hit.Data.(type) { + case nix.Option: + if o := convertMatch[nix.Option](hit.Data); o != nil { + @markdown(firstSentence(o.Description)) + } + case nix.Package: + if o := convertMatch[nix.Package](hit.Data); o != nil { + { firstSentence(o.Description) } + } + } + </td> + </tr> + } + </tbody> + </table> +} diff --git a/internal/components/data.go b/internal/components/data.go index 8f4fe62..601102d 100644 --- a/internal/components/data.go +++ b/internal/components/data.go @@ -11,9 +11,8 @@ import ( type TemplateData struct { Sources []*config.Source - Source config.Source + Source *config.Source Query string - Results bool SourceResult *bleve.SearchResult ExtraHeadHTML string Code int diff --git a/internal/components/page.templ b/internal/components/page.templ index da0322e..ade677f 100644 --- a/internal/components/page.templ +++ b/internal/components/page.templ @@ -18,11 +18,17 @@ templ Page(tdata TemplateData) { <link href={ sheet.URL } rel="stylesheet" integrity={ "sha256-" + sheet.Base64SHA256 }/> } @Unsafe(tdata.ExtraHeadHTML) + <link + rel="search" + type="application/opensearchdescription+xml" + title={ "Searchix " + sourceNameAndType(nil) } + href={ string(joinPath("/all", "opensearch.xml")) } + /> for _, source := range tdata.Sources { <link rel="search" type="application/opensearchdescription+xml" - title={ "Searchix " + sourceNameAndType(*source) } + title={ "Searchix " + sourceNameAndType(source) } href={ string(joinPath("/", source.Importer.String(), source.Key, "opensearch.xml")) } /> } @@ -31,9 +37,19 @@ templ Page(tdata TemplateData) { <header> <nav> <h1><a href="/">Searchix</a></h1> + <a + if tdata.Source == nil { + if tdata.SourceResult != nil || tdata.Query != "" { + class="current" + } + href="/all/search" + } else { + href={ joinPathQuery("/all/search", tdata.Query) } + } + >All</a> for _, source := range tdata.Sources { <a - if tdata.Source.Name == source.Name { + if tdata.Source != nil && tdata.Source.Name == source.Name { class="current" href={ joinPath("/", source.Importer.String(), source.Key, "search") } } else { @@ -65,7 +81,11 @@ func Unsafe(html string) templ.Component { }) } -func sourceNameAndType(source config.Source) string { +func sourceNameAndType(source *config.Source) string { + if source == nil { + return "Combined" + } + switch source.Importer { case config.Options: return source.Name + " " + source.Importer.String() diff --git a/internal/components/results.templ b/internal/components/results.templ index 6d85e16..226b71e 100644 --- a/internal/components/results.templ +++ b/internal/components/results.templ @@ -3,6 +3,7 @@ package components import ( "strconv" "go.alanpearce.eu/searchix/internal/nix" + "go.alanpearce.eu/searchix/internal/config" ) func convertMatch[I nix.Importable](m nix.Importable) *I { @@ -16,11 +17,15 @@ func convertMatch[I nix.Importable](m nix.Importable) *I { templ Results(r ResultData) { if r.Query != "" { if r.Results != nil && r.Results.Total > 0 { - switch r.Results.Hits[0].Data.(type) { - case nix.Option: - @Options(r.Results) - case nix.Package: - @Packages(r.Results) + if r.Source != nil { + switch r.Source.Importer { + case config.Options: + @Options(r.Results) + case config.Packages: + @Packages(r.Results) + } + } else { + @Combined(r.Results) } <footer aria-label="pagination"> <nav id="pagination"> @@ -50,3 +55,7 @@ templ ResultsPage(r ResultData) { templ openDialogLink(attr string) { <a class="open-dialog" href={ templ.SafeURL(attr) }>{ attr }</a> } + +templ openCombinedDialogLink(attr string) { + <a class="open-dialog" href={ templ.SafeURL("/" + attr) }>{ attr }</a> +} |