mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(icons): replace inline SVGs with consistent JSX properties for icons
This commit is contained in:
@@ -36,6 +36,15 @@ export type PerWidgetSettings = {
|
|||||||
const esc = (s: string) => s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"')
|
const esc = (s: string) => s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"')
|
||||||
const font = '-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif'
|
const font = '-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif'
|
||||||
|
|
||||||
|
const TAG_ACRONYMS = new Set(['ml','ai','ui','ux','api','cli','sql','css','html','js','ios'])
|
||||||
|
function formatTagLabel(tag: string): string {
|
||||||
|
return tag.split('-')
|
||||||
|
.map(w => TAG_ACRONYMS.has(w.toLowerCase())
|
||||||
|
? w.toUpperCase()
|
||||||
|
: w.charAt(0).toUpperCase() + w.slice(1))
|
||||||
|
.join(' ')
|
||||||
|
}
|
||||||
|
|
||||||
function cardWrapper(inner: string, w: number, h: number, t: Theme, title: string, prefix = '') {
|
function cardWrapper(inner: string, w: number, h: number, t: Theme, title: string, prefix = '') {
|
||||||
const sid = `${prefix}shadow`
|
const sid = `${prefix}shadow`
|
||||||
return `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}" fill="none">
|
return `<svg xmlns="http://www.w3.org/2000/svg" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}" fill="none">
|
||||||
@@ -82,7 +91,7 @@ function renderGrade(data: GradeData, t: Theme, s?: { max_tags?: number }): stri
|
|||||||
let tagsSvg = '', tx = 0, ty = 0
|
let tagsSvg = '', tx = 0, ty = 0
|
||||||
for (const tag of tags) {
|
for (const tag of tags) {
|
||||||
const tc = TAG_COLORS[tag.tag] ?? t.accent
|
const tc = TAG_COLORS[tag.tag] ?? t.accent
|
||||||
const label = tag.tag.replace(/-/g,' ').replace(/\b\w/g, c => c.toUpperCase())
|
const label = formatTagLabel(tag.tag)
|
||||||
const tw = Math.round(label.length * 6.6 + 18)
|
const tw = Math.round(label.length * 6.6 + 18)
|
||||||
const po = tag.source === 'earned' ? 0.9 : 0.55
|
const po = tag.source === 'earned' ? 0.9 : 0.55
|
||||||
if (tx + tw > 340) { tx = 0; ty += 30 }
|
if (tx + tw > 340) { tx = 0; ty += 30 }
|
||||||
@@ -244,7 +253,7 @@ function achievementIconSvg(iconType: string, color: string): string {
|
|||||||
const icons: Record<string, string> = {
|
const icons: Record<string, string> = {
|
||||||
trophy: `<svg viewBox="0 0 24 24" width="24" height="24"><path d="M7 2h10v2h2.5c.8 0 1.5.7 1.5 1.5V8c0 1.7-1.3 3-3 3h-.5c-.5 1.5-1.8 2.7-3.5 3v2.5h3c.6 0 1 .4 1 1s-.4 1-1 1H7c-.6 0-1-.4-1-1s.4-1 1-1h3V14c-1.7-.3-3-1.5-3.5-3H6c-1.7 0-3-1.3-3-3V5.5C3 4.7 3.7 4 4.5 4H7V2zm0 4H4.5v2c0 .8.7 1.5 1.5 1.5h1V6zm12.5 0H17v3.5h1c.8 0 1.5-.7 1.5-1.5V6z" fill="${color}" opacity="0.85"/></svg>`,
|
trophy: `<svg viewBox="0 0 24 24" width="24" height="24"><path d="M7 2h10v2h2.5c.8 0 1.5.7 1.5 1.5V8c0 1.7-1.3 3-3 3h-.5c-.5 1.5-1.8 2.7-3.5 3v2.5h3c.6 0 1 .4 1 1s-.4 1-1 1H7c-.6 0-1-.4-1-1s.4-1 1-1h3V14c-1.7-.3-3-1.5-3.5-3H6c-1.7 0-3-1.3-3-3V5.5C3 4.7 3.7 4 4.5 4H7V2zm0 4H4.5v2c0 .8.7 1.5 1.5 1.5h1V6zm12.5 0H17v3.5h1c.8 0 1.5-.7 1.5-1.5V6z" fill="${color}" opacity="0.85"/></svg>`,
|
||||||
medal: `<svg viewBox="0 0 24 24" width="24" height="24"><circle cx="12" cy="14" r="5" fill="${color}" opacity="0.2"/><circle cx="12" cy="14" r="4" fill="none" stroke="${color}" stroke-width="1.5"/><path d="M12 11.5l1 2 2.2.3-1.6 1.5.4 2.2-2-1-2 1 .4-2.2-1.6-1.5 2.2-.3z" fill="${color}"/><path d="M9 3l3 8m0-8l3 8m-6-8h6" stroke="${color}" stroke-width="1.5" fill="none" stroke-linecap="round"/></svg>`,
|
medal: `<svg viewBox="0 0 24 24" width="24" height="24"><circle cx="12" cy="14" r="5" fill="${color}" opacity="0.2"/><circle cx="12" cy="14" r="4" fill="none" stroke="${color}" stroke-width="1.5"/><path d="M12 11.5l1 2 2.2.3-1.6 1.5.4 2.2-2-1-2 1 .4-2.2-1.6-1.5 2.2-.3z" fill="${color}"/><path d="M9 3l3 8m0-8l3 8m-6-8h6" stroke="${color}" stroke-width="1.5" fill="none" stroke-linecap="round"/></svg>`,
|
||||||
star: `<svg viewBox="0 0 24 24" width="24" height="24"><path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z" fill="${color}" opacity="0.85"/></svg>`,
|
star: `<svg viewBox="0 0 24 24" width="24" height="24"><path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z" fill="none" stroke="${color}" stroke-width="1.5" stroke-linejoin="round"/></svg>`,
|
||||||
hackathon: `<svg viewBox="0 0 24 24" width="24" height="24"><rect x="4" y="5" width="16" height="11" rx="1" fill="none" stroke="${color}" stroke-width="1.5"/><rect x="3" y="16" width="18" height="1.5" rx="0.5" fill="${color}" opacity="0.85"/><path d="M9 9l-2 3 2 3m6-6l2 3-2 3" stroke="${color}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg>`,
|
hackathon: `<svg viewBox="0 0 24 24" width="24" height="24"><rect x="4" y="5" width="16" height="11" rx="1" fill="none" stroke="${color}" stroke-width="1.5"/><rect x="3" y="16" width="18" height="1.5" rx="0.5" fill="${color}" opacity="0.85"/><path d="M9 9l-2 3 2 3m6-6l2 3-2 3" stroke="${color}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg>`,
|
||||||
}
|
}
|
||||||
return icons[iconType] ?? icons.trophy
|
return icons[iconType] ?? icons.trophy
|
||||||
|
|||||||
@@ -19,47 +19,57 @@ const ALL_WIDGETS = [
|
|||||||
{ id: 'achievements', label: 'Achievements' },
|
{ id: 'achievements', label: 'Achievements' },
|
||||||
]
|
]
|
||||||
|
|
||||||
// Inline SVGs keep parity with the backend (generator/src/widgets/achievements.py)
|
// Lucide-style hollow glyphs: consistent stroke-weight + viewBox so the 4
|
||||||
// and render deterministically across platforms where emoji coverage varies.
|
// buttons line up and read as one icon family. Kept as JSX so they inherit
|
||||||
|
// currentColor from the surrounding button's text color.
|
||||||
|
const ICON_SVG_PROPS = {
|
||||||
|
width: 16,
|
||||||
|
height: 16,
|
||||||
|
viewBox: '0 0 24 24',
|
||||||
|
fill: 'none',
|
||||||
|
stroke: 'currentColor',
|
||||||
|
strokeWidth: 1.75,
|
||||||
|
strokeLinecap: 'round' as const,
|
||||||
|
strokeLinejoin: 'round' as const,
|
||||||
|
}
|
||||||
|
|
||||||
const ICONS: { id: string; svg: ReactNode }[] = [
|
const ICONS: { id: string; svg: ReactNode }[] = [
|
||||||
{
|
{
|
||||||
id: 'trophy',
|
id: 'trophy',
|
||||||
svg: (
|
svg: (
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
<svg {...ICON_SVG_PROPS}>
|
||||||
<path d="M6 9H4a2 2 0 0 1-2-2V5h4" />
|
<path d="M6 9H4.5a2.5 2.5 0 0 1 0-5H6" />
|
||||||
<path d="M18 9h2a2 2 0 0 0 2-2V5h-4" />
|
<path d="M18 9h1.5a2.5 2.5 0 0 0 0-5H18" />
|
||||||
<path d="M6 3h12v6a6 6 0 0 1-12 0V3z" />
|
<path d="M4 22h16" />
|
||||||
<path d="M10 21h4" />
|
<path d="M10 14.66V17c0 .55-.47.98-.97 1.21C7.85 18.75 7 20.24 7 22" />
|
||||||
<path d="M12 15v6" />
|
<path d="M14 14.66V17c0 .55.47.98.97 1.21C16.15 18.75 17 20.24 17 22" />
|
||||||
|
<path d="M18 2H6v7a6 6 0 0 0 12 0V2z" />
|
||||||
</svg>
|
</svg>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'medal',
|
id: 'medal',
|
||||||
svg: (
|
svg: (
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
<svg {...ICON_SVG_PROPS}>
|
||||||
<circle cx="12" cy="15" r="6" />
|
<circle cx="12" cy="8" r="6" />
|
||||||
<path d="M8.5 2l3.5 7 3.5-7" />
|
<path d="m15.477 12.89 1.515 8.526a.5.5 0 0 1-.81.47l-3.58-2.687a1 1 0 0 0-1.197 0l-3.586 2.686a.5.5 0 0 1-.81-.469l1.514-8.526" />
|
||||||
<path d="M7 2h10" />
|
|
||||||
</svg>
|
</svg>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'star',
|
id: 'star',
|
||||||
svg: (
|
svg: (
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
<svg {...ICON_SVG_PROPS}>
|
||||||
<polygon points="12 2 15 9 22 9.5 17 14.5 18.5 22 12 18 5.5 22 7 14.5 2 9.5 9 9 12 2" />
|
<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26" />
|
||||||
</svg>
|
</svg>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'hackathon',
|
id: 'hackathon',
|
||||||
svg: (
|
svg: (
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
<svg {...ICON_SVG_PROPS}>
|
||||||
<rect x="2" y="4" width="20" height="14" rx="2" />
|
<polyline points="16 18 22 12 16 6" />
|
||||||
<path d="M8 10l-2 2 2 2" />
|
<polyline points="8 6 2 12 8 18" />
|
||||||
<path d="M16 10l2 2-2 2" />
|
|
||||||
<path d="M2 20h20" />
|
|
||||||
</svg>
|
</svg>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
@@ -372,22 +382,24 @@ export function WorkshopScreen({
|
|||||||
{settings.achievements.map((ach, idx) => (
|
{settings.achievements.map((ach, idx) => (
|
||||||
<div key={idx} className="p-2.5 rounded-lg border border-gray-100 bg-gray-50/50">
|
<div key={idx} className="p-2.5 rounded-lg border border-gray-100 bg-gray-50/50">
|
||||||
<div className="flex items-center gap-1.5 mb-2">
|
<div className="flex items-center gap-1.5 mb-2">
|
||||||
{ICONS.map(ic => (
|
{ICONS.map(ic => {
|
||||||
<button
|
const selected = ach.icon === ic.id
|
||||||
key={ic.id}
|
return (
|
||||||
onClick={() => updateAchievement(idx, 'icon', ic.id)}
|
<button
|
||||||
className={`w-7 h-7 rounded-md text-sm flex items-center justify-center transition-colors ${
|
key={ic.id}
|
||||||
ach.icon === ic.id
|
onClick={() => updateAchievement(idx, 'icon', ic.id)}
|
||||||
? 'bg-gray-800 ring-1 ring-gray-800'
|
className={`w-8 h-8 rounded-md flex items-center justify-center transition-colors ${
|
||||||
: 'bg-white border border-gray-200 hover:border-gray-300'
|
selected
|
||||||
}`}
|
? 'bg-gray-800 text-white border border-gray-800'
|
||||||
title={ic.id}
|
: 'bg-white text-gray-500 border border-gray-200 hover:text-gray-800 hover:border-gray-300'
|
||||||
>
|
}`}
|
||||||
<span className={ach.icon === ic.id ? 'text-white' : 'text-gray-600'}>
|
title={ic.id}
|
||||||
|
aria-pressed={selected}
|
||||||
|
>
|
||||||
{ic.svg}
|
{ic.svg}
|
||||||
</span>
|
</button>
|
||||||
</button>
|
)
|
||||||
))}
|
})}
|
||||||
<div className="flex-1" />
|
<div className="flex-1" />
|
||||||
<button
|
<button
|
||||||
onClick={() => removeAchievement(idx)}
|
onClick={() => removeAchievement(idx)}
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ def _achievement_icon_svg(icon_type: str, color: str) -> str:
|
|||||||
<path d="M9 3l3 8m0-8l3 8m-6-8h6" stroke="{color}" stroke-width="1.5" fill="none" stroke-linecap="round"/>
|
<path d="M9 3l3 8m0-8l3 8m-6-8h6" stroke="{color}" stroke-width="1.5" fill="none" stroke-linecap="round"/>
|
||||||
</svg>''',
|
</svg>''',
|
||||||
"star": f'''<svg viewBox="0 0 24 24" width="24" height="24">
|
"star": f'''<svg viewBox="0 0 24 24" width="24" height="24">
|
||||||
<path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z" fill="{color}" opacity="0.85"/>
|
<path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"
|
||||||
|
fill="none" stroke="{color}" stroke-width="1.5" stroke-linejoin="round"/>
|
||||||
</svg>''',
|
</svg>''',
|
||||||
"hackathon": f'''<svg viewBox="0 0 24 24" width="24" height="24">
|
"hackathon": f'''<svg viewBox="0 0 24 24" width="24" height="24">
|
||||||
<rect x="4" y="5" width="16" height="11" rx="1" fill="none" stroke="{color}" stroke-width="1.5"/>
|
<rect x="4" y="5" width="16" height="11" rx="1" fill="none" stroke="{color}" stroke-width="1.5"/>
|
||||||
|
|||||||
@@ -5,6 +5,17 @@ from ..models import GradeData
|
|||||||
from ..themes import THEMES, TAG_COLORS, GRADE_COLORS
|
from ..themes import THEMES, TAG_COLORS, GRADE_COLORS
|
||||||
from ..utils import escape, card_wrapper, icon_svg
|
from ..utils import escape, card_wrapper, icon_svg
|
||||||
|
|
||||||
|
# Tokens that should render uppercase instead of title-cased (e.g. "ml-engineer"
|
||||||
|
# → "ML Engineer", not "Ml Engineer").
|
||||||
|
_TAG_ACRONYMS = {"ml", "ai", "ui", "ux", "api", "cli", "sql", "css", "html", "js", "ios"}
|
||||||
|
|
||||||
|
|
||||||
|
def _format_tag_label(tag: str) -> str:
|
||||||
|
return " ".join(
|
||||||
|
w.upper() if w.lower() in _TAG_ACRONYMS else w.capitalize()
|
||||||
|
for w in tag.split("-")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def render_grade_widget(data: GradeData, theme_name: str = "dark", settings: dict | None = None) -> str:
|
def render_grade_widget(data: GradeData, theme_name: str = "dark", settings: dict | None = None) -> str:
|
||||||
"""Renders the developer grade widget with stats and tags.
|
"""Renders the developer grade widget with stats and tags.
|
||||||
@@ -63,7 +74,7 @@ def render_grade_widget(data: GradeData, theme_name: str = "dark", settings: dic
|
|||||||
|
|
||||||
for tag in (data.tags or []):
|
for tag in (data.tags or []):
|
||||||
tag_color = TAG_COLORS.get(tag.tag, t["accent"])
|
tag_color = TAG_COLORS.get(tag.tag, t["accent"])
|
||||||
label = tag.tag.replace("-", " ").title()
|
label = _format_tag_label(tag.tag)
|
||||||
tw = int(len(label) * 6.6 + 18)
|
tw = int(len(label) * 6.6 + 18)
|
||||||
pill_opacity = 0.9 if tag.source == "earned" else 0.55
|
pill_opacity = 0.9 if tag.source == "earned" else 0.55
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user