Skip to content

Instantly share code, notes, and snippets.

@will-ockmore
Last active December 15, 2023 19:09
Show Gist options
  • Save will-ockmore/ba63447cd8866ebd8b9f4268ff3b8d95 to your computer and use it in GitHub Desktop.
Save will-ockmore/ba63447cd8866ebd8b9f4268ff3b8d95 to your computer and use it in GitHub Desktop.
Script to convert the full-width icons and pictograms to component entries
import os
import re
import sys
from pathlib import Path
dir_path = Path(sys.argv[1] if len(sys.argv) > 1 else ".").resolve()
numbers = {
"1": "One",
"2": "Two",
"3": "Three",
}
for filename in os.listdir(dir_path):
# Icons are named like Wayflyer_Icons_24px_20231213 copy_x-circle.svg
if filename.endswith(".svg"):
if filename.startswith("Wayflyer_Icons_24px_"):
icon_name = (
filename.split()[-1]
.removeprefix("copy_")
.removesuffix(".svg")
.replace("-", " ")
.title()
.replace(" ", "")
)
if icon_name.isnumeric():
icon_name = numbers[icon_name]
with open(dir_path / filename, "r") as f:
svg = re.sub(
r'width="\d+" height="\d+" fill="none"',
'className={cn("w-6 h-6", props.className)} {...props}',
f.read(),
)
print(f"{icon_name}: (props: CustomIconProps) => ({svg}),")
# Pictograms are named like Wayflyer_Pictograms_32px_20231213_Working Capital.svg
if filename.startswith("Wayflyer_Pictograms_32px"):
pictogram_name = (
re.sub(r"Wayflyer_Pictograms_32px_\d+_", "", filename)
.removesuffix(".svg")
.replace("-", " ")
.replace("_", " ")
.title()
.replace(" ", "")
)
if pictogram_name.isnumeric():
pictogram_name = numbers[pictogram_name]
with open(dir_path / filename, "r") as f:
svg = re.sub(
r'width="\d+" height="\d+" fill="none"',
'className={cn("w-6 h-6", props.className)} {...props}',
f.read(),
)
print(f"{pictogram_name}: (props: CustomPictogramProps) => ({svg}),")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment