Skip to content

Commit

Permalink
fix: issue with background checker for icon names that are not normal…
Browse files Browse the repository at this point in the history
…ized
  • Loading branch information
FlorianWoelki committed Oct 8, 2023
1 parent 25a52f0 commit cf51b6c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
13 changes: 8 additions & 5 deletions src/iconPackManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,9 @@ export const getIconFromIconPack = (iconPackName: string, iconName: string) => {
return undefined;
}

return iconPack.icons.find((icon) => icon.name === iconName);
return iconPack.icons.find(
(icon) => getNormalizedName(icon.name) === iconName,
);
};

export const getSvgFromLoadedIcon = (
Expand All @@ -576,11 +578,12 @@ export const getSvgFromLoadedIcon = (
);
if (!foundIcon) {
iconPacks.forEach((iconPack) => {
const icon = iconPack.icons.find(
(icon) =>
const icon = iconPack.icons.find((icon) => {
return (
icon.prefix.toLowerCase() === iconPrefix.toLowerCase() &&
icon.name.toLowerCase() === iconName.toLowerCase(),
);
getNormalizedName(icon.name).toLowerCase() === iconName.toLowerCase()
);
});
if (icon) {
foundIcon = icon;
}
Expand Down
22 changes: 13 additions & 9 deletions src/lib/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,18 @@ import customRule from './customRule';
import dom from './util/dom';
import iconTabs from './iconTabs';
import inheritance from './inheritance';
import {
getFileItemInnerTitleEl,
getFileItemTitleEl,
removeIconFromIconPack,
} from '../util';
import { getFileItemInnerTitleEl, getFileItemTitleEl } from '../util';
import {
Icon,
createIconPackPrefix,
extractIconToIconPack,
getAllIconPacks,
getIconFromIconPack,
getIconPackNameByPrefix,
getNormalizedName,
getPath,
getSvgFromLoadedIcon,
nextIdentifier,
} from '../iconPackManager';
import { CustomRule } from '../settings/data';
import config from '@app/config';
import { Notice } from 'obsidian';

Expand Down Expand Up @@ -114,12 +109,13 @@ const checkMissingIcons = async (

// Iterates over all the missing icons with its path and adds the icon to the node.
for (const icon of missingIcons) {
const normalizedName = getNormalizedName(icon.prefix + icon.name);
const nodesWithIcon = document.querySelectorAll(
`[${config.ICON_ATTRIBUTE_NAME}="${icon.prefix + icon.name}"]`,
`[${config.ICON_ATTRIBUTE_NAME}="${normalizedName}"]`,
);

nodesWithIcon.forEach((node: HTMLElement) => {
dom.setIconForNode(plugin, icon.prefix + icon.name, node);
dom.setIconForNode(plugin, normalizedName, node);
});
}

Expand All @@ -133,6 +129,14 @@ const checkMissingIcons = async (

// Remove all icon files that can not be found in the data.
for (const iconPack of getAllIconPacks()) {
// Checks if the icon pack exists.
const doesIconPackExist = await plugin.app.vault.adapter.exists(
`${getPath()}/${iconPack.name}`,
);
if (!doesIconPackExist) {
continue;
}

const iconFiles = await plugin.app.vault.adapter.list(
`${getPath()}/${iconPack.name}`,
);
Expand Down

0 comments on commit cf51b6c

Please sign in to comment.