mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2025-06-28 07:20:21 +08:00
refactor(ci): enhance URL extraction
This commit is contained in:
parent
8d087c04eb
commit
bab7a2165a
@ -28,10 +28,10 @@ class Icon:
|
|||||||
"author": author
|
"author": author
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def convertions(self) -> list[IconConvertion]:
|
def convertions(self) -> list[IconConvertion]:
|
||||||
raise NotImplementedError("Method 'files' must be implemented in subclass")
|
raise NotImplementedError("Method 'files' must be implemented in subclass")
|
||||||
|
|
||||||
|
|
||||||
class NormalIcon(Icon):
|
class NormalIcon(Icon):
|
||||||
def __init__(self, icon: str, name: str, type: str, categories: list, aliases: list):
|
def __init__(self, icon: str, name: str, type: str, categories: list, aliases: list):
|
||||||
@ -42,7 +42,7 @@ class NormalIcon(Icon):
|
|||||||
return [
|
return [
|
||||||
IconConvertion(self.name, self.icon)
|
IconConvertion(self.name, self.icon)
|
||||||
]
|
]
|
||||||
|
|
||||||
def from_addition_issue_form(input: dict):
|
def from_addition_issue_form(input: dict):
|
||||||
return NormalIcon(
|
return NormalIcon(
|
||||||
mapUrlFromMarkdownImage(input, "Paste icon"),
|
mapUrlFromMarkdownImage(input, "Paste icon"),
|
||||||
@ -51,13 +51,13 @@ class NormalIcon(Icon):
|
|||||||
mapListFrom(input, "Categories"),
|
mapListFrom(input, "Categories"),
|
||||||
mapListFrom(input, "Aliases")
|
mapListFrom(input, "Aliases")
|
||||||
)
|
)
|
||||||
|
|
||||||
def from_update_issue_form(input: dict):
|
def from_update_issue_form(input: dict):
|
||||||
try:
|
try:
|
||||||
name = convert_to_kebab_case(mapFromRequired(input, "Icon name"))
|
name = convert_to_kebab_case(mapFromRequired(input, "Icon name"))
|
||||||
metadata = load_metadata(name)
|
metadata = load_metadata(name)
|
||||||
|
|
||||||
|
|
||||||
return NormalIcon(
|
return NormalIcon(
|
||||||
mapUrlFromMarkdownImage(input, "Paste icon"),
|
mapUrlFromMarkdownImage(input, "Paste icon"),
|
||||||
mapFromRequired(input, "Icon name"),
|
mapFromRequired(input, "Icon name"),
|
||||||
@ -67,11 +67,11 @@ class NormalIcon(Icon):
|
|||||||
)
|
)
|
||||||
except Exception as exeption:
|
except Exception as exeption:
|
||||||
raise ValueError(f"Icon '{name}' does not exist", exeption)
|
raise ValueError(f"Icon '{name}' does not exist", exeption)
|
||||||
|
|
||||||
def from_metadata_update_issue_form(input: dict):
|
def from_metadata_update_issue_form(input: dict):
|
||||||
name = convert_to_kebab_case(mapFromRequired(input, "Icon name"))
|
name = convert_to_kebab_case(mapFromRequired(input, "Icon name"))
|
||||||
metadata = load_metadata(name)
|
metadata = load_metadata(name)
|
||||||
|
|
||||||
return NormalIcon(
|
return NormalIcon(
|
||||||
None,
|
None,
|
||||||
name,
|
name,
|
||||||
@ -80,14 +80,14 @@ class NormalIcon(Icon):
|
|||||||
mapListFrom(input, "Aliases")
|
mapListFrom(input, "Aliases")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MonochromeIcon(Icon):
|
class MonochromeIcon(Icon):
|
||||||
def __init__(self, lightIcon: str, darkIcon: str, name: str, type: str, categories: list, aliases: list):
|
def __init__(self, lightIcon: str, darkIcon: str, name: str, type: str, categories: list, aliases: list):
|
||||||
super().__init__(name, type, categories, aliases)
|
super().__init__(name, type, categories, aliases)
|
||||||
self.lightIcon = lightIcon
|
self.lightIcon = lightIcon
|
||||||
self.darkIcon = darkIcon
|
self.darkIcon = darkIcon
|
||||||
|
|
||||||
def to_colors(self) -> dict:
|
def to_colors(self) -> dict:
|
||||||
try:
|
try:
|
||||||
metadata = load_metadata(self.name)
|
metadata = load_metadata(self.name)
|
||||||
@ -105,14 +105,14 @@ class MonochromeIcon(Icon):
|
|||||||
metadata = super().to_metadata(author)
|
metadata = super().to_metadata(author)
|
||||||
metadata["colors"] = self.to_colors()
|
metadata["colors"] = self.to_colors()
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
def convertions(self) -> list[IconConvertion]:
|
def convertions(self) -> list[IconConvertion]:
|
||||||
colorNames = self.to_colors()
|
colorNames = self.to_colors()
|
||||||
return [
|
return [
|
||||||
IconConvertion(colorNames["light"], self.lightIcon),
|
IconConvertion(colorNames["light"], self.lightIcon),
|
||||||
IconConvertion(colorNames["dark"], self.darkIcon),
|
IconConvertion(colorNames["dark"], self.darkIcon),
|
||||||
]
|
]
|
||||||
|
|
||||||
def from_addition_issue_form(input: dict):
|
def from_addition_issue_form(input: dict):
|
||||||
return MonochromeIcon(
|
return MonochromeIcon(
|
||||||
mapUrlFromMarkdownImage(input, "Paste light mode icon"),
|
mapUrlFromMarkdownImage(input, "Paste light mode icon"),
|
||||||
@ -122,12 +122,12 @@ class MonochromeIcon(Icon):
|
|||||||
mapListFrom(input, "Categories"),
|
mapListFrom(input, "Categories"),
|
||||||
mapListFrom(input, "Aliases")
|
mapListFrom(input, "Aliases")
|
||||||
)
|
)
|
||||||
|
|
||||||
def from_update_issue_form(input: dict):
|
def from_update_issue_form(input: dict):
|
||||||
try:
|
try:
|
||||||
name = convert_to_kebab_case(mapFromRequired(input, "Icon name"))
|
name = convert_to_kebab_case(mapFromRequired(input, "Icon name"))
|
||||||
metadata = load_metadata(name)
|
metadata = load_metadata(name)
|
||||||
|
|
||||||
return MonochromeIcon(
|
return MonochromeIcon(
|
||||||
mapUrlFromMarkdownImage(input, "Paste light mode icon"),
|
mapUrlFromMarkdownImage(input, "Paste light mode icon"),
|
||||||
mapUrlFromMarkdownImage(input, "Paste dark mode icon"),
|
mapUrlFromMarkdownImage(input, "Paste dark mode icon"),
|
||||||
@ -138,11 +138,11 @@ class MonochromeIcon(Icon):
|
|||||||
)
|
)
|
||||||
except Exception as exeption:
|
except Exception as exeption:
|
||||||
raise ValueError(f"Icon '{name}' does not exist", exeption)
|
raise ValueError(f"Icon '{name}' does not exist", exeption)
|
||||||
|
|
||||||
def from_metadata_update_issue_form(input: dict):
|
def from_metadata_update_issue_form(input: dict):
|
||||||
name = convert_to_kebab_case(mapFromRequired(input, "Icon name"))
|
name = convert_to_kebab_case(mapFromRequired(input, "Icon name"))
|
||||||
metadata = load_metadata(name)
|
metadata = load_metadata(name)
|
||||||
|
|
||||||
return MonochromeIcon(
|
return MonochromeIcon(
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
@ -213,10 +213,19 @@ def mapListFrom(input: dict, label: str) -> list:
|
|||||||
return []
|
return []
|
||||||
return list(map(str.strip, stringList.split(",")))
|
return list(map(str.strip, stringList.split(",")))
|
||||||
|
|
||||||
def mapUrlFromMarkdownImage(input: dict, label: str) -> re.Match[str]:
|
def mapUrlFromMarkdownImage(input: dict, label: str) -> str:
|
||||||
markdown = mapFromRequired(input, label)
|
markdown_or_html = mapFromRequired(input, label)
|
||||||
try:
|
|
||||||
return re.match(r"!\[[^\]]+\]\((https:[^\)]+)\)", markdown)[1]
|
# Try Markdown format: 
|
||||||
except IndexError:
|
markdown_match = re.match(r"!\[[^\]]*\]\((https:[^\)]+)\)", markdown_or_html)
|
||||||
raise ValueError(f"Invalid markdown image: '{markdown}'")
|
if markdown_match:
|
||||||
|
return markdown_match[1]
|
||||||
|
|
||||||
|
# Try HTML format: <img src="url" ...>
|
||||||
|
html_match = re.search(r"<img[^>]+src=\"(https:[^\"]+)\"", markdown_or_html)
|
||||||
|
if html_match:
|
||||||
|
return html_match[1]
|
||||||
|
|
||||||
|
# If neither matches
|
||||||
|
raise ValueError(f"Could not extract URL from '{label}'. Expected Markdown image or HTML img tag, but got: '{markdown_or_html}'")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user