1
0
This commit is contained in:
syui 2025-05-28 15:21:08 +09:00
parent 8b363bc72e
commit 085ba10a99
Signed by: syui
GPG Key ID: 5417CFEBAD92DF56

58
scpt/fontawesome.py Normal file
View File

@ -0,0 +1,58 @@
import os
import requests
from bs4 import BeautifulSoup
# ▼ ChatGPTに渡す仮のSVG生成今は適当なSVGで代用
def generate_svg_from_name(name):
return f"""
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
<text x="0" y="55" font-size="60">{name[0].upper()}</text>
</svg>
""".strip()
# ▼ 1. Font Awesomeの名前一覧をスクレイピングFont Awesome 6 Free icons
def fetch_fontawesome_names(url="https://fontawesome.com/icons"):
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
icons = soup.select('[class^="fa-"]')
names = set()
for tag in icons:
classes = tag.get("class", [])
for cls in classes:
if cls.startswith("fa-") and not cls.startswith("fa-fw"):
names.add(cls.replace("fa-", ""))
return sorted(names)
# ▼ 2. SVGファイル保存
def save_svgs(icon_names, output_dir="svgs"):
os.makedirs(output_dir, exist_ok=True)
for name in icon_names:
svg = generate_svg_from_name(name)
with open(f"{output_dir}/{name}.svg", "w", encoding="utf-8") as f:
f.write(svg)
# ▼ 3. CSS生成
def generate_css(icon_names, output_file="icons.css"):
lines = [":root {"]
for name in icon_names:
lines.append(f""" --icon-{name}: url("svgs/{name}.svg");""")
lines.append("}\n")
lines.append(".icon { width: 1em; height: 1em; display: inline-block; background-size: contain; background-repeat: no-repeat; }\n")
for name in icon_names:
lines.append(f""".icon-{name} {{ background-image: var(--icon-{name}); }}""")
with open(output_file, "w", encoding="utf-8") as f:
f.write("\n".join(lines))
# ▼ 全自動実行
if __name__ == "__main__":
print("Fetching font names...")
icon_names = fetch_fontawesome_names()
print(f"Found {len(icon_names)} icons")
print("Generating SVGs...")
save_svgs(icon_names[:10]) # ※テストとして10件のみ処理全件だと数百個以上
print("Generating CSS...")
generate_css(icon_names[:10])
print("Complete!")