aboutsummaryrefslogtreecommitdiffstats
path: root/modules/fileicon/material.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2025-03-14 23:11:29 +0800
committerGitHub <noreply@github.com>2025-03-14 23:11:29 +0800
commit0dfa94edc8476c4227d46557ed81825388fd37fb (patch)
treecafaf9a268b1f5b267ffeb83eb6bd38e39c58706 /modules/fileicon/material.go
parentcb6b33c9cd1efa619351a458e2bce8ad1e6cd623 (diff)
downloadgitea-0dfa94edc8476c4227d46557ed81825388fd37fb.tar.gz
gitea-0dfa94edc8476c4227d46557ed81825388fd37fb.zip
Add old svg class name to git entry icon (#33884)
Fix https://github.com/go-gitea/gitea/pull/33837#discussion_r1995521288
Diffstat (limited to 'modules/fileicon/material.go')
-rw-r--r--modules/fileicon/material.go20
1 files changed, 15 insertions, 5 deletions
diff --git a/modules/fileicon/material.go b/modules/fileicon/material.go
index adea625c06..aa31cd8d7c 100644
--- a/modules/fileicon/material.go
+++ b/modules/fileicon/material.go
@@ -62,7 +62,7 @@ func (m *MaterialIconProvider) loadData() {
log.Debug("Loaded material icon rules and SVG images")
}
-func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name, svg string) template.HTML {
+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 {
@@ -75,7 +75,7 @@ func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name
panic("Invalid SVG icon")
}
svgID := "svg-mfi-" + name
- svgCommonAttrs := `class="svg fileicon" width="16" height="16" aria-hidden="true"`
+ svgCommonAttrs := `class="svg git-entry-icon ` + extraClass + `" width="16" height="16" aria-hidden="true"`
posOuterBefore := strings.IndexByte(svg, '>')
if renderedSVGs[svgID] && posOuterBefore != -1 {
return template.HTML(`<svg ` + svgCommonAttrs + `><use xlink:href="#` + svgID + `"></use></svg>`)
@@ -92,7 +92,8 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
if entry.IsLink() {
if te, err := entry.FollowLink(); err == nil && te.IsDir() {
- return svg.RenderHTML("material-folder-symlink")
+ // keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
+ return svg.RenderHTML("material-folder-symlink", 16, "octicon-file-directory-symlink")
}
return svg.RenderHTML("octicon-file-symlink-file") // TODO: find some better icons for them
}
@@ -100,10 +101,19 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
name := m.findIconNameByGit(entry)
if name == "folder" {
// the material icon pack's "folder" icon doesn't look good, so use our built-in one
- return svg.RenderHTML("material-folder-generic")
+ // keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
+ return svg.RenderHTML("material-folder-generic", 16, "octicon-file-directory-fill")
}
if iconSVG, ok := m.svgs[name]; ok && iconSVG != "" {
- return m.renderFileIconSVG(ctx, name, iconSVG)
+ // keep the old "octicon-xxx" class name to make some "theme plugin selector" could still work
+ extraClass := "octicon-file"
+ switch {
+ case entry.IsDir():
+ extraClass = "octicon-file-directory-fill"
+ case entry.IsSubModule():
+ extraClass = "octicon-file-submodule"
+ }
+ return m.renderFileIconSVG(ctx, name, iconSVG, extraClass)
}
return svg.RenderHTML("octicon-file")
}