Home

ugit @main - refs - log -
-
https://git.jolheiser.com/ugit.git
The code powering this h*ckin' site
tree log patch
feat: move search to topbar and no result indicator Signed-off-by: jolheiser <john.olheiser@gmail.com>
Signature
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEgqEQpE3xoo1QwJO/uFOtpdp7v3oFAmZRTYcACgkQuFOtpdp7 v3qujw//UnjSpZD966fWMbqfJ572I0Dce5QyZ8hfD3nqtxe4AqBENNkJ+HNvw4Pd KlgfomUO0VPCRExBe6ASw6Qgl8I8Vv0nuR4Iu71SdZD9X+gKTUioCzVqInKgXZym thbvOJCcWLEsHjx6rWgeEWGe8ZmX5C0TH/ZM5AL7PyRhjmU6pZUIKPZ+/hN/+f2X 3ZMK3shF39Z3O1Ibc7ZAD6tZcqGiT//7TvfZy8MZ/R9eJn81NQ0mf0vayEHMMSKI 9qvf0zeYRFygR6rGkNpnNaCJ3xbDfq61yQF3y0tugvX/wcBLCuHV8HCFmOMopuhN HsnF1OE722duOmlkqr9WseVN2t8OgGnf4xxBp/13d6HSBkbflEPQnYtx5vjS4nLk KPp2OOolRikGrT58ybKBOj5tqDoB1Bi16Mx6hnkFFx2jydqcZ2f8bUWBOPWlYUUM 5XUGl9hB1pF6xJz6Og6kfn5jV3XNCYgqlhvZryNWfWekwx4J17UjZtbssrt1B9ex J6kieuGbLta+ljJCxFX1eQ4jQoNH2gr6phxFj7qgypNdKFj4hOoytJURZRcvkUWp ihTIy+DI4pD2COzRk5I5duqAUZZOp2e9XzdoviTRfuFbwJx/YDaSJVinrgkreejm r66Ut1HC8VrHtRDV3YLK2XANy33ETbMFETd8xOO8wro0bPtdiL4= =ZqnA -----END PGP SIGNATURE-----
jolheiser <john.olheiser@gmail.com>
8 months ago
5 changed files, 50 additions(+), 42 deletions(-)
M internal/html/repo.templ -> internal/html/repo.templ
diff --git a/internal/html/repo.templ b/internal/html/repo.templ
index a25475a5c18336b71828d5305e93e3cda2888dbe..8f183c6119dc904345b11f5445ece82b7289b066 100644
--- a/internal/html/repo.templ
+++ b/internal/html/repo.templ
@@ -3,10 +3,10 @@
 import "fmt"
 
 type RepoHeaderComponentContext struct {
-  Name string
-  Ref string
-  Description string
-	CloneURL string
+	Name        string
+	Ref         string
+	Description string
+	CloneURL    string
 }
 
 templ repoHeaderComponent(rhcc RepoHeaderComponentContext) {
@@ -21,10 +21,9 @@ 		<a class="underline decoration-text/50 decoration-dashed hover:decoration-solid" href={ templ.SafeURL(fmt.Sprintf("/%s/refs", rhcc.Name)) }>refs</a>
 		{ " - " }
 		<a class="underline decoration-text/50 decoration-dashed hover:decoration-solid" href={ templ.SafeURL(fmt.Sprintf("/%s/log/%s", rhcc.Name, rhcc.Ref)) }>log</a>
 		{ " - " }
-		<a class="underline decoration-text/50 decoration-dashed hover:decoration-solid" href={ templ.SafeURL(fmt.Sprintf("/%s/search", rhcc.Name)) }>search</a>
+		<form class="inline-block" action={ templ.SafeURL(fmt.Sprintf("/%s/search", rhcc.Name)) } method="get"><input class="rounded p-1 bg-mantle focus:border-lavender focus:outline-none focus:ring-0" id="search" type="text" name="q" placeholder="search"/></form>
 		{ " - " }
 		<pre class="text-text inline select-all bg-base dark:bg-base/50 p-1 rounded">{ fmt.Sprintf("%s/%s.git", rhcc.CloneURL, rhcc.Name) }</pre>
 	</div>
 	<div class="text-text/80 mb-1">{ rhcc.Description }</div>
 }
-
M internal/html/repo_search.templ -> internal/html/repo_search.templ
diff --git a/internal/html/repo_search.templ b/internal/html/repo_search.templ
index 97224dd2d41746b5177f7ddff25cbb5c6ef17b7f..184e622a8958d3ae0a4de497d2b06cc23b1d5cf1 100644
--- a/internal/html/repo_search.templ
+++ b/internal/html/repo_search.templ
@@ -4,7 +4,7 @@ import "fmt"
 import "go.jolheiser.com/ugit/internal/git"
 
 type SearchContext struct {
-  BaseContext
+	BaseContext
 	RepoHeaderComponentContext
 	Results []git.GrepResult
 }
