@@ -13,7 +13,6 @@ import (
1313 "code.gitea.io/gitea/modules/json"
1414 "code.gitea.io/gitea/modules/log"
1515 "code.gitea.io/gitea/modules/options"
16- "code.gitea.io/gitea/modules/reqctx"
1716 "code.gitea.io/gitea/modules/svg"
1817)
1918
@@ -62,30 +61,21 @@ func (m *MaterialIconProvider) loadData() {
6261 log .Debug ("Loaded material icon rules and SVG images" )
6362}
6463
65- func (m * MaterialIconProvider ) renderFileIconSVG (ctx reqctx.RequestContext , name , svg , extraClass string ) template.HTML {
66- data := ctx .GetData ()
67- renderedSVGs , _ := data ["_RenderedSVGs" ].(map [string ]bool )
68- if renderedSVGs == nil {
69- renderedSVGs = make (map [string ]bool )
70- data ["_RenderedSVGs" ] = renderedSVGs
71- }
64+ func (m * MaterialIconProvider ) renderFileIconSVG (p * RenderedIconPool , name , svg , extraClass string ) template.HTML {
7265 // 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.
7366 // Will try to refactor this in the future.
7467 if ! strings .HasPrefix (svg , "<svg" ) {
7568 panic ("Invalid SVG icon" )
7669 }
7770 svgID := "svg-mfi-" + name
7871 svgCommonAttrs := `class="svg git-entry-icon ` + extraClass + `" width="16" height="16" aria-hidden="true"`
79- posOuterBefore := strings .IndexByte (svg , '>' )
80- if renderedSVGs [svgID ] && posOuterBefore != - 1 {
81- return template .HTML (`<svg ` + svgCommonAttrs + `><use xlink:href="#` + svgID + `"></use></svg>` )
72+ if p .IconSVGs [svgID ] == "" {
73+ p .IconSVGs [svgID ] = template .HTML (`<svg id="` + svgID + `" ` + svgCommonAttrs + svg [4 :])
8274 }
83- svg = `<svg id="` + svgID + `" ` + svgCommonAttrs + svg [4 :]
84- renderedSVGs [svgID ] = true
85- return template .HTML (svg )
75+ return template .HTML (`<svg ` + svgCommonAttrs + `><use xlink:href="#` + svgID + `"></use></svg>` )
8676}
8777
88- func (m * MaterialIconProvider ) FileIcon (ctx reqctx. RequestContext , entry * git.TreeEntry ) template.HTML {
78+ func (m * MaterialIconProvider ) FileIcon (p * RenderedIconPool , entry * git.TreeEntry ) template.HTML {
8979 if m .rules == nil {
9080 return BasicThemeIcon (entry )
9181 }
@@ -110,7 +100,7 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
110100 case entry .IsSubModule ():
111101 extraClass = "octicon-file-submodule"
112102 }
113- return m .renderFileIconSVG (ctx , name , iconSVG , extraClass )
103+ return m .renderFileIconSVG (p , name , iconSVG , extraClass )
114104 }
115105 // TODO: use an interface or wrapper for git.Entry to make the code testable.
116106 return BasicThemeIcon (entry )
0 commit comments