FlorianWoelki / obsidian-iconize

Simply add icons to anything you want in Obsidian.
https://florianwoelki.github.io/obsidian-iconize/
MIT License
862 stars 59 forks source link

Icons are stored without normalization in data.json and therefore are not shown in UI #158

Closed AlexanderMelde closed 1 year ago

AlexanderMelde commented 1 year ago

Describe the bug Icons are sometimes not shown in the UI

To Reproduce Steps to reproduce the behavior:

  1. Fresh install the plugin
  2. Download fontawesome-solid
  3. Set some folder and note icons, works fine
  4. close and restart obsidian
  5. some of the icons are no longer shown

Expected behavior All icons should be shown, even after restart.

Possible cause of error Only icons that have a hyphen or underscore are not shown, so it is likely to be caused by the icon name normalization.

Suggested Fix Inside data.json replace underscores and hyphens with empty string followed by capitalized next letter, e.g. from

  "x1": "FasChalkboard-user",
  "x2": "FasUser-group",
  "x3": "FasBook",
  "x4": "FasCity",
  "x5": "FasDesktop",
  "x6": "FasCalendar-week",
  "x7": "FasCalendar-days",
  "x8": "FasImages",
  "x9": "FasH",
  "x10": "FasDiagram-project",
  "x11": "FasQ",
  "x12": "FasK",
  "x13": "FasBook-open",
  "x14": "FasDatabase",
  "x15": "FasI"

to

  "x1": "FasChalkboardUser",
  "x2": "FasUserGroup",
  "x3": "FasBook",
  "x4": "FasCity",
  "x5": "FasDesktop",
  "x6": "FasCalendarWeek",
  "x7": "FasCalendarDays",
  "x8": "FasImages",
  "x9": "FasH",
  "x10": "FasDiagramProject",
  "x11": "FasQ",
  "x12": "FasK",
  "x13": "FasBookOpen",
  "x14": "FasDatabase",
  "x15": "FasI"

(folder and file names censored for privacy reasons)

Additional context Operating System: Windows 11 Obsidian V: 1.1.16 Icon Folder V: 1.7.0

Screenshots image

FlorianWoelki commented 1 year ago

Unfortunately, I cannot reproduce this issue. I am always testing this with RPG-Awesome, and everything works fine for me. Icons are recognized even with a - inside their name.

AlexanderMelde commented 1 year ago

I am using the version of "fontawesome-solid" that can be downloaded via the option page.

Just so that i understand you correctly, the intended behaviour is to have

Or does your example imply that with RPG-Awesome, filenames contain the -?

gossamerephermal commented 1 year ago

This sounds like a variation of the issue I submitted, except in my case the icon pack itself goes missing from the plugin list on relaunching obsidian, though is still recognized as existing when I try to readd it and have to remove and manually add it through the plugin. I only get a "you have to create an icon pack" message when trying to select icons, and none are shown. And yet the vault items that have icons set prior to relaunch still display.

There's no hyphens or uppercase characters in the folder/filenames, but disappearing on relaunch might be related.

Do the missing icons on your issue still display after relaunch, if you set them prior?

FlorianWoelki commented 1 year ago

Yes, I was testing the same functionality with the downloaded solid fontawesome pack.

When I download the fontawesome solid pack, I don't have any - in the icon names (same for the data.json, when I set an icon).

So basically, no matter what the name of the icon is, it should directly match in the dom.

This sounds like a variation of the issue I submitted, except in my case the icon pack itself goes missing from the plugin list on relaunching obsidian, though is still recognized as existing when I try to readd it and have to remove and manually add it through the plugin. I only get a "you have to create an icon pack" message when trying to select icons, and none are shown. And yet the vault items that have icons set prior to relaunch still display.

There's no hyphens or uppercase characters in the folder/filenames, but disappearing on relaunch might be related.

Do the missing icons on your issue still display after relaunch, if you set them prior?

I think, it would be really good if you can create a minimal reproduction version of your vault (discard all the personal files, plugins etc.), so that I can reproduce it.

AlexanderMelde commented 1 year ago

When I download the fontawesome solid pack, I don't have any - in [...] the data.json, when I set an icon

Wow, I did not expect that. On my two different vaults on different systems, every fontawesome icon is saved to data.json with the - in the name.

it would be really good if you can create a minimal reproduction version of your vault

Done! I just created an empty vault, put some notes in it, downloaded your plugin, downloaded fontawesome-solid, set icons to folders and notes, closed obsidian, opened obisidian - error is here 😄

Before re-opening Obsidian: image

After: image

data.json:

{
  "settings": {
    "migrated": true,
    "iconPacksPath": ".obsidian/plugins/obsidian-icon-folder/icons",
    "fontSize": 16,
    "emojiStyle": "none",
    "iconColor": null,
    "recentlyUsedIcons": [
      "FasBriefcase-medical",
      "FasArrows-up-down-left-right",
      "FasBattery-three-quarters"
    ],
    "recentlyUsedIconsSize": 5,
    "rules": [],
    "extraMargin": {
      "top": 0,
      "right": 4,
      "bottom": 0,
      "left": 0
    }
  },
  "Note in Folder.md": "FasBattery-three-quarters",
  "Example Folder/Note in Root.md": "FasArrows-up-down-left-right",
  "Example Folder": "FasBriefcase-medical"
}

After this observation, i deleted all non-relevant icons (there were over 1100 downloaded) to reduce vault size and put the whole vault into the attached .zip file icontest.zip.

FlorianWoelki commented 1 year ago

Ok beautiful, now I can reproduce this as well, thanks for the reproduction. I've tested this on my Dev Fault and could reproduce it as well. I'll try to provide a fix today.

It also seems like that the bug only appears the first time when you download something like Fas and then immediately change the icon. If you download Fas and then restart obsidian, it will work :D

FlorianWoelki commented 1 year ago

Ok, thanks for reporting. I've now fixed the issue. You can check out the main branch with the current code to check, if everything works. However, I've changed a lot of things in the codebase compared to the last update. So be aware that there could be some other potential bugs.

FlorianWoelki commented 1 year ago

This should be fixed in 2.0.0.