Skip to content

Commit

Permalink
chore: icon work
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Oct 16, 2023
1 parent 2884660 commit c7d0f25
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
9 changes: 4 additions & 5 deletions mknodes/basenodes/mklink.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import TYPE_CHECKING, Any

from mknodes.basenodes import mknode
from mknodes.utils import log, reprhelpers
from mknodes.utils import icons, log, reprhelpers


if TYPE_CHECKING:
Expand Down Expand Up @@ -66,10 +66,9 @@ def __repr__(self):

@property
def icon(self) -> str:
if not self._icon or self._icon.startswith(":"):
return self._icon
icon = self._icon if "/" in self._icon else f"material/{self._icon}"
return f':{icon.replace("/", "-")}:'
if not self._icon:
return ""
return icons.get_emoji_slug(self._icon)

@property
def url(self) -> str:
Expand Down
13 changes: 11 additions & 2 deletions mknodes/utils/icons.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ def get_icon_svg(icon: str) -> str:
get_icon_svg("material/file") # Material-style path
get_icon_svg(":material-file:") # material-style emoji slug
"""
key = get_pyconify_key(icon)
import pyconify

return pyconify.svg(key).decode()


def get_pyconify_key(icon: str):
for k, v in PYCONIFY_TO_PREFIXES.items():
path = f'{v.replace("-", "/")}/'
icon = icon.replace(path, f"{k}:")
Expand All @@ -132,9 +139,11 @@ def get_icon_svg(icon: str) -> str:
icon = icon.strip(":")
if ":" not in icon:
icon = f"mdi:{icon}"
import pyconify
return icon


return pyconify.svg(icon).decode()
def get_emoji_slug(icon):
return f":{get_pyconify_key(icon).replace(':', '-')}:"


def get_icon_xml(icon: str) -> etree.Element:
Expand Down

0 comments on commit c7d0f25

Please sign in to comment.