Skip to content

Commit a30083b

Browse files
committed
♻️ Refactor Use universal json and move styles out of line
1 parent 2f12b8d commit a30083b

File tree

9 files changed

+45
-1627
lines changed

9 files changed

+45
-1627
lines changed

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.

layouts/partials/head.html

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,31 @@
4545
{{ if $cssCustom }}
4646
{{ $assets.Add "css" (slice $cssCustom) }}
4747
{{ end }}
48+
49+
{{ $repoShortcodeExists := false }}
50+
{{ range .Site.Pages }}
51+
{{ if or (.Page.HasShortcode "codeberg") (.Page.HasShortcode "forgejo") (.Page.HasShortcode "gitea") (.Page.HasShortcode "github") }}
52+
{{ $repoShortcodeExists = true }}
53+
{{ end }}
54+
{{ end }}
55+
{{ if $repoShortcodeExists }}
56+
{{ $colorsRepos := .Site.Data.colorsRepos }}
57+
{{ range $language, $color := $colorsRepos }}
58+
{{ if not $color }}
59+
{{ $color = "" }}
60+
{{ end }}
61+
{{ $className := printf "color-repo-%s" (md5 $language) }}
62+
{{ $cssColorRepos := printf ".%s { background-color: %s; }" $className $color }}
63+
{{ $cssColorRepos = $cssColorRepos | resources.FromString "css/color-repo.css" }}
64+
{{ $assets.Add "css" (slice $cssColorRepos) }}
65+
{{ end }}
66+
{{ $color := "#0077b6" }}
67+
{{ $className := "color-repo-fallback" }}
68+
{{ $cssColorRepos := printf ".%s { background-color: %s; }" $className $color }}
69+
{{ $cssColorRepos = $cssColorRepos | resources.FromString "css/color-repo.css" }}
70+
{{ $assets.Add "css" (slice $cssColorRepos) }}
71+
{{ end }}
72+
4873
{{ $bundleCSS := $assets.Get "css" | resources.Concat "css/main.bundle.css" | resources.Minify | resources.Fingerprint
4974
(.Site.Params.fingerprintAlgorithm | default "sha512") }}
5075
<link type="text/css" rel="stylesheet" href="{{ $bundleCSS.RelPermalink }}"

layouts/shortcodes/codeberg.html

Lines changed: 5 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,12 @@
2322
</p>
2423

2524
<div class="m-0 mt-2 flex items-center">
25+
{{ $className := "color-repo-fallback" }}
26+
{{ if .language }}
27+
{{ $className = printf "color-repo-%s" (md5 .language) }}
28+
{{ end }}
2629
<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>
30+
class="mr-1 inline-block h-3 w-3 rounded-full {{ $className }}"></span>
3331
<div class="m-0 mr-5 text-md text-neutral-800 dark:text-neutral">
3432
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
3533
</div>

layouts/shortcodes/forgejo.html

Lines changed: 5 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,12 @@
2322
</p>
2423

2524
<div class="m-0 mt-2 flex items-center">
25+
{{ $className := "color-repo-fallback" }}
26+
{{ if .language }}
27+
{{ $className = printf "color-repo-%s" (md5 .language) }}
28+
{{ end }}
2629
<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>
30+
class="mr-1 inline-block h-3 w-3 rounded-full {{ $className }}"></span>
3331
<div class="m-0 mr-5 text-md text-neutral-800 dark:text-neutral">
3432
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
3533
</div>

layouts/shortcodes/gitea.html

Lines changed: 5 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,12 @@
2322
</p>
2423

2524
<div class="m-0 mt-2 flex items-center">
25+
{{ $className := "color-repo-fallback" }}
26+
{{ if .language }}
27+
{{ $className = printf "color-repo-%s" (md5 .language) }}
28+
{{ end }}
2629
<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>
30+
class="mr-1 inline-block h-3 w-3 rounded-full {{ $className }}"></span>
3331
<div class="m-0 mr-5 text-md text-neutral-800 dark:text-neutral">
3432
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
3533
</div>

layouts/shortcodes/github.html

Lines changed: 5 additions & 7 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,12 @@
3837
</p>
3938

4039
<div class="m-0 mt-2 flex items-center">
40+
{{ $className := "color-repo-fallback" }}
41+
{{ if .language }}
42+
{{ $className = printf "color-repo-%s" (md5 .language) }}
43+
{{ end }}
4144
<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>
45+
class="mr-1 inline-block h-3 w-3 rounded-full {{ $className }}"></span>
4846
<div class="m-0 mr-5 text-md text-neutral-800 dark:text-neutral">
4947
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
5048
</div>

0 commit comments

Comments
 (0)