mirror of https://github.com/go-gitea/gitea.git
Add old svg class name to git entry icon (#33884)
Fix https://github.com/go-gitea/gitea/pull/33837#discussion_r1995521288pull/33888/head
parent
cb6b33c9cd
commit
0dfa94edc8
|
@ -62,7 +62,7 @@ func (m *MaterialIconProvider) loadData() {
|
||||||
log.Debug("Loaded material icon rules and SVG images")
|
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()
|
data := ctx.GetData()
|
||||||
renderedSVGs, _ := data["_RenderedSVGs"].(map[string]bool)
|
renderedSVGs, _ := data["_RenderedSVGs"].(map[string]bool)
|
||||||
if renderedSVGs == nil {
|
if renderedSVGs == nil {
|
||||||
|
@ -75,7 +75,7 @@ func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name
|
||||||
panic("Invalid SVG icon")
|
panic("Invalid SVG icon")
|
||||||
}
|
}
|
||||||
svgID := "svg-mfi-" + name
|
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, '>')
|
posOuterBefore := strings.IndexByte(svg, '>')
|
||||||
if renderedSVGs[svgID] && posOuterBefore != -1 {
|
if renderedSVGs[svgID] && posOuterBefore != -1 {
|
||||||
return template.HTML(`<svg ` + svgCommonAttrs + `><use xlink:href="#` + svgID + `"></use></svg>`)
|
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 entry.IsLink() {
|
||||||
if te, err := entry.FollowLink(); err == nil && te.IsDir() {
|
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
|
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)
|
name := m.findIconNameByGit(entry)
|
||||||
if name == "folder" {
|
if name == "folder" {
|
||||||
// the material icon pack's "folder" icon doesn't look good, so use our built-in one
|
// 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 != "" {
|
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")
|
return svg.RenderHTML("octicon-file")
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
fill: currentcolor;
|
fill: currentcolor;
|
||||||
}
|
}
|
||||||
|
|
||||||
.svg.fileicon {
|
.svg.git-entry-icon {
|
||||||
fill: transparent; /* some material icons have dark background fill, so need to reset */
|
fill: transparent; /* some material icons have dark background fill, so need to reset */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue