mirror of https://github.com/gogs/gogs.git
pkg/context: change banner file path (#5750)
parent
dc13eb6df0
commit
d775fe7936
2
gogs.go
2
gogs.go
|
@ -16,7 +16,7 @@ import (
|
||||||
"github.com/gogs/gogs/pkg/setting"
|
"github.com/gogs/gogs/pkg/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.11.88.0627"
|
const APP_VER = "0.11.89.0728"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
setting.AppVer = APP_VER
|
setting.AppVer = APP_VER
|
||||||
|
|
|
@ -327,7 +327,7 @@ func Contexter() macaron.Handler {
|
||||||
c.Data["ShowFooterBranding"] = setting.ShowFooterBranding
|
c.Data["ShowFooterBranding"] = setting.ShowFooterBranding
|
||||||
c.Data["ShowFooterVersion"] = setting.ShowFooterVersion
|
c.Data["ShowFooterVersion"] = setting.ShowFooterVersion
|
||||||
|
|
||||||
c.Data["ServerNotice"] = readServerNotice()
|
c.renderNoticeBanner()
|
||||||
|
|
||||||
ctx.Map(c)
|
ctx.Map(c)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,47 +16,47 @@ import (
|
||||||
"github.com/gogs/gogs/pkg/tool"
|
"github.com/gogs/gogs/pkg/tool"
|
||||||
)
|
)
|
||||||
|
|
||||||
// readServerNotice checks if a notice file exists and loads the message to display
|
// renderNoticeBanner checks if a notice banner file exists and loads the message to display
|
||||||
// on all pages.
|
// on all pages.
|
||||||
func readServerNotice() string {
|
func (c *Context) renderNoticeBanner() {
|
||||||
fpath := path.Join(setting.CustomPath, "notice.md")
|
fpath := path.Join(setting.CustomPath, "notice/banner.md")
|
||||||
if !com.IsExist(fpath) {
|
if !com.IsExist(fpath) {
|
||||||
return ""
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
f, err := os.Open(fpath)
|
f, err := os.Open(fpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(2, "Failed to open notice file %s: %v", fpath, err)
|
log.Error(2, "Failed to open file %q: %v", fpath, err)
|
||||||
return ""
|
return
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
fi, err := f.Stat()
|
fi, err := f.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(2, "Failed to stat notice file %s: %v", fpath, err)
|
log.Error(2, "Failed to stat file %q: %v", fpath, err)
|
||||||
return ""
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit size to prevent very large messages from breaking pages
|
// Limit size to prevent very large messages from breaking pages
|
||||||
var maxSize int64 = 1024
|
var maxSize int64 = 1024
|
||||||
|
|
||||||
if fi.Size() > maxSize { // Refuse to print very long messages
|
if fi.Size() > maxSize { // Refuse to print very long messages
|
||||||
log.Error(2, "Notice file %s size too large [%d > %d]: refusing to render", fpath, fi.Size(), maxSize)
|
log.Warn("Notice banner file %q size too large [%d > %d]: refusing to render", fpath, fi.Size(), maxSize)
|
||||||
return ""
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := make([]byte, maxSize)
|
buf := make([]byte, maxSize)
|
||||||
n, err := f.Read(buf)
|
n, err := f.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(2, "Failed to read notice file: %v", err)
|
log.Error(2, "Failed to read file %q: %v", fpath, err)
|
||||||
return ""
|
return
|
||||||
}
|
}
|
||||||
buf = buf[:n]
|
buf = buf[:n]
|
||||||
|
|
||||||
if !tool.IsTextFile(buf) {
|
if !tool.IsTextFile(buf) {
|
||||||
log.Error(2, "Notice file %s does not appear to be a text file: aborting", fpath)
|
log.Warn("Notice banner file %q does not appear to be a text file: aborting", fpath)
|
||||||
return ""
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(markup.RawMarkdown(buf, ""))
|
c.Data["ServerNotice"] = string(markup.RawMarkdown(buf, ""))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.11.88.0627
|
0.11.89.0728
|
||||||
|
|
Loading…
Reference in New Issue