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

Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
Lunny Xiao 2022-04-27 20:04:53 +08:00 committed by GitHub
parent 39a0db6ecf
commit 8ff542c1a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -191,7 +191,10 @@ 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
//lookup filename in wiki - get filecontent, gitTree entry , real filename isSideBar := pageName == "_Sidebar"
isFooter := pageName == "_Footer"
// 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 {
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages") ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages")
@ -203,23 +206,33 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
return nil, nil return nil, nil
} }
sidebarContent, _, _, _ := wikiContentsByName(ctx, commit, "_Sidebar") var sidebarContent []byte
if ctx.Written() { if !isSideBar {
if wikiRepo != nil { sidebarContent, _, _, _ = wikiContentsByName(ctx, commit, "_Sidebar")
wikiRepo.Close() if ctx.Written() {
if wikiRepo != nil {
wikiRepo.Close()
}
return nil, nil
} }
return nil, nil } else {
sidebarContent = data
} }
footerContent, _, _, _ := wikiContentsByName(ctx, commit, "_Footer") var footerContent []byte
if ctx.Written() { if !isFooter {
if wikiRepo != nil { footerContent, _, _, _ = wikiContentsByName(ctx, commit, "_Footer")
wikiRepo.Close() if ctx.Written() {
if wikiRepo != nil {
wikiRepo.Close()
}
return nil, nil
} }
return nil, nil } else {
footerContent = data
} }
var rctx = &markup.RenderContext{ rctx := &markup.RenderContext{
URLPrefix: ctx.Repo.RepoLink, URLPrefix: ctx.Repo.RepoLink,
Metas: ctx.Repo.Repository.ComposeDocumentMetas(), Metas: ctx.Repo.Repository.ComposeDocumentMetas(),
IsWiki: true, IsWiki: true,
@ -236,27 +249,35 @@ 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())
buf.Reset() if !isSideBar {
if err := markdown.Render(rctx, bytes.NewReader(sidebarContent), &buf); err != nil { buf.Reset()
if wikiRepo != nil { if err := markdown.Render(rctx, bytes.NewReader(sidebarContent), &buf); err != nil {
wikiRepo.Close() if wikiRepo != nil {
wikiRepo.Close()
}
ctx.ServerError("Render", err)
return nil, nil
} }
ctx.ServerError("Render", err) ctx.Data["sidebarPresent"] = sidebarContent != nil
return nil, 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 !isFooter {
if err := markdown.Render(rctx, bytes.NewReader(footerContent), &buf); err != nil { buf.Reset()
if wikiRepo != nil { if err := markdown.Render(rctx, bytes.NewReader(footerContent), &buf); err != nil {
wikiRepo.Close() if wikiRepo != nil {
wikiRepo.Close()
}
ctx.ServerError("Render", err)
return nil, nil
} }
ctx.ServerError("Render", err) ctx.Data["footerPresent"] = footerContent != nil
return nil, 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 // get commit count - wiki revisions
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename) commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
@ -290,7 +311,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
ctx.Data["Username"] = ctx.Repo.Owner.Name ctx.Data["Username"] = ctx.Repo.Owner.Name
ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["Reponame"] = ctx.Repo.Repository.Name
//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 {
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages") ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages")
@ -364,7 +385,7 @@ func renderEditPage(ctx *context.Context) {
ctx.Data["title"] = pageName ctx.Data["title"] = pageName
ctx.Data["RequireHighlightJS"] = true ctx.Data["RequireHighlightJS"] = true
//lookup filename in wiki - get filecontent, gitTree entry , real filename // lookup filename in wiki - get filecontent, gitTree entry , real filename
data, entry, _, noEntry := wikiContentsByName(ctx, commit, pageName) data, entry, _, noEntry := wikiContentsByName(ctx, commit, pageName)
if noEntry { if noEntry {
ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages") ctx.Redirect(ctx.Repo.RepoLink + "/wiki/?action=_pages")