2024-03-01 17:58:05 +00:00
|
|
|
// Code generated by templ - DO NOT EDIT.
|
|
|
|
|
2024-06-27 04:23:41 +00:00
|
|
|
// templ: version: v0.2.707
|
2024-03-01 17:58:05 +00:00
|
|
|
package html
|
|
|
|
|
|
|
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
|
|
|
|
|
|
|
import "github.com/a-h/templ"
|
|
|
|
import "context"
|
|
|
|
import "io"
|
|
|
|
import "bytes"
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
import "go.jolheiser.com/ugit/internal/git"
|
|
|
|
|
|
|
|
type SearchContext struct {
|
|
|
|
BaseContext
|
|
|
|
RepoHeaderComponentContext
|
|
|
|
Results []git.GrepResult
|
|
|
|
}
|
|
|
|
|
2024-03-01 22:49:07 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-03-01 17:58:05 +00:00
|
|
|
func RepoSearch(sc SearchContext) templ.Component {
|
|
|
|
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
|
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
|
|
|
if !templ_7745c5c3_IsBuffer {
|
|
|
|
templ_7745c5c3_Buffer = templ.GetBuffer()
|
|
|
|
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
|
|
}
|
|
|
|
ctx = templ.InitializeContext(ctx)
|
|
|
|
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
|
|
|
if templ_7745c5c3_Var1 == nil {
|
|
|
|
templ_7745c5c3_Var1 = templ.NopComponent
|
|
|
|
}
|
|
|
|
ctx = templ.ClearChildren(ctx)
|
|
|
|
templ_7745c5c3_Var2 := templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
|
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
|
|
|
if !templ_7745c5c3_IsBuffer {
|
|
|
|
templ_7745c5c3_Buffer = templ.GetBuffer()
|
|
|
|
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
|
|
}
|
|
|
|
templ_7745c5c3_Err = repoHeaderComponent(sc.RepoHeaderComponentContext).Render(ctx, templ_7745c5c3_Buffer)
|
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
2024-05-25 02:31:35 +00:00
|
|
|
for _, results := range sc.DedupeResults() {
|
|
|
|
templ_7745c5c3_Err = repoSearchResult(sc.RepoHeaderComponentContext.Name, sc.RepoHeaderComponentContext.Ref, results).Render(ctx, templ_7745c5c3_Buffer)
|
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
2024-03-01 17:58:05 +00:00
|
|
|
}
|
2024-05-25 02:31:35 +00:00
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
|
2024-03-01 17:58:05 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
2024-05-25 02:31:35 +00:00
|
|
|
if len(sc.DedupeResults()) == 0 {
|
2024-06-27 04:23:41 +00:00
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<p class=\"text-text mt-5 text-lg\">No results</p>")
|
2024-03-01 22:49:07 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !templ_7745c5c3_IsBuffer {
|
|
|
|
_, templ_7745c5c3_Err = io.Copy(templ_7745c5c3_W, templ_7745c5c3_Buffer)
|
|
|
|
}
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
})
|
|
|
|
templ_7745c5c3_Err = base(sc.BaseContext).Render(templ.WithChildren(ctx, templ_7745c5c3_Var2), templ_7745c5c3_Buffer)
|
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
2024-06-27 04:23:41 +00:00
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<script>\n\t\tconst search = new URLSearchParams(window.location.search).get(\"q\");\n\t\tif (search !== \"\") document.querySelector(\"#search\").value = search;\n\t</script>")
|
2024-03-01 22:49:07 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
|
|
|
if !templ_7745c5c3_IsBuffer {
|
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
|
|
|
}
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func repoSearchResult(repo, ref string, results []git.GrepResult) templ.Component {
|
|
|
|
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
|
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
|
|
|
if !templ_7745c5c3_IsBuffer {
|
|
|
|
templ_7745c5c3_Buffer = templ.GetBuffer()
|
|
|
|
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
|
|
}
|
|
|
|
ctx = templ.InitializeContext(ctx)
|
2024-06-27 04:23:41 +00:00
|
|
|
templ_7745c5c3_Var3 := templ.GetChildren(ctx)
|
|
|
|
if templ_7745c5c3_Var3 == nil {
|
|
|
|
templ_7745c5c3_Var3 = templ.NopComponent
|
2024-03-01 22:49:07 +00:00
|
|
|
}
|
|
|
|
ctx = templ.ClearChildren(ctx)
|
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"text-text mt-5\"><a class=\"underline decoration-text/50 decoration-dashed hover:decoration-solid\" href=\"")
|
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
2024-06-27 04:23:41 +00:00
|
|
|
var templ_7745c5c3_Var4 templ.SafeURL = templ.SafeURL(fmt.Sprintf("/%s/tree/%s/%s#L%d", repo, ref, results[0].File, results[0].Line))
|
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var4)))
|
2024-03-01 22:49:07 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
|
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
2024-06-27 04:23:41 +00:00
|
|
|
var templ_7745c5c3_Var5 string
|
|
|
|
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(results[0].File)
|
2024-03-01 22:49:07 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
2024-06-27 04:23:41 +00:00
|
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 50, Col: 230}
|
2024-03-01 22:49:07 +00:00
|
|
|
}
|
2024-06-27 04:23:41 +00:00
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
|
2024-03-01 22:49:07 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a></div><div class=\"code\">")
|
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
|
|
|
templ_7745c5c3_Err = templ.Raw(results[0].Content).Render(ctx, templ_7745c5c3_Buffer)
|
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>")
|
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
|
|
|
if len(results) > 1 {
|
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<details class=\"text-text cursor-pointer\"><summary>")
|
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
2024-06-27 04:23:41 +00:00
|
|
|
var templ_7745c5c3_Var6 string
|
|
|
|
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d ", len(results[1:])))
|
2024-03-01 22:49:07 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
2024-06-27 04:23:41 +00:00
|
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 56, Col: 50}
|
2024-03-01 22:49:07 +00:00
|
|
|
}
|
2024-06-27 04:23:41 +00:00
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
|
2024-03-01 22:49:07 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
2024-06-27 04:23:41 +00:00
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("more</summary> ")
|
2024-03-01 22:49:07 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
|
|
|
for _, result := range results[1:] {
|
2024-03-22 18:12:47 +00:00
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"text-text mt-5 ml-5\"><a class=\"underline decoration-text/50 decoration-dashed hover:decoration-solid\" href=\"")
|
2024-03-01 17:58:05 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
2024-06-27 04:23:41 +00:00
|
|
|
var templ_7745c5c3_Var7 templ.SafeURL = templ.SafeURL(fmt.Sprintf("/%s/tree/%s/%s#L%d", repo, ref, result.File, result.Line))
|
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var7)))
|
2024-03-01 17:58:05 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\">")
|
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
2024-06-27 04:23:41 +00:00
|
|
|
var templ_7745c5c3_Var8 string
|
|
|
|
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(results[0].File)
|
2024-03-01 17:58:05 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
2024-06-27 04:23:41 +00:00
|
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 58, Col: 230}
|
2024-03-01 17:58:05 +00:00
|
|
|
}
|
2024-06-27 04:23:41 +00:00
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
|
2024-03-01 17:58:05 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
2024-03-22 18:12:47 +00:00
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a></div><div class=\"code ml-5\">")
|
2024-03-01 17:58:05 +00:00
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
|
|
|
templ_7745c5c3_Err = templ.Raw(result.Content).Render(ctx, templ_7745c5c3_Buffer)
|
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div>")
|
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
}
|
|
|
|
}
|
2024-03-01 22:49:07 +00:00
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</details>")
|
|
|
|
if templ_7745c5c3_Err != nil {
|
|
|
|
return templ_7745c5c3_Err
|
2024-03-01 17:58:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if !templ_7745c5c3_IsBuffer {
|
|
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
|
|
|
}
|
|
|
|
return templ_7745c5c3_Err
|
|
|
|
})
|
|
|
|
}
|