@@ -13,7 +13,6 @@ import (
13
13
"code.gitea.io/gitea/modules/json"
14
14
"code.gitea.io/gitea/modules/log"
15
15
"code.gitea.io/gitea/modules/options"
16
- "code.gitea.io/gitea/modules/reqctx"
17
16
"code.gitea.io/gitea/modules/svg"
18
17
)
19
18
@@ -62,30 +61,21 @@ func (m *MaterialIconProvider) loadData() {
62
61
log .Debug ("Loaded material icon rules and SVG images" )
63
62
}
64
63
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 {
72
65
// 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.
73
66
// Will try to refactor this in the future.
74
67
if ! strings .HasPrefix (svg , "<svg" ) {
75
68
panic ("Invalid SVG icon" )
76
69
}
77
70
svgID := "svg-mfi-" + name
78
71
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 :])
82
74
}
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>` )
86
76
}
87
77
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 {
89
79
if m .rules == nil {
90
80
return BasicThemeIcon (entry )
91
81
}
@@ -110,7 +100,7 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
110
100
case entry .IsSubModule ():
111
101
extraClass = "octicon-file-submodule"
112
102
}
113
- return m .renderFileIconSVG (ctx , name , iconSVG , extraClass )
103
+ return m .renderFileIconSVG (p , name , iconSVG , extraClass )
114
104
}
115
105
// TODO: use an interface or wrapper for git.Entry to make the code testable.
116
106
return BasicThemeIcon (entry )
0 commit comments