- {{ $languageDotColor := cond (eq $type "model") "#ff6b35" "#0077b6" }}
- {{ $css := resources.FromString (printf "css/%s.css" $id) (printf ".language-dot-%s{background-color:%s}" $id $languageDotColor)
- | minify | resources.Fingerprint (.Site.Params.fingerprintAlgorithm | default "sha512")
- }}
-
{{ if eq $type "model" }}
{{ if .pipeline_tag }}{{ .pipeline_tag }}{{ else }}model{{ end }}
From af221fbf3b60774079285d7dba103f3a849ec699 Mon Sep 17 00:00:00 2001
From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com>
Date: Fri, 12 Sep 2025 11:11:52 +0800
Subject: [PATCH 3/3] perf(repo-card): only generate used CSS class
---
layouts/partials/vendor.html | 30 ++++++++++++++++++-----------
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, 49 insertions(+), 16 deletions(-)
diff --git a/layouts/partials/vendor.html b/layouts/partials/vendor.html
index cb074675..d2edcdff 100644
--- a/layouts/partials/vendor.html
+++ b/layouts/partials/vendor.html
@@ -119,7 +119,7 @@
{{ end }}
{{/* Repo cards */}}
-{{ $repoCards := slice "github" "gitea" "hugging-face" "codeberg" "forgejo" }}
+{{ $repoCards := slice "codeberg" "forgejo" "gitea" "github" "hugging-face" }}
{{ $hasRepoCards := false }}
{{ range $repoCards }}
{{ if $.Page.HasShortcode . }}
@@ -131,18 +131,26 @@
{{ $repoColors := site.Data.repoColors }}
{{ $cssRules := slice }}
- {{/* 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) }}
+ {{ $usedLanguages := $.Page.Store.Get "repoCardLanguages" }}
+ {{ if not $usedLanguages }}
+ {{ $usedLanguages = slice "default" }}
+ {{ else }}
+ {{ $usedLanguages = $usedLanguages | append "default" }}
{{ end }}
- {{ $repoCardCss := resources.FromString "css/repo-cards.css" (delimit $cssRules "\n")
+ {{ 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 }}
+
+ {{ $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 50db132c..30ff1b39 100644
--- a/layouts/shortcodes/codeberg.html
+++ b/layouts/shortcodes/codeberg.html
@@ -33,7 +33,12 @@
-
+ {{ $language := cond .language .language "default" }}
+ {{ $currentLangs := $.Page.Store.Get "repoCardLanguages" | default slice }}
+ {{ $.Page.Store.Set "repoCardLanguages" ($currentLangs | append $language) }}
+
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
diff --git a/layouts/shortcodes/forgejo.html b/layouts/shortcodes/forgejo.html
index a6395a3c..5e4f49ba 100644
--- a/layouts/shortcodes/forgejo.html
+++ b/layouts/shortcodes/forgejo.html
@@ -33,7 +33,12 @@
-
+ {{ $language := cond .language .language "default" }}
+ {{ $currentLangs := $.Page.Store.Get "repoCardLanguages" | default slice }}
+ {{ $.Page.Store.Set "repoCardLanguages" ($currentLangs | append $language) }}
+
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
diff --git a/layouts/shortcodes/gitea.html b/layouts/shortcodes/gitea.html
index 3175fa99..3bb81bcf 100644
--- a/layouts/shortcodes/gitea.html
+++ b/layouts/shortcodes/gitea.html
@@ -33,7 +33,12 @@
-
+ {{ $language := cond .language .language "default" }}
+ {{ $currentLangs := $.Page.Store.Get "repoCardLanguages" | default slice }}
+ {{ $.Page.Store.Set "repoCardLanguages" ($currentLangs | append $language) }}
+
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
diff --git a/layouts/shortcodes/github.html b/layouts/shortcodes/github.html
index c3a5dcec..a42d8808 100644
--- a/layouts/shortcodes/github.html
+++ b/layouts/shortcodes/github.html
@@ -46,7 +46,12 @@
-
+ {{ $language := cond .language .language "default" }}
+ {{ $currentLangs := $.Page.Store.Get "repoCardLanguages" | default slice }}
+ {{ $.Page.Store.Set "repoCardLanguages" ($currentLangs | append $language) }}
+
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
diff --git a/layouts/shortcodes/huggingface.html b/layouts/shortcodes/huggingface.html
index 03e6bf04..8aa55a95 100644
--- a/layouts/shortcodes/huggingface.html
+++ b/layouts/shortcodes/huggingface.html
@@ -53,7 +53,12 @@
-
+ {{ $language := cond (eq $type "model") "model" "default" }}
+ {{ $currentLangs := $.Page.Store.Get "repoCardLanguages" | default slice }}
+ {{ $.Page.Store.Set "repoCardLanguages" ($currentLangs | append $language) }}
+
{{ if eq $type "model" }}
{{ if .pipeline_tag }}{{ .pipeline_tag }}{{ else }}model{{ end }}