Skip to content

Commit ffae59a

Browse files
committed
fix
1 parent c102492 commit ffae59a

File tree

7 files changed

+216
-3270
lines changed

7 files changed

+216
-3270
lines changed

modules/fileicon/material.go

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ import (
1818
)
1919

2020
type materialIconRulesData struct {
21-
IconDefinitions map[string]*struct {
22-
IconPath string `json:"iconPath"`
23-
} `json:"iconDefinitions"`
2421
FileNames map[string]string `json:"fileNames"`
2522
FolderNames map[string]string `json:"folderNames"`
2623
FileExtensions map[string]string `json:"fileExtensions"`
@@ -36,6 +33,7 @@ type MaterialIconProvider struct {
3633
var materialIconProvider MaterialIconProvider
3734

3835
func DefaultMaterialIconProvider() *MaterialIconProvider {
36+
materialIconProvider.once.Do(materialIconProvider.loadData)
3937
return &materialIconProvider
4038
}
4139

@@ -88,8 +86,6 @@ func (m *MaterialIconProvider) renderFileIconSVG(ctx reqctx.RequestContext, name
8886
}
8987

9088
func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.TreeEntry) template.HTML {
91-
m.once.Do(m.loadData)
92-
9389
if m.rules == nil {
9490
return BasicThemeIcon(entry)
9591
}
@@ -101,7 +97,7 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
10197
return svg.RenderHTML("octicon-file-symlink-file") // TODO: find some better icons for them
10298
}
10399

104-
name := m.findIconName(entry)
100+
name := m.findIconNameByGit(entry)
105101
if name == "folder" {
106102
// the material icon pack's "folder" icon doesn't look good, so use our built-in one
107103
return svg.RenderHTML("material-folder-generic")
@@ -112,34 +108,23 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
112108
return svg.RenderHTML("octicon-file")
113109
}
114110

115-
func (m *MaterialIconProvider) findIconName(entry *git.TreeEntry) string {
116-
if entry.IsSubModule() {
117-
return "folder-git"
118-
}
119-
111+
func (m *MaterialIconProvider) FindIconName(name string, isDir bool) string {
120112
iconsData := m.rules
121-
fileName := path.Base(entry.Name())
122-
123-
if entry.IsDir() {
124-
if s, ok := iconsData.FolderNames[fileName]; ok {
125-
return s
126-
}
127-
if s, ok := iconsData.FolderNames[strings.ToLower(fileName)]; ok {
113+
fileNameLower := strings.ToLower(path.Base(name))
114+
if isDir {
115+
if s, ok := iconsData.FolderNames[fileNameLower]; ok {
128116
return s
129117
}
130118
return "folder"
131119
}
132120

133-
if s, ok := iconsData.FileNames[fileName]; ok {
134-
return s
135-
}
136-
if s, ok := iconsData.FileNames[strings.ToLower(fileName)]; ok {
121+
if s, ok := iconsData.FileNames[fileNameLower]; ok {
137122
return s
138123
}
139124

140-
for i := len(fileName) - 1; i >= 0; i-- {
141-
if fileName[i] == '.' {
142-
ext := fileName[i+1:]
125+
for i := len(fileNameLower) - 1; i >= 0; i-- {
126+
if fileNameLower[i] == '.' {
127+
ext := fileNameLower[i+1:]
143128
if s, ok := iconsData.FileExtensions[ext]; ok {
144129
return s
145130
}
@@ -148,3 +133,10 @@ func (m *MaterialIconProvider) findIconName(entry *git.TreeEntry) string {
148133

149134
return "file"
150135
}
136+
137+
func (m *MaterialIconProvider) findIconNameByGit(entry *git.TreeEntry) string {
138+
if entry.IsSubModule() {
139+
return "folder-git"
140+
}
141+
return m.FindIconName(entry.Name(), entry.IsDir())
142+
}

modules/fileicon/material_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package fileicon_test
2+
3+
import (
4+
"testing"
5+
6+
"code.gitea.io/gitea/models/unittest"
7+
"code.gitea.io/gitea/modules/fileicon"
8+
9+
"github.com/stretchr/testify/assert"
10+
)
11+
12+
func TestMain(m *testing.M) {
13+
unittest.MainTest(m, &unittest.TestOptions{FixtureFiles: []string{}})
14+
}
15+
16+
func TestFindIconName(t *testing.T) {
17+
unittest.PrepareTestEnv(t)
18+
p := fileicon.DefaultMaterialIconProvider()
19+
assert.Equal(t, "php", p.FindIconName("foo.php", false))
20+
assert.Equal(t, "php", p.FindIconName("foo.PHP", false))
21+
}

modules/git/commit_info_nogogit.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
6565
log.Debug("missing commit for %s", entry.Name())
6666
}
6767

68-
// If the entry if a submodule add a submodule file for this
68+
// If the entry is a submodule add a submodule file for this
6969
if entry.IsSubModule() {
7070
subModuleURL := ""
7171
var fullPath string
@@ -85,8 +85,8 @@ func (tes Entries) GetCommitsInfo(ctx context.Context, commit *Commit, treePath
8585
}
8686

8787
// Retrieve the commit for the treePath itself (see above). We basically
88-
// get it for free during the tree traversal and it's used for listing
89-
// pages to display information about newest commit for a given path.
88+
// get it for free during the tree traversal, and it's used for listing
89+
// pages to display information about the newest commit for a given path.
9090
var treeCommit *Commit
9191
var ok bool
9292
if treePath == "" {

0 commit comments

Comments
 (0)