When view _Siderbar or _Footer, just display once (#19501)

Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
Lunny Xiao 2022-04-27 07:24:20 +08:00 committed by GitHub
parent 2728f0c213
commit 5651c650c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -191,6 +191,9 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
ctx.Data["title"] = pageName ctx.Data["title"] = pageName
ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireHighlightJS"] = true
isSideBar := pageName == "_Sidebar"
isFooter := pageName == "_Footer"
// lookup filename in wiki - get filecontent, gitTree entry , real filename // lookup filename in wiki - get filecontent, gitTree entry , real filename
data, entry, pageFilename, noEntry := wikiContentsByName(ctx, commit, pageName) data, entry, pageFilename, noEntry := wikiContentsByName(ctx, commit, pageName)
if noEntry { if noEntry {
@ -203,21 +206,31 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
return nil, nil return nil, nil
} }
sidebarContent, _, _, _ := wikiContentsByName(ctx, commit, "_Sidebar") var sidebarContent []byte
if !isSideBar {
sidebarContent, _, _, _ = wikiContentsByName(ctx, commit, "_Sidebar")
if ctx.Written() { if ctx.Written() {
if wikiRepo != nil { if wikiRepo != nil {
wikiRepo.Close() wikiRepo.Close()
} }
return nil, nil return nil, nil
} }
} else {
sidebarContent = data
}
footerContent, _, _, _ := wikiContentsByName(ctx, commit, "_Footer") var footerContent []byte
if !isFooter {
footerContent, _, _, _ = wikiContentsByName(ctx, commit, "_Footer")
if ctx.Written() { if ctx.Written() {
if wikiRepo != nil { if wikiRepo != nil {
wikiRepo.Close() wikiRepo.Close()
} }
return nil, nil return nil, nil
} }
} else {
footerContent = data
}
rctx := &markup.RenderContext{ rctx := &markup.RenderContext{
Ctx: ctx, Ctx: ctx,
@ -237,6 +250,7 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
ctx.Data["EscapeStatus"], ctx.Data["content"] = charset.EscapeControlString(buf.String()) ctx.Data["EscapeStatus"], ctx.Data["content"] = charset.EscapeControlString(buf.String())
if !isSideBar {
buf.Reset() buf.Reset()
if err := markdown.Render(rctx, bytes.NewReader(sidebarContent), &buf); err != nil { if err := markdown.Render(rctx, bytes.NewReader(sidebarContent), &buf); err != nil {
if wikiRepo != nil { if wikiRepo != nil {
@ -247,7 +261,11 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
} }
ctx.Data["sidebarPresent"] = sidebarContent != nil ctx.Data["sidebarPresent"] = sidebarContent != nil
ctx.Data["sidebarEscapeStatus"], ctx.Data["sidebarContent"] = charset.EscapeControlString(buf.String()) ctx.Data["sidebarEscapeStatus"], ctx.Data["sidebarContent"] = charset.EscapeControlString(buf.String())
} else {
ctx.Data["sidebarPresent"] = false
}
if !isFooter {
buf.Reset() buf.Reset()
if err := markdown.Render(rctx, bytes.NewReader(footerContent), &buf); err != nil { if err := markdown.Render(rctx, bytes.NewReader(footerContent), &buf); err != nil {
if wikiRepo != nil { if wikiRepo != nil {
@ -258,6 +276,9 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
} }
ctx.Data["footerPresent"] = footerContent != nil ctx.Data["footerPresent"] = footerContent != nil
ctx.Data["footerEscapeStatus"], ctx.Data["footerContent"] = charset.EscapeControlString(buf.String()) ctx.Data["footerEscapeStatus"], ctx.Data["footerContent"] = charset.EscapeControlString(buf.String())
} else {
ctx.Data["footerPresent"] = false
}
// get commit count - wiki revisions // get commit count - wiki revisions
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename) commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)