diff --git a/routers/web/explore/code.go b/routers/web/explore/code.go index d81884ec62deb..0c5ebbee1450c 100644 --- a/routers/web/explore/code.go +++ b/routers/web/explore/code.go @@ -16,6 +16,7 @@ import ( const ( // tplExploreCode explore code page template tplExploreCode base.TplName = "explore/code" + tplSearchBody base.TplName = "code/search_body" ) // Code render explore code page @@ -42,8 +43,15 @@ func Code(ctx *context.Context) { ctx.Data["queryType"] = queryType ctx.Data["PageIsViewCode"] = true + isHtmxRequest := len(ctx.Req.Header.Values("HX-Request")) > 0 + + template := tplExploreCode + if isHtmxRequest { + template = tplSearchBody + } + if keyword == "" { - ctx.HTML(http.StatusOK, tplExploreCode) + ctx.HTML(http.StatusOK, template) return } @@ -131,5 +139,5 @@ func Code(ctx *context.Context) { pager.AddParam(ctx, "l", "Language") ctx.Data["Page"] = pager - ctx.HTML(http.StatusOK, tplExploreCode) + ctx.HTML(http.StatusOK, template) } diff --git a/routers/web/repo/search.go b/routers/web/repo/search.go index 3c0fa4bc00ea0..fab9d2277a5ce 100644 --- a/routers/web/repo/search.go +++ b/routers/web/repo/search.go @@ -12,7 +12,10 @@ import ( "code.gitea.io/gitea/modules/setting" ) -const tplSearch base.TplName = "repo/search" +const ( + tplSearch base.TplName = "repo/search" + tplSearchResult base.TplName = "repo/search_result" +) // Search render repository search page func Search(ctx *context.Context) { @@ -32,8 +35,15 @@ func Search(ctx *context.Context) { ctx.Data["queryType"] = queryType ctx.Data["PageIsViewCode"] = true + isHtmxRequest := len(ctx.Req.Header.Values("HX-Request")) > 0 + + template := tplSearch + if isHtmxRequest { + template = tplSearchResult + } + if keyword == "" { - ctx.HTML(http.StatusOK, tplSearch) + ctx.HTML(http.StatusOK, template) return } @@ -63,5 +73,5 @@ func Search(ctx *context.Context) { pager.AddParam(ctx, "l", "Language") ctx.Data["Page"] = pager - ctx.HTML(http.StatusOK, tplSearch) + ctx.HTML(http.StatusOK, template) } diff --git a/routers/web/user/code.go b/routers/web/user/code.go index ee514a7cfe535..dfd27ff4c38bf 100644 --- a/routers/web/user/code.go +++ b/routers/web/user/code.go @@ -15,7 +15,8 @@ import ( ) const ( - tplUserCode base.TplName = "user/code" + tplUserCode base.TplName = "user/code" + tplSearchBody base.TplName = "code/search_body" ) // CodeSearch render user/organization code search page @@ -47,8 +48,15 @@ func CodeSearch(ctx *context.Context) { ctx.Data["queryType"] = queryType ctx.Data["IsCodePage"] = true + isHtmxRequest := len(ctx.Req.Header.Values("HX-Request")) > 0 + + template := tplUserCode + if isHtmxRequest { + template = tplSearchBody + } + if keyword == "" { - ctx.HTML(http.StatusOK, tplUserCode) + ctx.HTML(http.StatusOK, template) return } @@ -116,5 +124,5 @@ func CodeSearch(ctx *context.Context) { pager.AddParam(ctx, "l", "Language") ctx.Data["Page"] = pager - ctx.HTML(http.StatusOK, tplUserCode) + ctx.HTML(http.StatusOK, template) } diff --git a/templates/code/search_body.tmpl b/templates/code/search_body.tmpl new file mode 100644 index 0000000000000..c9c94aeef37a6 --- /dev/null +++ b/templates/code/search_body.tmpl @@ -0,0 +1,12 @@ +