package html import "fmt" import "go.jolheiser.com/ugit/internal/git" type SearchContext struct { BaseContext RepoHeaderComponentContext Results []git.GrepResult } func (s SearchContext) DedupeResults() [][]git.GrepResult { var ( results [][]git.GrepResult currentFile string currentResults []git.GrepResult ) for _, result := range s.Results { if result.File == currentFile { currentResults = append(currentResults, result) continue } if currentFile != "" { results = append(results, currentResults) } currentFile = result.File currentResults = []git.GrepResult{result} } return results } templ RepoSearch(sc SearchContext) { @base(sc.BaseContext) { @repoHeaderComponent(sc.RepoHeaderComponentContext)
for _, results := range sc.DedupeResults() { @repoSearchResult(sc.RepoHeaderComponentContext.Name, sc.RepoHeaderComponentContext.Ref, results) } } } templ repoSearchResult(repo, ref string, results []git.GrepResult) {
{ results[0].File }
@templ.Raw(results[0].Content)
if len(results) > 1 {
{ fmt.Sprintf("%d ", len(results[1:])) }more for _, result := range results[1:] {
{ results[0].File }
@templ.Raw(result.Content)
}
} }