aboutsummaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
Diffstat (limited to 'pkg')
-rw-r--r--pkg/context/context.go2
-rw-r--r--pkg/context/notice.go30
2 files changed, 16 insertions, 16 deletions
diff --git a/pkg/context/context.go b/pkg/context/context.go
index 33ae8b79..bcb87a9a 100644
--- a/pkg/context/context.go
+++ b/pkg/context/context.go
@@ -327,7 +327,7 @@ func Contexter() macaron.Handler {
c.Data["ShowFooterBranding"] = setting.ShowFooterBranding
c.Data["ShowFooterVersion"] = setting.ShowFooterVersion
- c.Data["ServerNotice"] = readServerNotice()
+ c.renderNoticeBanner()
ctx.Map(c)
}
diff --git a/pkg/context/notice.go b/pkg/context/notice.go
index e1bce474..2ac1d453 100644
--- a/pkg/context/notice.go
+++ b/pkg/context/notice.go
@@ -16,47 +16,47 @@ import (
"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.
-func readServerNotice() string {
- fpath := path.Join(setting.CustomPath, "notice.md")
+func (c *Context) renderNoticeBanner() {
+ fpath := path.Join(setting.CustomPath, "notice/banner.md")
if !com.IsExist(fpath) {
- return ""
+ return
}
f, err := os.Open(fpath)
if err != nil {
- log.Error(2, "Failed to open notice file %s: %v", fpath, err)
- return ""
+ log.Error(2, "Failed to open file %q: %v", fpath, err)
+ return
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
- log.Error(2, "Failed to stat notice file %s: %v", fpath, err)
- return ""
+ log.Error(2, "Failed to stat file %q: %v", fpath, err)
+ return
}
// Limit size to prevent very large messages from breaking pages
var maxSize int64 = 1024
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)
- return ""
+ log.Warn("Notice banner file %q size too large [%d > %d]: refusing to render", fpath, fi.Size(), maxSize)
+ return
}
buf := make([]byte, maxSize)
n, err := f.Read(buf)
if err != nil {
- log.Error(2, "Failed to read notice file: %v", err)
- return ""
+ log.Error(2, "Failed to read file %q: %v", fpath, err)
+ return
}
buf = buf[:n]
if !tool.IsTextFile(buf) {
- log.Error(2, "Notice file %s does not appear to be a text file: aborting", fpath)
- return ""
+ log.Warn("Notice banner file %q does not appear to be a text file: aborting", fpath)
+ return
}
- return string(markup.RawMarkdown(buf, ""))
+ c.Data["ServerNotice"] = string(markup.RawMarkdown(buf, ""))
}