mirror of
https://github.com/ShayManor/github-readme-stats.git
synced 2026-12-02 11:53:48 +05:30
feat(worker): add achievements parameter to widget settings processing
This commit is contained in:
@@ -145,6 +145,7 @@ export default function App() {
|
||||
custom_tags: settings.customTags,
|
||||
hidden_languages: settings.hiddenLanguages,
|
||||
widget_settings: settings.widgetSettings,
|
||||
achievements: settings.achievements.filter(a => a.title.trim()),
|
||||
}
|
||||
const patchRes = await fetch(`/api/${encodeURIComponent(username)}/settings`, {
|
||||
method: 'PATCH',
|
||||
|
||||
@@ -238,6 +238,18 @@ function renderLanguages(languages: LanguageData[], t: Theme, s?: { max_language
|
||||
return cardWrapper(inner, 380, rowsH + 36, t, 'Languages')
|
||||
}
|
||||
|
||||
function achievementIconSvg(iconType: string, color: string): string {
|
||||
// Mirrors generator/src/widgets/achievements.py::_achievement_icon_svg so
|
||||
// the Workshop client preview matches the backend-rendered composite.
|
||||
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>`,
|
||||
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>`,
|
||||
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
|
||||
}
|
||||
|
||||
function renderAchievements(achievements: AchievementInput[], t: Theme, s?: { max_items?: number }): string {
|
||||
const maxItems = Math.min(Math.max(s?.max_items ?? 5, 1), 10)
|
||||
const shown = achievements.filter(a => a.title.trim()).slice(0, maxItems)
|
||||
@@ -249,7 +261,8 @@ function renderAchievements(achievements: AchievementInput[], t: Theme, s?: { ma
|
||||
for (let i = 0; i < shown.length; i++) {
|
||||
const ach = shown[i], y = i * 56
|
||||
const color = accentColors[i % accentColors.length]
|
||||
items += `<g transform="translate(16, ${y+8})"><rect width="348" height="48" rx="8" fill="${color}" opacity="0.06"/><rect width="348" height="48" rx="8" fill="none" stroke="${color}" stroke-width="0.5" opacity="0.3"/><text x="16" y="20" font-family="${font}" font-size="13" font-weight="600" fill="${t.text}">${esc(ach.title)}</text><text x="16" y="36" font-family="${font}" font-size="10" fill="${t.text_secondary}">${esc(ach.subtitle)}${ach.event_date ? ' · ' + ach.event_date : ''}</text></g>`
|
||||
const icon = achievementIconSvg(ach.icon, color)
|
||||
items += `<g transform="translate(16, ${y+8})"><rect width="348" height="48" rx="8" fill="${color}" opacity="0.06"/><rect width="348" height="48" rx="8" fill="none" stroke="${color}" stroke-width="0.5" opacity="0.3"/><g transform="translate(12, 12)">${icon}</g><text x="48" y="20" font-family="${font}" font-size="13" font-weight="600" fill="${t.text}">${esc(ach.title)}</text><text x="48" y="36" font-family="${font}" font-size="10" fill="${t.text_secondary}">${esc(ach.subtitle)}${ach.event_date ? ' · ' + ach.event_date : ''}</text></g>`
|
||||
}
|
||||
|
||||
return cardWrapper(items, 380, shown.length * 56 + 50, t, 'Achievements')
|
||||
|
||||
@@ -10,6 +10,7 @@ from .models import (
|
||||
CollaboratorData,
|
||||
FocusCategory,
|
||||
LanguageData,
|
||||
AchievementData,
|
||||
)
|
||||
from .widgets import (
|
||||
render_grade_widget,
|
||||
@@ -17,6 +18,7 @@ from .widgets import (
|
||||
render_collaborators_widget,
|
||||
render_focus_widget,
|
||||
render_languages_widget,
|
||||
render_achievements_widget,
|
||||
)
|
||||
|
||||
|
||||
@@ -495,6 +497,7 @@ def generate_widgets_from_github(
|
||||
hidden_languages: list[str] = None,
|
||||
enabled: list[str] = None,
|
||||
widget_settings: dict[str, dict] | None = None,
|
||||
achievements: list[dict] | None = None,
|
||||
) -> dict[str, str]:
|
||||
"""
|
||||
Takes raw GitHub API data and returns rendered SVG strings
|
||||
@@ -539,4 +542,19 @@ def generate_widgets_from_github(
|
||||
languages = compute_languages(github_data, hidden_languages=hidden_languages)
|
||||
widgets["languages"] = render_languages_widget(languages, theme, settings=ws.get("languages"))
|
||||
|
||||
if "achievements" in enabled_set:
|
||||
# User-authored content — no GitHub data involved.
|
||||
raw = [a for a in (achievements or []) if (a.get("title") or "").strip()]
|
||||
items = [
|
||||
AchievementData(
|
||||
title=a.get("title", ""),
|
||||
subtitle=a.get("subtitle", ""),
|
||||
event_date=a.get("event_date", ""),
|
||||
icon=a.get("icon", "trophy"),
|
||||
)
|
||||
for a in raw
|
||||
]
|
||||
if items:
|
||||
widgets["achievements"] = render_achievements_widget(items, theme, settings=ws.get("achievements"))
|
||||
|
||||
return widgets
|
||||
|
||||
@@ -48,6 +48,7 @@ def _render_widgets(username: str, payload: dict, settings: dict) -> dict[str, s
|
||||
hidden_languages=settings.get("hidden_languages"),
|
||||
enabled=enabled,
|
||||
widget_settings=settings.get("widget_settings") or {},
|
||||
achievements=settings.get("achievements") or [],
|
||||
)
|
||||
ordered = [w for w in order if w in enabled and w in widgets and widgets[w]]
|
||||
composite = compose_widget(
|
||||
|
||||
Reference in New Issue
Block a user