From 2ff6b0e8bd1ff8e3f7b5a3d1e3d3598eaacc4937 Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Sun, 13 Jul 2025 20:55:38 +0800 Subject: [PATCH 1/2] fix: repo card language color is missed --- layouts/partials/head.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/layouts/partials/head.html b/layouts/partials/head.html index a1db6860..08f93a41 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -54,6 +54,15 @@ {{ $cssZoom := resources.Get "lib/zoom/style.css" }} {{ $assets.Add "css" (slice $cssZoom) }} {{ end }} + {{ $repoLanguages := partial "functions/repo-languages.html" }} + {{ $repoColors := .Site.Data.repoColors }} + {{ range $repoLanguages }} + {{ $color := index $repoColors . | default "#0077b6" }} + {{ $className := printf "background-color-%s" (md5 .) }} + {{ $cssRepoColor := printf ".%s { background-color: %s; }" $className $color }} + {{ $cssRepoColor = $cssRepoColor | resources.FromString (printf "css/background-color.css") }} + {{ $assets.Add "css" (slice $cssRepoColor) }} + {{ end }} {{ $bundleCSS := $assets.Get "css" | resources.Concat "css/main.bundle.css" | resources.Minify | resources.Fingerprint (.Site.Params.fingerprintAlgorithm | default "sha512") }} From 5009fffcf48f224c2b5727f9fb995d41b99710dd Mon Sep 17 00:00:00 2001 From: ZhenShuo Leo <98386542+ZhenShuo2021@users.noreply.github.com> Date: Thu, 17 Jul 2025 02:50:42 +0800 Subject: [PATCH 2/2] fix(repo-card): manually revert to the version in 2.87.0 The md5 method has severe performance degradation It is approximately 2x slower without cache and 5x slower with cache Reverted due to lack of a better option --- .../partials/functions/repo-languages.html | 20 ------------------- layouts/partials/head.html | 9 --------- layouts/shortcodes/codeberg.html | 10 +++++++--- layouts/shortcodes/forgejo.html | 10 +++++++--- layouts/shortcodes/gitea.html | 10 +++++++--- layouts/shortcodes/github.html | 10 +++++++--- 6 files changed, 28 insertions(+), 41 deletions(-) delete mode 100644 layouts/partials/functions/repo-languages.html diff --git a/layouts/partials/functions/repo-languages.html b/layouts/partials/functions/repo-languages.html deleted file mode 100644 index 9ac1a6e5..00000000 --- a/layouts/partials/functions/repo-languages.html +++ /dev/null @@ -1,20 +0,0 @@ -{{ $repoColors := site.Data.repoColors }} -{{ $classNameMap := dict }} -{{ range $language, $unused := $repoColors }} - {{ $className := printf "background-color-%s" (md5 $language) }} - {{ $classNameMap = merge $classNameMap (dict $className $language) }} -{{ end }} - -{{ $repoLanguages := slice }} -{{ range site.Pages }} - {{ $matchedClasses := findRE `background-color-[a-f0-9]{32}` .Content }} - {{ range $matchedClasses }} - {{ with index $classNameMap . }} - {{ $repoLanguages = $repoLanguages | append . }} - {{ else }} - {{ $repoLanguages = $repoLanguages | append "fallback" }} - {{ end }} - {{ end }} -{{ end }} - -{{ return (uniq $repoLanguages) }} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 08f93a41..a1db6860 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -54,15 +54,6 @@ {{ $cssZoom := resources.Get "lib/zoom/style.css" }} {{ $assets.Add "css" (slice $cssZoom) }} {{ end }} - {{ $repoLanguages := partial "functions/repo-languages.html" }} - {{ $repoColors := .Site.Data.repoColors }} - {{ range $repoLanguages }} - {{ $color := index $repoColors . | default "#0077b6" }} - {{ $className := printf "background-color-%s" (md5 .) }} - {{ $cssRepoColor := printf ".%s { background-color: %s; }" $className $color }} - {{ $cssRepoColor = $cssRepoColor | resources.FromString (printf "css/background-color.css") }} - {{ $assets.Add "css" (slice $cssRepoColor) }} - {{ end }} {{ $bundleCSS := $assets.Get "css" | resources.Concat "css/main.bundle.css" | resources.Minify | resources.Fingerprint (.Site.Params.fingerprintAlgorithm | default "sha512") }} diff --git a/layouts/shortcodes/codeberg.html b/layouts/shortcodes/codeberg.html index 787db9e4..89201e0f 100644 --- a/layouts/shortcodes/codeberg.html +++ b/layouts/shortcodes/codeberg.html @@ -1,5 +1,6 @@ {{ $id := delimit (slice "codeberg" (partial "functions/uid.html" .)) "-" }} {{- $codebergURL := print "https://codeberg.org/api/v1/repos/" (.Get "repo") -}} +{{- $codebergColors := .Site.Data.repoColors -}} {{- $codebergData := dict -}} {{- with try (resources.GetRemote $codebergURL) -}} {{- with .Err -}} @@ -32,10 +33,13 @@

