aboutsummaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-04-18 03:05:19 +0800
committerGitHub <noreply@github.com>2023-04-17 15:05:19 -0400
commit1ab16e48cccc086e7f97fb3ae8a293fe47a3a452 (patch)
tree24f19185b5606ea605f5d74d6369dbfd4dc2d189 /routers
parentf045e58cc7ba076a0ac4b0b5bf0702fa155eaa59 (diff)
downloadgitea-1ab16e48cccc086e7f97fb3ae8a293fe47a3a452.tar.gz
gitea-1ab16e48cccc086e7f97fb3ae8a293fe47a3a452.zip
Improve Wiki TOC (#24137)
The old code has a lot of technical debts, eg: `repo/wiki/view.tmpl` / `Iterate` This PR improves the Wiki TOC display and improves the code. --------- Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'routers')
-rw-r--r--routers/web/base.go24
-rw-r--r--routers/web/repo/wiki.go10
2 files changed, 20 insertions, 14 deletions
diff --git a/routers/web/base.go b/routers/web/base.go
index da18a75643..79991d89db 100644
--- a/routers/web/base.go
+++ b/routers/web/base.go
@@ -143,31 +143,29 @@ func Recovery(ctx goctx.Context) func(next http.Handler) http.Handler {
"locale": lc,
}
- user := context.GetContextUser(req)
+ // TODO: this recovery handler is usually called without Gitea's web context, so we shouldn't touch that context too much
+ // Otherwise, the 500 page may cause new panics, eg: cache.GetContextWithData, it makes the developer&users couldn't find the original panic
+ user := context.GetContextUser(req) // almost always nil
if user == nil {
// Get user from session if logged in - do not attempt to sign-in
user = auth.SessionUser(sessionStore)
}
- if user != nil {
- store["IsSigned"] = true
- store["SignedUser"] = user
- store["SignedUserID"] = user.ID
- store["SignedUserName"] = user.Name
- store["IsAdmin"] = user.IsAdmin
- } else {
- store["SignedUserID"] = int64(0)
- store["SignedUserName"] = ""
- }
httpcache.SetCacheControlInHeader(w.Header(), 0, "no-transform")
w.Header().Set(`X-Frame-Options`, setting.CORSConfig.XFrameOptions)
- if !setting.IsProd {
+ if !setting.IsProd || (user != nil && user.IsAdmin) {
store["ErrorMsg"] = combinedErr
}
+
+ defer func() {
+ if err := recover(); err != nil {
+ log.Error("HTML render in Recovery handler panics again: %v", err)
+ }
+ }()
err = rnd.HTML(w, http.StatusInternalServerError, "status/500", templates.BaseVars().Merge(store))
if err != nil {
- log.Error("%v", err)
+ log.Error("HTML render in Recovery handler fails again: %v", err)
}
}
}()
diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go
index fe2becb7bb..0c5c5eed7d 100644
--- a/routers/web/repo/wiki.go
+++ b/routers/web/repo/wiki.go
@@ -298,7 +298,15 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
ctx.Data["footerPresent"] = false
}
- ctx.Data["toc"] = rctx.TableOfContents
+ if rctx.SidebarTocNode != nil {
+ sb := &strings.Builder{}
+ err = markdown.SpecializedMarkdown().Renderer().Render(sb, nil, rctx.SidebarTocNode)
+ if err != nil {
+ log.Error("Failed to render wiki sidebar TOC: %v", err)
+ } else {
+ ctx.Data["sidebarTocContent"] = sb.String()
+ }
+ }
// get commit count - wiki revisions
commitsCount, _ := wikiRepo.FileCommitsCount(wiki_service.DefaultBranch, pageFilename)