From 8c9d2bdee34ba31bbb8c69b45b746c597505fb1b Mon Sep 17 00:00:00 2001 From: Kerwin Bryant Date: Mon, 7 Apr 2025 03:35:08 +0800 Subject: [PATCH] Keep file tree view icons consistent with icon theme (#33921) Fix #33914 before: ![3000-gogitea-gitea-y4ulxr46c4k ws-us118 gitpod io_test_test gitea_src_branch_main_ gitmodules](https://github.com/user-attachments/assets/ca50eeff-cc44-4041-b01f-c0c5bdd3b6aa) after: ![3000-gogitea-gitea-y4ulxr46c4k ws-us118 gitpod io_test_test gitea_src_branch_main_README md](https://github.com/user-attachments/assets/3b87fdbd-81d0-4831-8a74-4dbfcd5b6d91) --------- Co-authored-by: wxiaoguang --- modules/fileicon/material.go | 22 +++------ modules/fileicon/render.go | 52 ++++++++++++++++++++++ modules/git/error.go | 12 ++--- modules/git/tree_entry.go | 42 ++++++++--------- modules/git/tree_entry_mode.go | 20 +++------ modules/templates/util_render.go | 9 ---- routers/web/repo/treelist.go | 6 ++- routers/web/repo/view.go | 12 +++++ routers/web/repo/view_readme.go | 2 +- services/repository/files/tree.go | 38 ++++++++++++---- services/repository/files/tree_test.go | 19 ++++++-- templates/repo/view_list.tmpl | 3 +- web_src/js/components/ViewFileTree.vue | 10 +++++ web_src/js/components/ViewFileTreeItem.vue | 9 +++- 14 files changed, 170 insertions(+), 86 deletions(-) create mode 100644 modules/fileicon/render.go diff --git a/modules/fileicon/material.go b/modules/fileicon/material.go index cbdb962ee3..557f7ca9e4 100644 --- a/modules/fileicon/material.go +++ b/modules/fileicon/material.go @@ -13,7 +13,6 @@ import ( "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/options" - "code.gitea.io/gitea/modules/reqctx" "code.gitea.io/gitea/modules/svg" ) @@ -62,13 +61,7 @@ func (m *MaterialIconProvider) loadData() { log.Debug("Loaded material icon rules and SVG images") } -func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name, svg, extraClass string) template.HTML { - data := ctx.GetData() - renderedSVGs, _ := data["_RenderedSVGs"].(map[string]bool) - if renderedSVGs == nil { - renderedSVGs = make(map[string]bool) - data["_RenderedSVGs"] = renderedSVGs - } +func (m *MaterialIconProvider) renderFileIconSVG(p *RenderedIconPool, name, svg, extraClass string) template.HTML { // This part is a bit hacky, but it works really well. It should be safe to do so because all SVG icons are generated by us. // Will try to refactor this in the future. if !strings.HasPrefix(svg, "