@@ -33,9 +33,11 @@
 templ RepoSearch(sc SearchContext) {
 	@base(sc.BaseContext) {
 		@repoHeaderComponent(sc.RepoHeaderComponentContext)
-		<form method="get"><label class="text-text">Search <input class="rounded p-1 mt-2 bg-mantle focus:border-lavender focus:outline-none focus:ring-0" id="search" type="text" name="q" placeholder="search"/></label></form>
 		for _, results := range sc.DedupeResults() {
 			@repoSearchResult(sc.RepoHeaderComponentContext.Name, sc.RepoHeaderComponentContext.Ref, results)
+		}
+		if len(sc.DedupeResults()) == 0 {
+			<p class="text-text mt-5 text-lg">No results</p>
 		}
 	}
 	<script>
@@ -46,15 +48,18 @@ }
 
 templ repoSearchResult(repo, ref string, results []git.GrepResult) {
 	<div class="text-text mt-5"><a class="underline decoration-text/50 decoration-dashed hover:decoration-solid" href={ templ.SafeURL(fmt.Sprintf("/%s/tree/%s/%s#L%d", repo, ref, results[0].File, results[0].Line)) }>{ results[0].File }</a></div>
-	<div class="code">@templ.Raw(results[0].Content)</div>
+	<div class="code">
+		@templ.Raw(results[0].Content)
+	</div>
 	if len(results) > 1 {
 		<details class="text-text cursor-pointer">
 			<summary>{ fmt.Sprintf("%d ", len(results[1:])) }more</summary>
 			for _, result := range results[1:] {
 				<div class="text-text mt-5 ml-5"><a class="underline decoration-text/50 decoration-dashed hover:decoration-solid" href={ templ.SafeURL(fmt.Sprintf("/%s/tree/%s/%s#L%d", repo, ref, result.File, result.Line)) }>{ results[0].File }</a></div>
-				<div class="code ml-5">@templ.Raw(result.Content)</div>
+				<div class="code ml-5">
+					@templ.Raw(result.Content)
+				</div>
 			}
 		</details>
 	}
 }
-
M internal/html/repo_search_templ.go -> internal/html/repo_search_templ.go
diff --git a/internal/html/repo_search_templ.go b/internal/html/repo_search_templ.go
index 60fc0323f1e8f032f661f5f8be648e428c1f6200..3e5ccf2d643ae81c51cdd8b4dea85a81629d032f 100644
--- a/internal/html/repo_search_templ.go
+++ b/internal/html/repo_search_templ.go
@@ -63,21 +63,31 @@ 			templ_7745c5c3_Err = repoHeaderComponent(sc.RepoHeaderComponentContext).Render(ctx, templ_7745c5c3_Buffer)
 			if templ_7745c5c3_Err != nil {
 				return templ_7745c5c3_Err
 			}
-			_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" <form method=\"get\"><label class=\"text-text\">")
+			_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
 			if templ_7745c5c3_Err != nil {
 				return templ_7745c5c3_Err
 			}
-			templ_7745c5c3_Var3 := `Search `
-			_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
-			if templ_7745c5c3_Err != nil {
-				return templ_7745c5c3_Err
+			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
+				}
 			}
-			_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<input class=\"rounded p-1 mt-2 bg-mantle focus:border-lavender focus:outline-none focus:ring-0\" id=\"search\" type=\"text\" name=\"q\" placeholder=\"search\"></label></form>")
+			_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" ")
 			if templ_7745c5c3_Err != nil {
 				return templ_7745c5c3_Err
 			}
-			for _, results := range sc.DedupeResults() {
-				templ_7745c5c3_Err = repoSearchResult(sc.RepoHeaderComponentContext.Name, sc.RepoHeaderComponentContext.Ref, results).Render(ctx, templ_7745c5c3_Buffer)
+			if len(sc.DedupeResults()) == 0 {
+				_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<p class=\"text-text mt-5 text-lg\">")
+				if templ_7745c5c3_Err != nil {
+					return templ_7745c5c3_Err
+				}
+				templ_7745c5c3_Var3 := `No results`
+				_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var3)
+				if templ_7745c5c3_Err != nil {
+					return templ_7745c5c3_Err
+				}
+				_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</p>")
 				if templ_7745c5c3_Err != nil {
 					return templ_7745c5c3_Err
 				}