- {{ $language := .language | default "fallback" }} - {{ $className := printf "background-color-%s" (md5 $language) }} + class="mr-1 inline-block h-3 w-3 rounded-full" + style="background-color: {{ if .language }} + {{- index $codebergColors .language -}} + {{ else }} + #0077b6 + {{ end }}">
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
diff --git a/layouts/shortcodes/forgejo.html b/layouts/shortcodes/forgejo.html index a66a2631..d230a4e3 100644 --- a/layouts/shortcodes/forgejo.html +++ b/layouts/shortcodes/forgejo.html @@ -1,5 +1,6 @@ {{ $id := delimit (slice "forgejo" (partial "functions/uid.html" .)) "-" }} {{- $forgejoURL := print (.Get "server" | default .Site.Params.forgejoDefaultServer) "/api/v1/repos/" (.Get "repo") -}} +{{- $forgejoColors := .Site.Data.repoColors -}} {{- $forgejoData := dict -}} {{- with try (resources.GetRemote $forgejoURL) -}} {{- with .Err -}} @@ -32,10 +33,13 @@

- {{ $language := .language | default "fallback" }} - {{ $className := printf "background-color-%s" (md5 $language) }} + class="mr-1 inline-block h-3 w-3 rounded-full" + style="background-color: {{ if .language }} + {{- index $forgejoColors .language -}} + {{ else }} + #0077b6 + {{ end }}">
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
diff --git a/layouts/shortcodes/gitea.html b/layouts/shortcodes/gitea.html index 0be6a064..f8e7531d 100644 --- a/layouts/shortcodes/gitea.html +++ b/layouts/shortcodes/gitea.html @@ -1,5 +1,6 @@ {{ $id := delimit (slice "gitea" (partial "functions/uid.html" .)) "-" }} {{- $giteaURL := print (.Get "server" | default .Site.Params.giteaDefaultServer) "/api/v1/repos/" (.Get "repo") -}} +{{- $giteaColors := .Site.Data.repoColors -}} {{- $giteaData := dict -}} {{- with try (resources.GetRemote $giteaURL) -}} {{- with .Err -}} @@ -32,10 +33,13 @@

- {{ $language := .language | default "fallback" }} - {{ $className := printf "background-color-%s" (md5 $language) }} + class="mr-1 inline-block h-3 w-3 rounded-full" + style="background-color: {{ if .language }} + {{- index $giteaColors .language -}} + {{ else }} + #0077b6 + {{ end }}">
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
diff --git a/layouts/shortcodes/github.html b/layouts/shortcodes/github.html index 2ffc10f4..bad67123 100644 --- a/layouts/shortcodes/github.html +++ b/layouts/shortcodes/github.html @@ -2,6 +2,7 @@ {{- $githubURL := print "https://api.github.com/repos/" (.Get "repo") -}} {{- $githubThumbnailURL := print "https://opengraph.githubassets.com/0/" (.Get "repo") -}} {{- $showThumbnail := .Get "showThumbnail" | default true -}} +{{- $githubColors := .Site.Data.repoColors -}} {{- $githubData := dict -}} {{- with try (resources.GetRemote $githubURL) -}} {{- with .Err -}} @@ -45,10 +46,13 @@

- {{ $language := .language | default "fallback" }} - {{ $className := printf "background-color-%s" (md5 $language) }} + class="mr-1 inline-block h-3 w-3 rounded-full" + style="background-color: {{ if .language }} + {{- index $githubColors .language -}} + {{ else }} + #0077b6 + {{ end }}">
{{ if .language }}{{ .language }}{{ else }}null{{ end }}