Skip to content

Commit f11c4cc

Browse files
committed
enhance
1 parent 458de74 commit f11c4cc

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

modules/fileicon/fileicon.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,35 @@ func getBasicFileIconName(entry *git.TreeEntry) string {
4545
return "octicon-file"
4646
}
4747

48+
// getFileIconNames returns a list of possible icon names for a file or directory
49+
// Folder named `sub-folder` =>
50+
// - `folder_sub-folder“ (. will be replaced with _)
51+
// - `folder`
52+
//
53+
// File named `.gitignore` =>
54+
// - `file__gitignore` (. will be replaced with _)
55+
// - `file_`
56+
//
57+
// File named `README.md` =>
58+
// - `file_readme_md`
59+
// - `file_md`
4860
func getFileIconNames(entry *git.TreeEntry) []string {
49-
fileName := strings.ToLower(path.Base(entry.Name()))
61+
fileName := strings.ReplaceAll(strings.ToLower(path.Base(entry.Name())), ".", "_")
5062

5163
if entry.IsDir() {
5264
return []string{"folder_" + fileName, "folder"}
5365
}
5466

5567
if entry.IsRegular() {
56-
ext := strings.ToLower(strings.TrimPrefix(path.Ext(fileName), "."))
68+
ext := strings.ToLower(strings.TrimPrefix(path.Ext(entry.Name()), "."))
5769
return []string{"file_" + fileName, "file_" + ext, "file"}
5870
}
5971

6072
return nil
6173
}
6274

6375
func loadCustomIcon(iconPath string) (string, error) {
64-
log.Info("Loading custom icon from %s", iconPath)
76+
log.Debug("Loading custom icon from %s", iconPath)
6577

6678
if icon, ok := fileIconCache.Get(iconPath); ok {
6779
return icon, nil

0 commit comments

Comments
 (0)