@@ -143,7 +153,7 @@ 		}
 		var templ_7745c5c3_Var7 string
 		templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(results[0].File)
 		if templ_7745c5c3_Err != nil {
-			return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 47, Col: 230}
+			return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 49, Col: 230}
 		}
 		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
 		if templ_7745c5c3_Err != nil {
@@ -169,7 +179,7 @@ 			}
 			var templ_7745c5c3_Var8 string
 			templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d ", len(results[1:])))
 			if templ_7745c5c3_Err != nil {
-				return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 51, Col: 50}
+				return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 55, Col: 50}
 			}
 			_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
 			if templ_7745c5c3_Err != nil {
@@ -201,7 +211,7 @@ 				}
 				var templ_7745c5c3_Var11 string
 				templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(results[0].File)
 				if templ_7745c5c3_Err != nil {
-					return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 53, Col: 230}
+					return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo_search.templ`, Line: 57, Col: 230}
 				}
 				_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
 				if templ_7745c5c3_Err != nil {
M internal/html/repo_templ.go -> internal/html/repo_templ.go
diff --git a/internal/html/repo_templ.go b/internal/html/repo_templ.go
index 23e886730b0171aa2f99227459956cbabbf11d15..97dd65e510e75fde93a98935b7f6b98c1e24a1f9 100644
--- a/internal/html/repo_templ.go
+++ b/internal/html/repo_templ.go
@@ -166,7 +166,7 @@ 		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
 		if templ_7745c5c3_Err != nil {
 			return templ_7745c5c3_Err
 		}
-		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(" <a class=\"underline decoration-text/50 decoration-dashed hover:decoration-solid\" href=\"")
+		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<form class=\"inline-block\" action=\"")
 		if templ_7745c5c3_Err != nil {
 			return templ_7745c5c3_Err
 		}
@@ -175,25 +175,16 @@ 		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(string(templ_7745c5c3_Var14)))
 		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
-		}
-		templ_7745c5c3_Var15 := `search`
-		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ_7745c5c3_Var15)
+		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" method=\"get\"><input class=\"rounded p-1 bg-mantle focus:border-lavender focus:outline-none focus:ring-0\" id=\"search\" type=\"text\" name=\"q\" placeholder=\"search\"></form>")
 		if templ_7745c5c3_Err != nil {
 			return templ_7745c5c3_Err
 		}
-		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</a> ")
-		if templ_7745c5c3_Err != nil {
-			return templ_7745c5c3_Err
-		}
-		var templ_7745c5c3_Var16 string
-		templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(" - ")
+		var templ_7745c5c3_Var15 string
+		templ_7745c5c3_Var15, templ_7745c5c3_Err = templ.JoinStringErrs(" - ")
 		if templ_7745c5c3_Err != nil {
 			return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo.templ`, Line: 24, Col: 9}
 		}
-		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
+		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var15))
 		if templ_7745c5c3_Err != nil {
 			return templ_7745c5c3_Err
 		}
@@ -201,12 +192,12 @@ 		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<pre class=\"text-text inline select-all bg-base dark:bg-base/50 p-1 rounded\">")
 		if templ_7745c5c3_Err != nil {
 			return templ_7745c5c3_Err
 		}
-		var templ_7745c5c3_Var17 string
-		templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%s/%s.git", rhcc.CloneURL, rhcc.Name))
+		var templ_7745c5c3_Var16 string
+		templ_7745c5c3_Var16, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%s/%s.git", rhcc.CloneURL, rhcc.Name))
 		if templ_7745c5c3_Err != nil {
 			return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo.templ`, Line: 25, Col: 131}
 		}
-		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
+		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var16))
 		if templ_7745c5c3_Err != nil {
 			return templ_7745c5c3_Err
 		}
@@ -214,12 +205,12 @@ 		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</pre></div><div class=\"text-text/80 mb-1\">")
 		if templ_7745c5c3_Err != nil {
 			return templ_7745c5c3_Err
 		}
-		var templ_7745c5c3_Var18 string
-		templ_7745c5c3_Var18, templ_7745c5c3_Err = templ.JoinStringErrs(rhcc.Description)
+		var templ_7745c5c3_Var17 string
+		templ_7745c5c3_Var17, templ_7745c5c3_Err = templ.JoinStringErrs(rhcc.Description)
 		if templ_7745c5c3_Err != nil {
 			return templ.Error{Err: templ_7745c5c3_Err, FileName: `repo.templ`, Line: 27, Col: 50}
 		}
-		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var18))
+		_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var17))
 		if templ_7745c5c3_Err != nil {
 			return templ_7745c5c3_Err
 		}
M internal/http/repo.go -> internal/http/repo.go
diff --git a/internal/http/repo.go b/internal/http/repo.go
index c4a767aa4dacb3fd9cea5296e1ad22ae64ac80b8..743c503c3ca49ea12f9159661113112f6a7f48c7 100644
--- a/internal/http/repo.go
+++ b/internal/http/repo.go
@@ -71,6 +71,9 @@
 func (rh repoHandler) repoFile(w http.ResponseWriter, r *http.Request, repo *git.Repo, ref, path string) error {
 	content, err := repo.FileContent(ref, path)
 	if err != nil {
+		if errors.Is(err, object.ErrFileNotFound) {
+			return httperr.Status(err, http.StatusNotFound)
+		}
 		return httperr.Error(err)
 	}