From 884d84363e6ed021a72d62ef5a8859599ebf4f76 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Fri, 17 Oct 2025 14:27:53 +0800 Subject: [PATCH] Revert "perf(repo-card): only generate used CSS class" This reverts commit af221fbf3b60774079285d7dba103f3a849ec699. fix language dot colors in repo-card not displaying This occurs because head.html is rendered before the page content, making .Page.Store unavailable at that point in the template execution order. This issue doesn't appear in local development because page refreshes trigger full re-renders, allowing the Store values to be properly populated from shortcodes. Alternative solutions considered: 1. templates.Defer: too complex and unreliable 2. Moving CSS to footer: confusing and delayed load 3. Inline styles: incurs CSP issue Final I choose pre-generate CSS for all languages. After zstd compression, the CSS file is only 8KB and benefits from browser caching across all pages. --- layouts/partials/vendor.html | 32 ++++++++++------------------- layouts/shortcodes/codeberg.html | 7 +------ layouts/shortcodes/forgejo.html | 7 +------ layouts/shortcodes/gitea.html | 7 +------ layouts/shortcodes/github.html | 7 +------ layouts/shortcodes/huggingface.html | 7 +------ 6 files changed, 16 insertions(+), 51 deletions(-) diff --git a/layouts/partials/vendor.html b/layouts/partials/vendor.html index a0f0ec54..31872d08 100644 --- a/layouts/partials/vendor.html +++ b/layouts/partials/vendor.html @@ -131,27 +131,17 @@ {{ $repoColors := site.Data.repoColors }} {{ $cssRules := slice }} - {{ $usedLanguages := $.Page.Store.Get "repoCardLanguages" }} - {{ if not $usedLanguages }} - {{ $usedLanguages = slice "default" }} - {{ else }} - {{ $usedLanguages = $usedLanguages | append "default" }} + {{/* default color */}} + {{ $cssRules = $cssRules | append ".language-dot[data-language=\"default\"] { background-color: #0077b6; }" }} + + {{/* Hugging Face model color */}} + {{ $cssRules = $cssRules | append ".language-dot[data-language=\"model\"] { background-color: #ff6b35; }" }} + + {{ range $lang, $color := $repoColors }} + {{ $cssRules = $cssRules | append (printf ".language-dot[data-language=\"%s\"] { background-color: %s; }" $lang $color) }} {{ end }} - - {{ range $usedLanguages }} - {{ if eq . "default" }} - {{ $cssRules = $cssRules | append ".language-dot[data-language=\"default\"] { background-color: #0077b6; }" }} - {{ else if eq . "model" }} - {{ $cssRules = $cssRules | append ".language-dot[data-language=\"model\"] { background-color: #ff6b35; }" }} - {{ else if index $repoColors . }} - {{ $color := index $repoColors . }} - {{ $cssRules = $cssRules | append (printf ".language-dot[data-language=\"%s\"] { background-color: %s; }" . $color) }} - {{ end }} - {{ end }} - - {{ $cssContent := delimit $cssRules "\n" }} - {{ $outputPath := path.Join .Page.RelPermalink "repo-cards.css" }} - {{ $repoCardCSS := resources.FromString $outputPath $cssContent | minify | resources.Fingerprint (.Site.Params.fingerprintAlgorithm | default "sha512") }} - + {{ $repoCardCSS := resources.FromString "css/repo-cards.css" (delimit $cssRules "\n") + | minify | resources.Fingerprint (.Site.Params.fingerprintAlgorithm | default "sha512") + }} {{ end }} diff --git a/layouts/shortcodes/codeberg.html b/layouts/shortcodes/codeberg.html index 86918aa2..bb1921e4 100644 --- a/layouts/shortcodes/codeberg.html +++ b/layouts/shortcodes/codeberg.html @@ -33,12 +33,7 @@