aboutsummaryrefslogtreecommitdiff
path: root/routers/repo
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-01-25 07:10:52 -0500
committerUnknwon <u@gogs.io>2017-01-25 07:10:52 -0500
commit8cb903fbbb6de5decb443af1481b44b5c1a426d1 (patch)
tree78c577d42471344c06a876609c5766689f3758c1 /routers/repo
parentd1c327d508e5d3c1ad9237ccf7c7d5b6cc21be8a (diff)
Fix unexpected rendering of README when it is not in Markdown
This patch also handles case when a file name looks like README but is not a text file (e.g. image, PDF).
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/view.go6
1 files changed, 2 insertions, 4 deletions
diff --git a/routers/repo/view.go b/routers/repo/view.go
index 2c17ed8d..5fc38fb2 100644
--- a/routers/repo/view.go
+++ b/routers/repo/view.go
@@ -79,9 +79,8 @@ func renderDirectory(ctx *context.Context, treeLink string) {
buf = buf[:n]
isTextFile := base.IsTextFile(buf)
- ctx.Data["FileIsText"] = isTextFile
+ ctx.Data["IsTextFile"] = isTextFile
ctx.Data["FileName"] = readmeFile.Name()
- // FIXME: what happens when README file is an image?
if isTextFile {
d, _ := ioutil.ReadAll(dataRc)
buf = append(buf, d...)
@@ -156,10 +155,9 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
isMarkdown := markdown.IsMarkdownFile(blob.Name())
ctx.Data["IsMarkdown"] = isMarkdown
- readmeExist := isMarkdown || markdown.IsReadmeFile(blob.Name())
+ readmeExist := isMarkdown && markdown.IsReadmeFile(blob.Name())
ctx.Data["ReadmeExist"] = readmeExist
if readmeExist {
- // TODO: don't need to render if it's a README but not Markdown file.
ctx.Data["FileContent"] = string(markdown.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
} else {
// Building code view blocks with line number on server side.