Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions modules/fileicon/material.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type materialIconRulesData struct {
FileNames map[string]string `json:"fileNames"`
FolderNames map[string]string `json:"folderNames"`
FileExtensions map[string]string `json:"fileExtensions"`
LanguageIDs map[string]string `json:"languageIds"`
}

type MaterialIconProvider struct {
Expand Down Expand Up @@ -107,25 +108,40 @@ func (m *MaterialIconProvider) FileIcon(ctx reqctx.RequestContext, entry *git.Tr
return svg.RenderHTML("octicon-file")
}

func (m *MaterialIconProvider) findIconNameWithLangID(s string) string {
if _, ok := m.svgs[s]; ok {
return s
}
if s, ok := m.rules.LanguageIDs[s]; ok {
if _, ok = m.svgs[s]; ok {
return s
}
}
return ""
}

func (m *MaterialIconProvider) FindIconName(name string, isDir bool) string {
iconsData := m.rules
fileNameLower := strings.ToLower(path.Base(name))
if isDir {
if s, ok := iconsData.FolderNames[fileNameLower]; ok {
if s, ok := m.rules.FolderNames[fileNameLower]; ok {
return s
}
return "folder"
}

if s, ok := iconsData.FileNames[fileNameLower]; ok {
return s
if s, ok := m.rules.FileNames[fileNameLower]; ok {
if s = m.findIconNameWithLangID(s); s != "" {
return s
}
}

for i := len(fileNameLower) - 1; i >= 0; i-- {
if fileNameLower[i] == '.' {
ext := fileNameLower[i+1:]
if s, ok := iconsData.FileExtensions[ext]; ok {
return s
if s, ok := m.rules.FileExtensions[ext]; ok {
if s = m.findIconNameWithLangID(s); s != "" {
return s
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions modules/fileicon/material_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ func TestFindIconName(t *testing.T) {
p := fileicon.DefaultMaterialIconProvider()
assert.Equal(t, "php", p.FindIconName("foo.php", false))
assert.Equal(t, "php", p.FindIconName("foo.PHP", false))
assert.Equal(t, "javascript", p.FindIconName("foo.js", false))
assert.Equal(t, "visualstudio", p.FindIconName("foo.vba", false))
}
296 changes: 197 additions & 99 deletions options/fileicon/material-icon-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -7038,107 +7038,201 @@
"gnu": "gnuplot",
"yaml-tmlanguage": "yaml",
"tmlanguage": "xml",
"git": "git",
"git-commit": "git",
"git-rebase": "git",
"ignore": "git",
"github-actions-workflow": "github-actions-workflow",
"yaml": "yaml",
"spring-boot-properties-yaml": "yaml",
"ansible": "yaml",
"ansible-jinja": "yaml",
"matlab": "matlab",
"makefile": "settings",
"spring-boot-properties": "settings",
"cljx": "clojure",
"clojure": "clojure",
"edn": "clojure",
"cppm": "cpp",
"ccm": "cpp",
"cxxm": "cpp",
"c++m": "cpp",
"ipp": "cpp",
"ixx": "cpp",
"tpp": "cpp",
"txx": "cpp",
"hpp.in": "cpp",
"h.in": "cpp",
"diff": "diff",
"razor": "razor",
"aspnetcorerazor": "razor",
"python": "python",
"javascript": "javascript",
"typescript": "typescript",
"rej": "diff",
"fsscript": "fsharp",
"gitignore_global": "ignore",
"gitignore": "ignore",
"git-blame-ignore-revs": "ignore",
"gvy": "groovy",
"nf": "groovy",
"handlebars": "handlebars",
"perl": "perl",
"perl6": "perl",
"haxe": "haxe",
"hxml": "haxe",
"puppet": "puppet",
"elixir": "elixir",
"livescript": "livescript",
"erlang": "erlang",
"julia": "julia",
"purescript": "purescript",
"stylus": "stylus",
"robotframework": "robot",
"testoutput": "visualstudio",
"solidity": "solidity",
"autoit": "autoit",
"terraform": "terraform",
"cucumber": "cucumber",
"postcss": "postcss",
"lang-cfml": "coldfusion",
"haskell": "haskell",
"ruby": "ruby",
"php": "php",
"hack": "hack",
"javascriptreact": "react",
"processing": "processing",
"django-html": "django",
"django-txt": "django",
"hjs": "handlebars",
"hlsli": "hlsl",
"fx": "hlsl",
"fxh": "hlsl",
"vsh": "hlsl",
"psh": "hlsl",
"cginc": "hlsl",
"compute": "hlsl",
"html": "html",
"gdscript": "godot",
"gdresource": "godot-assets",
"viml": "vim",
"prolog": "prolog",
"pawn": "pawn",
"reason": "reason",
"reason_lisp": "reason",
"doctex": "tex",
"latex": "tex",
"latex-expl3": "tex",
"apex": "salesforce",
"dockercompose": "docker",
"shellscript": "console",
"objective-c": "objective-c",
"objective-cpp": "objective-cpp",
"coffeescript": "coffee",
"fsharp": "fsharp",
"editorconfig": "editorconfig",
"clojure": "clojure",
"pip-requirements": "python-misc",
"vue-postcss": "vue",
"vue-html": "vue",
"bibtex": "lib",
"bibtex-style": "lib",
"jupyter": "jupyter",
"plaintext": "document",
"powershell": "powershell",
"rsweave": "r",
"rust": "rust",
"ssh_config": "lock",
"typescriptreact": "react_ts",
"search-result": "search",
"rescript": "rescript",
"twee3": "twine",
"twee3-harlowe-3": "twine",
"twee3-chapbook-1": "twine",
"twee3-sugarcube-2": "twine",
"grain": "grain",
"lolcode": "lolcode",
"idris": "idris",
"text-gemini": "gemini",
"wolfram": "wolframlanguage",
"shaderlab": "shader",
"cadence": "cadence",
"stylable": "stylable",
"capnb": "cds",
"cds-markdown-injection": "cds",
"concourse-pipeline-yaml": "concourse",
"concourse-task-yaml": "concourse",
"systemd-conf": "systemd",
"systemd-unit-file": "systemd",
"hosts": "hosts",
"ahk2": "ahk2",
"gnuplot": "gnuplot"
"shtml": "html",
"xht": "html",
"aspx": "html",
"jshtm": "html",
"volt": "html",
"rhtml": "html",
"directory": "properties",
"gitattributes": "properties",
"gitconfig": "properties",
"gitmodules": "properties",
"editorconfig": "properties",
"repo": "properties",
"jav": "java",
"js": "javascript",
"es6": "javascript",
"cjs": "javascript",
"pac": "javascript",
"bowerrc": "json",
"jscsrc": "json",
"webmanifest": "json",
"ts.map": "json",
"har": "json",
"jslintrc": "json",
"jsonld": "json",
"geojson": "json",
"vuerc": "json",
"eslintrc": "jsonc",
"eslintrc.json": "jsonc",
"jsfmtrc": "jsonc",
"jshintrc": "jsonc",
"hintrc": "jsonc",
"babelrc": "jsonc",
"jmd": "juliamarkdown",
"cls": "tex",
"bbx": "tex",
"cbx": "tex",
"ctx": "latex",
"mak": "makefile",
"mkd": "markdown",
"mdwn": "markdown",
"mdown": "markdown",
"markdn": "markdown",
"mdtxt": "markdown",
"mdtext": "markdown",
"workbook": "markdown",
"npmignore": "ignore",
"npmrc": "properties",
"m": "objective-c",
"mm": "objective-cpp",
"pod": "perl",
"t": "perl",
"psgi": "perl",
"rakumod": "raku",
"rakutest": "raku",
"rakudoc": "raku",
"nqp": "raku",
"p6": "raku",
"pl6": "raku",
"pm6": "raku",
"php": "php",
"php4": "php",
"php5": "php",
"phtml": "php",
"ctp": "php",
"psrc": "powershell",
"rpy": "python",
"pyw": "python",
"cpy": "python",
"gyp": "python",
"gypi": "python",
"pyi": "python",
"ipy": "python",
"pyt": "python",
"rhistory": "r",
"rprofile": "r",
"rt": "r",
"razor": "razor",
"rbx": "ruby",
"rjs": "ruby",
"gemspec": "ruby",
"rake": "ruby",
"ru": "ruby",
"podspec": "ruby",
"rbi": "ruby",
"bashrc": "shellscript",
"bash_aliases": "shellscript",
"bash_profile": "shellscript",
"bash_login": "shellscript",
"ebuild": "shellscript",
"eclass": "shellscript",
"profile": "shellscript",
"bash_logout": "shellscript",
"xprofile": "shellscript",
"xsession": "shellscript",
"xsessionrc": "shellscript",
"zshrc": "shellscript",
"zprofile": "shellscript",
"zlogin": "shellscript",
"zlogout": "shellscript",
"zshenv": "shellscript",
"zsh-theme": "shellscript",
"cshrc": "shellscript",
"tcshrc": "shellscript",
"yashrc": "shellscript",
"yash_profile": "shellscript",
"dsql": "sql",
"ts": "typescript",
"cts": "typescript",
"mts": "typescript",
"brs": "vb",
"bas": "vb",
"vba": "vb",
"ascx": "xml",
"atom": "xml",
"axml": "xml",
"axaml": "xml",
"bpmn": "xml",
"csl": "xml",
"csproj.user": "xml",
"dita": "xml",
"ditamap": "xml",
"ent": "xml",
"dtml": "xml",
"fxml": "xml",
"isml": "xml",
"jmx": "xml",
"launch": "xml",
"menu": "xml",
"nuspec": "xml",
"opml": "xml",
"owl": "xml",
"proj": "xml",
"pt": "xml",
"publishsettings": "xml",
"pubxml": "xml",
"pubxml.user": "xml",
"rdf": "xml",
"rng": "xml",
"rss": "xml",
"shproj": "xml",
"storyboard": "xml",
"targets": "xml",
"tld": "xml",
"tmx": "xml",
"vbproj": "xml",
"vbproj.user": "xml",
"wsdl": "xml",
"wxi": "xml",
"wxl": "xml",
"wxs": "xml",
"xbl": "xml",
"xib": "xml",
"xliff": "xml",
"xpdl": "xml",
"xul": "xml",
"xoml": "xml",
"yaml": "yaml",
"yml": "yaml",
"eyaml": "yaml",
"eyml": "yaml",
"cff": "yaml",
"yaml-tmpreferences": "yaml",
"yaml-tmtheme": "yaml",
"winget": "yaml"
},
"fileNames": {
".pug-lintrc": "pug",
Expand Down Expand Up @@ -9015,7 +9109,11 @@
"caddyfile": "caddy",
"pklproject": "pkl",
"pklproject.deps.json": "pkl",
".github/funding.yml": "github-sponsors"
".github/funding.yml": "github-sponsors",
"language-configuration.json": "jsonc",
"icon-theme.json": "jsonc",
"color-theme.json": "jsonc",
"*.log.?": "log"
},
"languageIds": {
"git": "git",
Expand Down
Loading