From 3bb1440e5fd2ac351b33142abfcc1ace5dc4b6db Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Wed, 12 Jun 2024 15:14:41 +0800 Subject: [PATCH 1/6] fix --- options/locale/locale_en-US.ini | 1 + routers/web/repo/blame.go | 2 -- routers/web/repo/setting/lfs.go | 1 + routers/web/repo/view.go | 7 +++---- templates/repo/blame.tmpl | 2 ++ templates/repo/file_info.tmpl | 4 ++-- templates/repo/settings/lfs_file.tmpl | 6 ++---- templates/repo/view_file.tmpl | 2 ++ templates/shared/fileisempty.tmpl | 3 +++ 9 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 templates/shared/fileisempty.tmpl diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 539715b3f9c91..fbada5472c5c6 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1238,6 +1238,7 @@ file_view_rendered = View Rendered file_view_raw = View Raw file_permalink = Permalink file_too_large = The file is too large to be shown. +file_is_empty = The file is empty. code_preview_line_from_to = Lines %[1]d to %[2]d in %[3]s code_preview_line_in = Line %[1]d in %[2]s invisible_runes_header = `This file contains invisible Unicode characters` diff --git a/routers/web/repo/blame.go b/routers/web/repo/blame.go index 1887e4d95da3d..3e76ea6df4367 100644 --- a/routers/web/repo/blame.go +++ b/routers/web/repo/blame.go @@ -99,8 +99,6 @@ func RefBlame(ctx *context.Context) { } ctx.Data["NumLines"], err = blob.GetBlobLineCount() - ctx.Data["NumLinesSet"] = true - if err != nil { ctx.NotFound("GetBlobLineCount", err) return diff --git a/routers/web/repo/setting/lfs.go b/routers/web/repo/setting/lfs.go index 6dddade066e8e..2891556d6fc30 100644 --- a/routers/web/repo/setting/lfs.go +++ b/routers/web/repo/setting/lfs.go @@ -303,6 +303,7 @@ func LFSFileGet(ctx *context.Context) { rd := charset.ToUTF8WithFallbackReader(io.MultiReader(bytes.NewReader(buf), dataRc), charset.ConvertOpts{}) // Building code view blocks with line number on server side. + // FIXME: the logic is not right here: it first calls EscapeControlReader then calls HTMLEscapeString: double-escaping escapedContent := &bytes.Buffer{} ctx.Data["EscapeStatus"], _ = charset.EscapeControlReader(rd, escapedContent, ctx.Locale) diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 386ef7be5ce87..0aa3fe1efd77b 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -286,6 +286,7 @@ func renderReadmeFile(ctx *context.Context, subfolder string, readmeFile *git.Tr ctx.Data["FileIsText"] = fInfo.isTextFile ctx.Data["FileName"] = path.Join(subfolder, readmeFile.Name()) + ctx.Data["FileSize"] = fInfo.fileSize ctx.Data["IsLFSFile"] = fInfo.isLFSFile if fInfo.isLFSFile { @@ -301,7 +302,6 @@ func renderReadmeFile(ctx *context.Context, subfolder string, readmeFile *git.Tr // Pretend that this is a normal text file to display 'This file is too large to be shown' ctx.Data["IsFileTooLarge"] = true ctx.Data["IsTextFile"] = true - ctx.Data["FileSize"] = fInfo.fileSize return } @@ -552,7 +552,6 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) { } else { ctx.Data["NumLines"] = bytes.Count(buf, []byte{'\n'}) + 1 } - ctx.Data["NumLinesSet"] = true language, err := files_service.TryGetContentLanguage(ctx.Repo.GitRepo, ctx.Repo.CommitID, ctx.Repo.TreePath) if err != nil { @@ -606,8 +605,8 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) { break } - // TODO: this logic seems strange, it duplicates with "isRepresentableAsText=true", it is not the same as "LFSFileGet" in "lfs.go" - // maybe for this case, the file is a binary file, and shouldn't be rendered? + // TODO: this logic duplicates with "isRepresentableAsText=true", it is not the same as "LFSFileGet" in "lfs.go" + // It is used by "external renders", markupRender will execute external programs to get rendered content. if markupType := markup.Type(blob.Name()); markupType != "" { rd := io.MultiReader(bytes.NewReader(buf), dataRc) ctx.Data["IsMarkup"] = true diff --git a/templates/repo/blame.tmpl b/templates/repo/blame.tmpl index 4ad3ed85c9a1f..3e7cd92066264 100644 --- a/templates/repo/blame.tmpl +++ b/templates/repo/blame.tmpl @@ -32,6 +32,8 @@
{{if .IsFileTooLarge}} {{template "shared/filetoolarge" dict "RawFileLink" .RawFileLink}} + {{else if not .FileSize}} + {{template "shared/fileisempty"}} {{else}} diff --git a/templates/repo/file_info.tmpl b/templates/repo/file_info.tmpl index 823cf1b7d8c99..b63af68973dbe 100644 --- a/templates/repo/file_info.tmpl +++ b/templates/repo/file_info.tmpl @@ -4,12 +4,12 @@ {{ctx.Locale.Tr "repo.symbolic_link"}} {{end}} - {{if .NumLinesSet}}{{/* Explicit attribute needed to show 0 line changes */}} + {{if ne .NumLines nil}}
{{.NumLines}} {{ctx.Locale.TrN .NumLines "repo.line" "repo.lines"}}
{{end}} - {{if .FileSize}} + {{if ne .FileSize nil}}
{{FileSize .FileSize}}{{if .IsLFSFile}} ({{ctx.Locale.Tr "repo.stored_lfs"}}){{end}}
diff --git a/templates/repo/settings/lfs_file.tmpl b/templates/repo/settings/lfs_file.tmpl index a015cc8bd1aab..f6fac05b69141 100644 --- a/templates/repo/settings/lfs_file.tmpl +++ b/templates/repo/settings/lfs_file.tmpl @@ -16,10 +16,8 @@
{{if .IsFileTooLarge}} {{template "shared/filetoolarge" dict "RawFileLink" .RawFileLink}} - {{else if .IsMarkup}} - {{if .FileContent}}{{.FileContent | SafeHTML}}{{end}} - {{else if .IsPlainText}} -
{{if .FileContent}}{{.FileContent | SafeHTML}}{{end}}
+ {{else if not .FileSize}} + {{template "shared/fileisempty"}} {{else if not .IsTextFile}}
{{if .IsImageFile}} diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index 0a34b6c325b05..0ec400cfe9153 100644 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -91,6 +91,8 @@
{{if .IsFileTooLarge}} {{template "shared/filetoolarge" dict "RawFileLink" .RawFileLink}} + {{else if not .FileSize}} + {{template "shared/fileisempty"}} {{else if .IsMarkup}} {{if .FileContent}}{{.FileContent}}{{end}} {{else if .IsPlainText}} diff --git a/templates/shared/fileisempty.tmpl b/templates/shared/fileisempty.tmpl new file mode 100644 index 0000000000000..ab59294b2f0a7 --- /dev/null +++ b/templates/shared/fileisempty.tmpl @@ -0,0 +1,3 @@ +
+ {{ctx.Locale.Tr "repo.file_is_empty"}} +
From 2058ff218a8958465b8aceca8155826558b00854 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 12 Jun 2024 18:44:56 +0200 Subject: [PATCH 2/6] center the text --- templates/shared/fileisempty.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/shared/fileisempty.tmpl b/templates/shared/fileisempty.tmpl index ab59294b2f0a7..095b5fa676650 100644 --- a/templates/shared/fileisempty.tmpl +++ b/templates/shared/fileisempty.tmpl @@ -1,3 +1,3 @@ -
+
{{ctx.Locale.Tr "repo.file_is_empty"}}
From fed56cce2c2538f7ecbd0a38eb0f5c0ecd082fd9 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 12 Jun 2024 18:48:57 +0200 Subject: [PATCH 3/6] fix padding on markup --- templates/shared/fileisempty.tmpl | 2 +- web_src/css/repo.css | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/templates/shared/fileisempty.tmpl b/templates/shared/fileisempty.tmpl index 095b5fa676650..5d9c1b2facec3 100644 --- a/templates/shared/fileisempty.tmpl +++ b/templates/shared/fileisempty.tmpl @@ -1,3 +1,3 @@ -
+
{{ctx.Locale.Tr "repo.file_is_empty"}}
diff --git a/web_src/css/repo.css b/web_src/css/repo.css index e44bc9811b88d..c19af91dcd395 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -1714,6 +1714,11 @@ td .commit-summary { .file-view.markup { padding: 1em 2em; } + +.file-view.markup:has(.file-is-empty) { + padding: 0; +} + .repository .activity-header { display: flex; justify-content: space-between; From f6e568797e5a37cc3c8cd0d7ac5f3584a555d399 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 12 Jun 2024 18:53:47 +0200 Subject: [PATCH 4/6] fix font-size and line-height --- web_src/css/base.css | 3 ++- web_src/css/repo.css | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/web_src/css/base.css b/web_src/css/base.css index 3bdcde99f6d22..20590d3336d1a 100644 --- a/web_src/css/base.css +++ b/web_src/css/base.css @@ -11,6 +11,7 @@ --font-weight-bold: 700; /* line-height: use the default value as "modules/normalize.css" */ --line-height-default: normal; + --font-size-default: 14px; /* images */ --checkbox-mask-checked: url('data:image/svg+xml;utf8,'); --checkbox-mask-indeterminate: url('data:image/svg+xml;utf8,'); @@ -54,7 +55,7 @@ html, body { height: 100%; - font-size: 14px; + font-size: var(--font-size-default); } body { diff --git a/web_src/css/repo.css b/web_src/css/repo.css index c19af91dcd395..73684abf13405 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -1719,6 +1719,11 @@ td .commit-summary { padding: 0; } +.file-is-empty { + font-size: var(--font-size-default) !important; + line-height: var(--line-height-default) !important; +} + .repository .activity-header { display: flex; justify-content: space-between; From 397155096a440745b9833a12bcc9635690b3e925 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 12 Jun 2024 18:57:18 +0200 Subject: [PATCH 5/6] move styles to css --- templates/shared/fileisempty.tmpl | 2 +- web_src/css/base.css | 3 +-- web_src/css/repo.css | 6 ++++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/templates/shared/fileisempty.tmpl b/templates/shared/fileisempty.tmpl index 5d9c1b2facec3..d16812d38d75e 100644 --- a/templates/shared/fileisempty.tmpl +++ b/templates/shared/fileisempty.tmpl @@ -1,3 +1,3 @@ -
+
{{ctx.Locale.Tr "repo.file_is_empty"}}
diff --git a/web_src/css/base.css b/web_src/css/base.css index 20590d3336d1a..3bdcde99f6d22 100644 --- a/web_src/css/base.css +++ b/web_src/css/base.css @@ -11,7 +11,6 @@ --font-weight-bold: 700; /* line-height: use the default value as "modules/normalize.css" */ --line-height-default: normal; - --font-size-default: 14px; /* images */ --checkbox-mask-checked: url('data:image/svg+xml;utf8,'); --checkbox-mask-indeterminate: url('data:image/svg+xml;utf8,'); @@ -55,7 +54,7 @@ html, body { height: 100%; - font-size: var(--font-size-default); + font-size: 14px; } body { diff --git a/web_src/css/repo.css b/web_src/css/repo.css index 73684abf13405..bb612f6845ca9 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -1720,8 +1720,10 @@ td .commit-summary { } .file-is-empty { - font-size: var(--font-size-default) !important; - line-height: var(--line-height-default) !important; + padding: 1rem; + text-align: center; + font-size: 1rem !important; /* undo style from .markup parent */ + line-height: var(--line-height-default) !important; /* undo style from .markup parent */ } .repository .activity-header { From 89a87b3a8b89ef8a0777e75d985500fd3124eb7d Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Thu, 13 Jun 2024 08:36:52 +0800 Subject: [PATCH 6/6] use name "file-not-rendered-prompt" --- templates/shared/fileisempty.tmpl | 2 +- templates/shared/filetoolarge.tmpl | 2 +- web_src/css/repo.css | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/templates/shared/fileisempty.tmpl b/templates/shared/fileisempty.tmpl index d16812d38d75e..a92bcbcdbcd7a 100644 --- a/templates/shared/fileisempty.tmpl +++ b/templates/shared/fileisempty.tmpl @@ -1,3 +1,3 @@ -
+
{{ctx.Locale.Tr "repo.file_is_empty"}}
diff --git a/templates/shared/filetoolarge.tmpl b/templates/shared/filetoolarge.tmpl index 8842fb1b91141..cb23864ec8efc 100644 --- a/templates/shared/filetoolarge.tmpl +++ b/templates/shared/filetoolarge.tmpl @@ -1,4 +1,4 @@ -
+
{{ctx.Locale.Tr "repo.file_too_large"}} {{if .RawFileLink}}{{ctx.Locale.Tr "repo.file_view_raw"}}{{end}}
diff --git a/web_src/css/repo.css b/web_src/css/repo.css index bb612f6845ca9..669e5960a80e4 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -1715,15 +1715,15 @@ td .commit-summary { padding: 1em 2em; } -.file-view.markup:has(.file-is-empty) { - padding: 0; +.file-view.markup:has(.file-not-rendered-prompt) { + padding: 0; /* let the file-not-rendered-prompt layout itself */ } -.file-is-empty { +.file-not-rendered-prompt { padding: 1rem; text-align: center; - font-size: 1rem !important; /* undo style from .markup parent */ - line-height: var(--line-height-default) !important; /* undo style from .markup parent */ + font-size: 1rem !important; /* use consistent styles for various containers (code, markup, etc) */ + line-height: var(--line-height-default) !important; /* same as above */ } .repository .activity-header {