|
|
|
@ -19,6 +19,7 @@ import ( |
|
|
|
|
"github.com/gogits/gogs/modules/context" |
|
|
|
|
"github.com/gogits/gogs/modules/log" |
|
|
|
|
"github.com/gogits/gogs/modules/markdown" |
|
|
|
|
"github.com/gogits/gogs/modules/setting" |
|
|
|
|
"github.com/gogits/gogs/modules/template" |
|
|
|
|
"github.com/gogits/gogs/modules/template/highlight" |
|
|
|
|
) |
|
|
|
@ -104,20 +105,25 @@ func Home(ctx *context.Context) { |
|
|
|
|
case isImageFile: |
|
|
|
|
ctx.Data["IsImageFile"] = true |
|
|
|
|
case isTextFile: |
|
|
|
|
d, _ := ioutil.ReadAll(dataRc) |
|
|
|
|
buf = append(buf, d...) |
|
|
|
|
readmeExist := markdown.IsMarkdownFile(blob.Name()) || markdown.IsReadmeFile(blob.Name()) |
|
|
|
|
ctx.Data["ReadmeExist"] = readmeExist |
|
|
|
|
if readmeExist { |
|
|
|
|
ctx.Data["FileContent"] = string(markdown.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas())) |
|
|
|
|
if blob.Size() >= setting.MaxDisplayFileSize { |
|
|
|
|
ctx.Data["IsFileTooLarge"] = true |
|
|
|
|
} else { |
|
|
|
|
if err, content := template.ToUtf8WithErr(buf); err != nil { |
|
|
|
|
if err != nil { |
|
|
|
|
log.Error(4, "Convert content encoding: %s", err) |
|
|
|
|
} |
|
|
|
|
ctx.Data["FileContent"] = string(buf) |
|
|
|
|
ctx.Data["IsFileTooLarge"] = false |
|
|
|
|
d, _ := ioutil.ReadAll(dataRc) |
|
|
|
|
buf = append(buf, d...) |
|
|
|
|
readmeExist := markdown.IsMarkdownFile(blob.Name()) || markdown.IsReadmeFile(blob.Name()) |
|
|
|
|
ctx.Data["ReadmeExist"] = readmeExist |
|
|
|
|
if readmeExist { |
|
|
|
|
ctx.Data["FileContent"] = string(markdown.Render(buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas())) |
|
|
|
|
} else { |
|
|
|
|
ctx.Data["FileContent"] = content |
|
|
|
|
if err, content := template.ToUtf8WithErr(buf); err != nil { |
|
|
|
|
if err != nil { |
|
|
|
|
log.Error(4, "Convert content encoding: %s", err) |
|
|
|
|
} |
|
|
|
|
ctx.Data["FileContent"] = string(buf) |
|
|
|
|
} else { |
|
|
|
|
ctx.Data["FileContent"] = content |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|