diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index ea9f6147ae292..1746bc69d6471 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -90,6 +90,7 @@ remove = Remove remove_all = Remove All remove_label_str = Remove item "%s" edit = Edit +empty_file = Empty File enabled = Enabled disabled = Disabled diff --git a/routers/web/repo/blame.go b/routers/web/repo/blame.go index b1cb42297c1a6..600bad70f0f85 100644 --- a/routers/web/repo/blame.go +++ b/routers/web/repo/blame.go @@ -94,7 +94,6 @@ func RefBlame(ctx *context.Context) { ctx.Data["FileName"] = blob.Name() ctx.Data["NumLines"], err = blob.GetBlobLineCount() - ctx.Data["NumLinesSet"] = true if err != nil { ctx.NotFound("GetBlobLineCount", err) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index f0fe6140dfb8e..6a95e9901f7fa 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -463,6 +463,16 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st ctx.Data["HasSourceRenderedToggle"] = true } + buf, _ := io.ReadAll(rd) + + // empty: 0 lines; "a": one line; "a\n": two lines; "a\nb": two lines; + // the NumLines is only used for the display on the UI: "xxx lines" + if len(buf) == 0 { + ctx.Data["NumLines"] = 0 + } else { + ctx.Data["NumLines"] = bytes.Count(buf, []byte{'\n'}) + 1 + } + if markupType != "" && !shouldRenderSource { ctx.Data["IsMarkup"] = true ctx.Data["MarkupType"] = markupType @@ -486,17 +496,6 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry, treeLink, rawLink st // to prevent iframe load third-party url ctx.Resp.Header().Add("Content-Security-Policy", "frame-src 'self'") } else { - buf, _ := io.ReadAll(rd) - - // empty: 0 lines; "a": one line; "a\n": two lines; "a\nb": two lines; - // the NumLines is only used for the display on the UI: "xxx lines" - if len(buf) == 0 { - ctx.Data["NumLines"] = 0 - } else { - ctx.Data["NumLines"] = bytes.Count(buf, []byte{'\n'}) + 1 - } - ctx.Data["NumLinesSet"] = true - language := "" indexFilename, worktree, deleteTemporaryFile, err := ctx.Repo.GitRepo.ReadTreeToTemporaryIndex(ctx.Repo.CommitID) diff --git a/templates/repo/blame.tmpl b/templates/repo/blame.tmpl index b253c4d90143b..1fcf790d094c4 100644 --- a/templates/repo/blame.tmpl +++ b/templates/repo/blame.tmpl @@ -20,46 +20,50 @@
- {{range $row := .BlameRows}} - - + - - - {{if $.EscapeStatus.Escaped}} - + - {{end}} - - + + {{if $.EscapeStatus.Escaped}} + + {{end}} + + + {{end}} + {{else}} +
{{.locale.Tr "empty_file"}}
{{end}}
-
-
-
- {{$row.Avatar}} -
- -
- {{$row.CommitSince}} + {{if .BlameRows}} + {{range $row := .BlameRows}} +
+
+
+
+ {{$row.Avatar}} +
+ +
+ {{$row.CommitSince}} +
- -
- {{if $row.PreviousSha}} - - {{svg "octicon-versions"}} - - {{end}} - - - - {{if $row.EscapeStatus.Escaped}} - + + {{if $row.PreviousSha}} + + {{svg "octicon-versions"}} + {{end}} - {{$row.Code}} -
+ + + {{if $row.EscapeStatus.Escaped}} + + {{end}} + + {{$row.Code}} +
diff --git a/templates/repo/file_info.tmpl b/templates/repo/file_info.tmpl index 7323b30d77b53..4fe15d43fce9a 100644 --- a/templates/repo/file_info.tmpl +++ b/templates/repo/file_info.tmpl @@ -4,12 +4,12 @@ {{.locale.Tr "repo.symbolic_link"}}
{{end}} - {{if .NumLinesSet}}{{/* Explicit attribute needed to show 0 line changes */}} + {{if not (eq .NumLines nil)}}
{{.NumLines}} {{.locale.TrN .NumLines "repo.line" "repo.lines"}}
{{end}} - {{if .FileSize}} + {{if not (eq .FileSize nil)}}
{{FileSize .FileSize}}{{if .IsLFSFile}} ({{.locale.Tr "repo.stored_lfs"}}){{end}}
diff --git a/templates/repo/settings/lfs_file.tmpl b/templates/repo/settings/lfs_file.tmpl index de6f0100f86e1..36dd1d7f7e971 100644 --- a/templates/repo/settings/lfs_file.tmpl +++ b/templates/repo/settings/lfs_file.tmpl @@ -15,9 +15,17 @@ {{template "repo/unicode_escape_prompt" dict "EscapeStatus" .EscapeStatus "root" $}}
{{if .IsMarkup}} - {{if .FileContent}}{{.FileContent | Safe}}{{end}} + {{if .FileContent}} + {{.FileContent | Safe}} + {{else}} +
{{.locale.Tr "empty_file"}}
+ {{end}} {{else if .IsPlainText}} -
{{if .FileContent}}{{.FileContent | Safe}}{{end}}
+ {{if .FileContent}} +
{{.FileContent | Safe}}
+ {{else}} +
{{.locale.Tr "empty_file"}}
+ {{end}} {{else if not .IsTextFile}}
{{if .IsImageFile}} @@ -49,6 +57,8 @@ + {{else if not .FileSize}} +
{{.locale.Tr "empty_file"}}
{{end}}
diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 0882ff4b27462..15d8ca0f40084 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -69,9 +69,17 @@ {{end}}
{{if .IsMarkup}} - {{if .FileContent}}{{.FileContent | Safe}}{{end}} + {{if .FileContent}} + {{.FileContent | Safe}} + {{else}} +
{{.locale.Tr "empty_file"}}
+ {{end}} {{else if .IsPlainText}} -
{{if .FileContent}}{{.FileContent | Safe}}{{end}}
+ {{if .FileContent}} +
{{.FileContent | Safe}}
+ {{else}} +
{{.locale.Tr "empty_file"}}
+ {{end}} {{else if not .IsTextSource}}
{{if .IsImageFile}} @@ -122,6 +130,8 @@ {{.locale.Tr "repo.file_copy_permalink"}}
{{end}} + {{else if not .FileSize}} +
{{.locale.Tr "empty_file"}}
{{end}}