diff --git a/data/colorsRepos.json b/data/repoColors.json similarity index 100% rename from data/colorsRepos.json rename to data/repoColors.json diff --git a/layouts/partials/get-repo-languages.html b/layouts/partials/get-repo-languages.html new file mode 100644 index 00000000..5832025f --- /dev/null +++ b/layouts/partials/get-repo-languages.html @@ -0,0 +1,20 @@ +{{ $repoColors := site.Data.repoColors }} +{{ $classNameMap := dict }} +{{ range $language, $unused := $repoColors }} + {{ $className := printf "background-color-%s" (md5 $language) }} + {{ $classNameMap = merge $classNameMap (dict $className $language) }} +{{ end }} + +{{ $classNames := slice }} +{{ range site.Pages }} + {{ $matchedClasses := findRE `background-color-[a-f0-9]{32}` .Content }} + {{ range $matchedClasses }} + {{ with index $classNameMap . }} + {{ $classNames = $classNames | append . }} + {{ else }} + {{ $classNames = $classNames | append "fallback" }} + {{ end }} + {{ end }} +{{ end }} + +{{ return (uniq $classNames) }} diff --git a/layouts/partials/head.html b/layouts/partials/head.html index e68dc932..1a9c2098 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -85,28 +85,14 @@ {{ end }} {{ end }} - {{ $repoShortcodeExists := false }} - {{ range .Site.Pages }} - {{ if or (.Page.HasShortcode "codeberg") (.Page.HasShortcode "forgejo") (.Page.HasShortcode "gitea") (.Page.HasShortcode "github") }} - {{ $repoShortcodeExists = true }} - {{ end }} - {{ end }} - {{ if $repoShortcodeExists }} - {{ $colorsRepos := .Site.Data.colorsRepos }} - {{ range $language, $color := $colorsRepos }} - {{ if not $color }} - {{ $color = "" }} - {{ end }} - {{ $className := printf "color-repo-%s" (md5 $language) }} - {{ $cssColorRepos := printf ".%s { background-color: %s; }" $className $color }} - {{ $cssColorRepos = $cssColorRepos | resources.FromString "css/color-repo.css" }} - {{ $assets.Add "css" (slice $cssColorRepos) }} - {{ end }} - {{ $color := "#0077b6" }} - {{ $className := "color-repo-fallback" }} - {{ $cssColorRepos := printf ".%s { background-color: %s; }" $className $color }} - {{ $cssColorRepos = $cssColorRepos | resources.FromString "css/color-repo.css" }} - {{ $assets.Add "css" (slice $cssColorRepos) }} + {{ $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 diff --git a/layouts/shortcodes/codeberg.html b/layouts/shortcodes/codeberg.html index efcd66d3..45a8275c 100644 --- a/layouts/shortcodes/codeberg.html +++ b/layouts/shortcodes/codeberg.html @@ -22,10 +22,8 @@