Skip to content
13 changes: 6 additions & 7 deletions routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"fmt"
gotemplate "html/template"
"io/ioutil"
"path"
"strconv"
"strings"

Expand All @@ -36,7 +35,7 @@ const (
tplForks base.TplName = "repo/forks"
)

func renderDirectory(ctx *context.Context, treeLink string) {
func renderDirectory(ctx *context.Context) {
tree, err := ctx.Repo.Commit.SubTree(ctx.Repo.TreePath)
if err != nil {
ctx.NotFoundOrServerError("Repo.Commit.SubTree", git.IsErrNotExist, err)
Expand Down Expand Up @@ -104,7 +103,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {

if markup.Type(readmeFile.Name()) != "" {
ctx.Data["IsMarkup"] = true
ctx.Data["FileContent"] = string(markup.Render(readmeFile.Name(), buf, treeLink, ctx.Repo.Repository.ComposeMetas()))
ctx.Data["FileContent"] = string(markup.Render(readmeFile.Name(), buf, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
} else {
ctx.Data["IsRenderedHTML"] = true
ctx.Data["FileContent"] = strings.Replace(
Expand Down Expand Up @@ -143,7 +142,7 @@ func renderDirectory(ctx *context.Context, treeLink string) {
}
}

func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink string) {
func renderFile(ctx *context.Context, entry *git.TreeEntry, rawLink string) {
ctx.Data["IsViewFile"] = true

blob := entry.Blob()
Expand Down Expand Up @@ -211,7 +210,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st
ctx.Data["ReadmeExist"] = readmeExist
if markup.Type(blob.Name()) != "" {
ctx.Data["IsMarkup"] = true
ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, path.Dir(treeLink), ctx.Repo.Repository.ComposeMetas()))
ctx.Data["FileContent"] = string(markup.Render(blob.Name(), buf, ctx.Repo.RepoLink, ctx.Repo.Repository.ComposeMetas()))
} else if readmeExist {
ctx.Data["IsRenderedHTML"] = true
ctx.Data["FileContent"] = strings.Replace(
Expand Down Expand Up @@ -344,9 +343,9 @@ func renderCode(ctx *context.Context) {
}

if entry.IsDir() {
renderDirectory(ctx, treeLink)
renderDirectory(ctx)
} else {
renderFile(ctx, entry, treeLink, rawLink)
renderFile(ctx, entry, rawLink)
}
if ctx.Written() {
return
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/editor/edit.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="ui top attached tabular menu" data-write="write" data-preview="preview" data-diff="diff">
<a class="active item" data-tab="write"><i class="octicon octicon-code"></i> {{if .IsNewFile}}{{.i18n.Tr "repo.editor.new_file"}}{{else}}{{.i18n.Tr "repo.editor.edit_file"}}{{end}}</a>
{{if not .IsNewFile}}
<a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}/src/{{.BranchNameSubURL | EscapePound}}" data-preview-file-modes="{{.PreviewableFileModes}}"><i class="octicon octicon-eye"></i> {{.i18n.Tr "repo.release.preview"}}</a>
<a class="item" data-tab="preview" data-url="{{AppSubUrl}}/api/v1/markdown" data-context="{{.RepoLink}}" data-preview-file-modes="{{.PreviewableFileModes}}"><i class="octicon octicon-eye"></i> {{.i18n.Tr "repo.release.preview"}}</a>
<a class="item" data-tab="diff" data-url="{{.RepoLink}}/_preview/{{.BranchName | EscapePound}}/{{.TreePath | EscapePound}}" data-context="{{.BranchLink}}"><i class="octicon octicon-diff"></i> {{.i18n.Tr "repo.editor.preview_changes"}}</a>
{{end}}
</div>
Expand Down