diff --git a/modules/base/tool.go b/modules/base/tool.go index e3a3ff4a23..ada73df7da 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -118,9 +118,17 @@ func EntryIcon(entry *git.TreeEntry) string { return "file-submodule" } + if IsCitationFile(entry) { + return "cross-reference" + } + return "file" } +func IsCitationFile(entry *git.TreeEntry) bool { + return entry.Name() == "CITATION.cff" || entry.Name() == "CITATION.bib" +} + // SetupGiteaRoot Sets GITEA_ROOT if it is not already set and returns the value func SetupGiteaRoot() string { giteaRoot := os.Getenv("GITEA_ROOT") diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 4d44a485b9..17e25d55ae 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -605,7 +605,7 @@ func renderFile(ctx *context.Context, entry *git.TreeEntry) { ctx.Data["EscapeStatus"] = status ctx.Data["FileContent"] = fileContent ctx.Data["LineEscapeStatus"] = statuses - ctx.Data["IsCitationFile"] = isCitationFile(entry) + ctx.Data["IsCitationFile"] = base.IsCitationFile(entry) } if !fInfo.isLFSFile { if ctx.Repo.CanEnableEditor(ctx, ctx.Doer) { @@ -783,10 +783,6 @@ func checkHomeCodeViewable(ctx *context.Context) { ctx.NotFound("Home", errors.New(ctx.Locale.TrString("units.error.no_unit_allowed_repo"))) } -func isCitationFile(entry *git.TreeEntry) bool { - return entry.Name() == "CITATION.cff" || entry.Name() == "CITATION.bib" -} - func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) { if entry.Name() != "" { return @@ -802,7 +798,7 @@ func checkCitationFile(ctx *context.Context, entry *git.TreeEntry) { return } for _, entry := range allEntries { - if isCitationFile(entry) { + if base.IsCitationFile(entry) { ctx.Data["CitationFile"] = entry.Name() break } diff --git a/tests/integration/repo_view_test.go b/tests/integration/repo_view_test.go index ce24aca16a..74864765ea 100644 --- a/tests/integration/repo_view_test.go +++ b/tests/integration/repo_view_test.go @@ -188,6 +188,11 @@ func TestRepoViewFileLines(t *testing.T) { TreePath: "seemingly-empty", ContentReader: strings.NewReader("\n"), }, + { + Operation: "create", + TreePath: "CITATION.cff", + ContentReader: strings.NewReader(""), + }, }) defer f() @@ -220,5 +225,18 @@ func TestRepoViewFileLines(t *testing.T) { testEOL(t, "empty", true) testEOL(t, "seemingly-empty", true) }) + t.Run("list", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + req := NewRequest(t, "GET", repo.Link()) + resp := MakeRequest(t, req, http.StatusOK) + htmlDoc := NewHTMLParser(t, resp.Body) + + nodes := htmlDoc.Find("#repo-files-table tr") + t.Run("CITATION.cff", func(t *testing.T) { + c, ok := nodes.Find(`.name a[title="CITATION.cff"] svg`).Attr("class") + assert.True(t, ok, "could not find CITATION.cff line") + assert.Contains(t, c, "octicon-cross-reference") + }) + }) }) } diff --git a/web_src/css/repo.css b/web_src/css/repo.css index 4234c07bf0..48705180b2 100644 --- a/web_src/css/repo.css +++ b/web_src/css/repo.css @@ -252,6 +252,7 @@ td .commit-summary { color: var(--color-primary); } +.repository.file.list #repo-files-table tbody .svg.octicon-cross-reference, .repository.file.list #repo-files-table tbody .svg.octicon-file, .repository.file.list #repo-files-table tbody .svg.octicon-file-symlink-file, .repository.file.list #repo-files-table tbody .svg.octicon-file-directory-symlink {