summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2022-04-27 07:24:20 +0800
committerGitHub <noreply@github.com>2022-04-26 19:24:20 -0400
commit5651c650c09accbb01bfe21e268f7d289a3b5d19 (patch)
tree3065ba5091936e761af6d4272f3b80aeea00d305
parent2728f0c21360a81845b7b5aebe68c857a5d04bd5 (diff)
downloadgitea-5651c650c09accbb01bfe21e268f7d289a3b5d19.tar.gz
gitea-5651c650c09accbb01bfe21e268f7d289a3b5d19.zip
When view _Siderbar or _Footer, just display once (#19501)
Co-authored-by: zeripath <art27@cantab.net>
-rw-r--r--routers/web/repo/wiki.go73
1 files changed, 47 insertions, 26 deletions
diff --git a/routers/web/repo/wiki.go b/routers/web/repo/wiki.go
index 32f596ff37..2dbd62d816 100644
--- a/routers/web/repo/wiki.go
+++ b/routers/web/repo/wiki.go
@@ -191,6 +191,9 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
ctx.Data["title"] = pageName
ctx.Data["RequireHighlightJS"] = true
+ isSideBar := pageName == "_Sidebar"
+ isFooter := pageName == "_Footer"
+
// lookup filename in wiki - get filecontent, gitTree entry , real filename
data, entry, pageFilename, noEntry := wikiContentsByName(ctx, commit, pageName)
if noEntry {
@@ -203,20 +206,30 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
return nil, nil
}
- sidebarContent, _, _, _ := wikiContentsByName(ctx, commit, "_Sidebar")
- if ctx.Written() {
- if wikiRepo != nil {
- wikiRepo.Close()
+ var sidebarContent []byte
+ if !isSideBar {
+ sidebarContent, _, _, _ = wikiContentsByName(ctx, commit, "_Sidebar")
+ if ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+ return nil, nil
}
- return nil, nil
+ } else {
+ sidebarContent = data
}
- footerContent, _, _, _ := wikiContentsByName(ctx, commit, "_Footer")
- if ctx.Written() {
- if wikiRepo != nil {
- wikiRepo.Close()
+ var footerContent []byte
+ if !isFooter {
+ footerContent, _, _, _ = wikiContentsByName(ctx, commit, "_Footer")
+ if ctx.Written() {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+ return nil, nil
}
- return nil, nil
+ } else {
+ footerContent = data
}
rctx := &markup.RenderContext{
@@ -237,27 +250,35 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
ctx.Data["EscapeStatus"], ctx.Data["content"] = charset.EscapeControlString(buf.String())
- buf.Reset()
- if err := markdown.Render(rctx, bytes.NewReader(sidebarContent), &buf); err != nil {
- if wikiRepo != nil {
- wikiRepo.Close()
+ if !isSideBar {
+ buf.Reset()
+ if err := markdown.Render(rctx, bytes.NewReader(sidebarContent), &buf); err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+ ctx.ServerError("Render", err)
+ return nil, nil
}
- ctx.ServerError("Render", err)
- return nil, nil
+ ctx.Data["sidebarPresent"] = sidebarContent != nil
+ ctx.Data["sidebarEscapeStatus"], ctx.Data["sidebarContent"] = charset.EscapeControlString(buf.String())
+ } else {
+ ctx.Data["sidebarPresent"] = false
}
- ctx.Data["sidebarPresent"] = sidebarContent != nil
- ctx.Data["sidebarEscapeStatus"], ctx.Data["sidebarContent"] = charset.EscapeControlString(buf.String())
- buf.Reset()
- if err := markdown.Render(rctx, bytes.NewReader(footerContent), &buf); err != nil {
- if wikiRepo != nil {
- wikiRepo.Close()
+ if !isFooter {
+ buf.Reset()
+ if err := markdown.Render(rctx, bytes.NewReader(footerContent), &buf); err != nil {
+ if wikiRepo != nil {
+ wikiRepo.Close()
+ }
+ ctx.ServerError("Render", err)
+ return nil, nil
}
- ctx.ServerError("Render", err)
- return nil, nil
+ ctx.Data["footerPresent"] = footerContent != nil
+ ctx.Data["footerEscapeStatus"], ctx.Data["footerContent"] = charset.EscapeControlString(buf.String())
+ } else {
+ ctx.Data["footerPresent"] = false
}
- ctx.Data["footerPresent"] = footerContent != nil
- ctx.Data["footerEscapeStatus"], ctx.Data["footerContent"] = charset.EscapeControlString(buf.String())
// get commit count - wiki revisions
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)