mirror of
https://github.com/go-gitea/gitea.git
synced 2025-06-29 04:29:55 +00:00
Fix file icon mapping (#33855)
Use the file extension mapping from VSCode's extensions. Otherwise js/ts/vba/... files won't get correct icons.
This commit is contained in:
parent
608ccc32e5
commit
f61f30153b
5 changed files with 811 additions and 110 deletions
|
@ -63,17 +63,32 @@ async function processMaterialFileIcons() {
|
|||
}
|
||||
fs.writeFileSync(fileURLToPath(new URL(`../options/fileicon/material-icon-svgs.json`, import.meta.url)), JSON.stringify(svgSymbols, null, 2));
|
||||
|
||||
const vscodeExtensionsJson = await readFile(fileURLToPath(new URL(`generate-svg-vscode-extensions.json`, import.meta.url)));
|
||||
const vscodeExtensions = JSON.parse(vscodeExtensionsJson);
|
||||
const iconRulesJson = await readFile(fileURLToPath(new URL(`../node_modules/material-icon-theme/dist/material-icons.json`, import.meta.url)));
|
||||
const iconRules = JSON.parse(iconRulesJson);
|
||||
// The rules are from VSCode material-icon-theme, we need to adjust them to our needs
|
||||
// 1. We only use lowercase filenames to match (it should be good enough for most cases and more efficient)
|
||||
// 2. We do not have a "Language ID" system: https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers
|
||||
// * So we just treat the "Language ID" as file extension, it is not always true, but it is good enough for most cases.
|
||||
// 2. We do not have a "Language ID" system:
|
||||
// * https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers
|
||||
// * https://github.com/microsoft/vscode/tree/1.98.0/extensions
|
||||
delete iconRules.iconDefinitions;
|
||||
for (const [k, v] of Object.entries(iconRules.fileNames)) iconRules.fileNames[k.toLowerCase()] = v;
|
||||
for (const [k, v] of Object.entries(iconRules.folderNames)) iconRules.folderNames[k.toLowerCase()] = v;
|
||||
for (const [k, v] of Object.entries(iconRules.fileExtensions)) iconRules.fileExtensions[k.toLowerCase()] = v;
|
||||
for (const [k, v] of Object.entries(iconRules.languageIds)) iconRules.fileExtensions[k.toLowerCase()] = v;
|
||||
// Use VSCode's "Language ID" mapping from its extensions
|
||||
for (const [_, langIdExtMap] of Object.entries(vscodeExtensions)) {
|
||||
for (const [langId, names] of Object.entries(langIdExtMap)) {
|
||||
for (const name of names) {
|
||||
const nameLower = name.toLowerCase();
|
||||
if (nameLower[0] === '.') {
|
||||
iconRules.fileExtensions[nameLower.substring(1)] ??= langId;
|
||||
} else {
|
||||
iconRules.fileNames[nameLower] ??= langId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const iconRulesPretty = JSON.stringify(iconRules, null, 2);
|
||||
fs.writeFileSync(fileURLToPath(new URL(`../options/fileicon/material-icon-rules.json`, import.meta.url)), iconRulesPretty);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue