Skip to content

Commit 6d94d1d

Browse files
authored
Merge pull request #2269 from servedsmart/use-data-repo-colors-and-move-out-of-line
♻️ Refactor: Use universal json for repo shortcodes and move styles out of line
2 parents 037c741 + 25977d8 commit 6d94d1d

10 files changed

Lines changed: 42 additions & 1628 deletions

File tree

data/forgejoColors.json

Lines changed: 0 additions & 533 deletions
This file was deleted.

data/giteaColors.json

Lines changed: 0 additions & 533 deletions
This file was deleted.

data/githubColors.json

Lines changed: 0 additions & 533 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{{ $repoColors := site.Data.repoColors }}
2+
{{ $classNameMap := dict }}
3+
{{ range $language, $unused := $repoColors }}
4+
{{ $className := printf "background-color-%s" (md5 $language) }}
5+
{{ $classNameMap = merge $classNameMap (dict $className $language) }}
6+
{{ end }}
7+
8+
{{ $repoLanguages := slice }}
9+
{{ range site.Pages }}
10+
{{ $matchedClasses := findRE `background-color-[a-f0-9]{32}` .Content }}
11+
{{ range $matchedClasses }}
12+
{{ with index $classNameMap . }}
13+
{{ $repoLanguages = $repoLanguages | append . }}
14+
{{ else }}
15+
{{ $repoLanguages = $repoLanguages | append "fallback" }}
16+
{{ end }}
17+
{{ end }}
18+
{{ end }}
19+
20+
{{ return (uniq $repoLanguages) }}

layouts/partials/head.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@
8585
{{ end }}
8686
{{ end }}
8787

88+
{{ $repoLanguages := partial "functions/repo-languages.html" }}
89+
{{ $repoColors := .Site.Data.repoColors }}
90+
{{ range $repoLanguages }}
91+
{{ $color := index $repoColors . | default "#0077b6" }}
92+
{{ $className := printf "background-color-%s" (md5 .) }}
93+
{{ $cssRepoColor := printf ".%s { background-color: %s; }" $className $color }}
94+
{{ $cssRepoColor = $cssRepoColor | resources.FromString (printf "css/background-color.css") }}
95+
{{ $assets.Add "css" (slice $cssRepoColor) }}
96+
{{ end }}
97+
8898
{{ $bundleCSS := $assets.Get "css" | resources.Concat "css/main.bundle.css" | resources.Minify | resources.Fingerprint
8999
(.Site.Params.fingerprintAlgorithm | default "sha512")
90100
}}

layouts/shortcodes/codeberg.html

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{{ $id := delimit (slice "codeberg" (partial "functions/uid.html" .)) "-" }}
22
{{- $codebergURL := print "https://codeberg.org/api/v1/repos/" (.Get "repo") -}}
33
{{- $codebergData := resources.GetRemote $codebergURL | transform.Unmarshal -}}
4-
{{- $codebergColors := .Site.Data.codebergColors -}}
54
{{- with $codebergData -}}
65
<div class="codeberg-card-wrapper">
76
<a id="{{ $id }}" target="_blank" href="{{ .html_url }}" class="cursor-pointer">
@@ -23,13 +22,10 @@
2322
</p>
2423

2524
<div class="m-0 mt-2 flex items-center">
25+
{{ $language := .language | default "fallback" }}
26+
{{ $className := printf "background-color-%s" (md5 $language) }}
2627
<span
27-
class="mr-1 inline-block h-3 w-3 rounded-full"
28-
style="background-color: {{ if .language }}
29-
{{- index $codebergColors .language -}}
30-
{{ else }}
31-
#0077b6
32-
{{ end }}"></span>
28+
class="mr-1 inline-block h-3 w-3 rounded-full {{ $className }}"></span>
3329
<div class="m-0 mr-5 text-md text-neutral-800 dark:text-neutral">
3430
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
3531
</div>

layouts/shortcodes/forgejo.html

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{{ $id := delimit (slice "forgejo" (partial "functions/uid.html" .)) "-" }}
22
{{- $forgejoURL := print (.Get "server" | default .Site.Params.forgejoDefaultServer) "/api/v1/repos/" (.Get "repo") -}}
33
{{- $forgejoData := resources.GetRemote $forgejoURL | transform.Unmarshal -}}
4-
{{- $forgejoColors := .Site.Data.forgejoColors -}}
54
{{- with $forgejoData -}}
65
<div class="forgejo-card-wrapper">
76
<a id="{{ $id }}" target="_blank" href="{{ .html_url }}" class="cursor-pointer">
@@ -23,13 +22,10 @@
2322
</p>
2423

2524
<div class="m-0 mt-2 flex items-center">
25+
{{ $language := .language | default "fallback" }}
26+
{{ $className := printf "background-color-%s" (md5 $language) }}
2627
<span
27-
class="mr-1 inline-block h-3 w-3 rounded-full"
28-
style="background-color: {{ if .language }}
29-
{{- index $forgejoColors .language -}}
30-
{{ else }}
31-
#0077b6
32-
{{ end }}"></span>
28+
class="mr-1 inline-block h-3 w-3 rounded-full {{ $className }}"></span>
3329
<div class="m-0 mr-5 text-md text-neutral-800 dark:text-neutral">
3430
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
3531
</div>

layouts/shortcodes/gitea.html

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{{ $id := delimit (slice "gitea" (partial "functions/uid.html" .)) "-" }}
22
{{- $giteaURL := print (.Get "server" | default .Site.Params.giteaDefaultServer) "/api/v1/repos/" (.Get "repo") -}}
33
{{- $giteaData := resources.GetRemote $giteaURL | transform.Unmarshal -}}
4-
{{- $giteaColors := .Site.Data.giteaColors -}}
54
{{- with $giteaData -}}
65
<div class="gitea-card-wrapper">
76
<a id="{{ $id }}" target="_blank" href="{{ .html_url }}" class="cursor-pointer">
@@ -23,13 +22,10 @@
2322
</p>
2423

2524
<div class="m-0 mt-2 flex items-center">
25+
{{ $language := .language | default "fallback" }}
26+
{{ $className := printf "background-color-%s" (md5 $language) }}
2627
<span
27-
class="mr-1 inline-block h-3 w-3 rounded-full"
28-
style="background-color: {{ if .language }}
29-
{{- index $giteaColors .language -}}
30-
{{ else }}
31-
#0077b6
32-
{{ end }}"></span>
28+
class="mr-1 inline-block h-3 w-3 rounded-full {{ $className }}"></span>
3329
<div class="m-0 mr-5 text-md text-neutral-800 dark:text-neutral">
3430
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
3531
</div>

layouts/shortcodes/github.html

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{{ $id := delimit (slice "github" (partial "functions/uid.html" .)) "-" }}
22
{{- $githubURL := print "https://api.github.com/repos/" (.Get "repo") -}}
33
{{- $githubData := resources.GetRemote $githubURL | transform.Unmarshal -}}
4-
{{- $githubColors := .Site.Data.githubColors -}}
54
{{- $githubThumbnailURL := print "https://opengraph.githubassets.com/0/" (.Get "repo") -}}
65
{{- $showThumbnail := .Get "showThumbnail" | default true -}}
76

@@ -38,13 +37,10 @@
3837
</p>
3938

4039
<div class="m-0 mt-2 flex items-center">
40+
{{ $language := .language | default "fallback" }}
41+
{{ $className := printf "background-color-%s" (md5 $language) }}
4142
<span
42-
class="mr-1 inline-block h-3 w-3 rounded-full"
43-
style="background-color: {{ if .language }}
44-
{{- index $githubColors .language -}}
45-
{{ else }}
46-
#0077b6
47-
{{ end }}"></span>
43+
class="mr-1 inline-block h-3 w-3 rounded-full {{ $className }}"></span>
4844
<div class="m-0 mr-5 text-md text-neutral-800 dark:text-neutral">
4945
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
5046
</div>
@@ -76,5 +72,4 @@
7672
data-repo-id="{{ $id }}"></script>
7773
</a>
7874
{{- end -}}
79-
8075
</div>

0 commit comments

Comments
 (0)