Files
blowfish/layouts/shortcodes/github.html
ZhenShuo Leo 884d84363e Revert "perf(repo-card): only generate used CSS class"
This reverts commit af221fbf3b.

fix language dot colors in repo-card not displaying

This occurs because head.html is rendered before the page content,
making .Page.Store unavailable at that point in the template
execution order.

This issue doesn't appear in local development because page refreshes
trigger full re-renders, allowing the Store values to be properly
populated from shortcodes.

Alternative solutions considered:

1. templates.Defer: too complex and unreliable
2. Moving CSS to footer: confusing and delayed load
3. Inline styles: incurs CSP issue

Final I choose pre-generate CSS for all languages. After zstd
compression, the CSS file is only 8KB and benefits from browser
caching across all pages.
2025-10-17 14:38:24 +08:00

84 lines
3.5 KiB
HTML

{{ $id := delimit (slice "github" (partial "functions/uid.html" .)) "-" }}
{{- $githubURL := print "https://api.github.com/repos/" (.Get "repo") -}}
{{- $githubThumbnailURL := print "https://opengraph.githubassets.com/0/" (.Get "repo") -}}
{{- $showThumbnail := .Get "showThumbnail" | default true -}}
{{- $repoColors := .Site.Data.repoColors -}}
{{- $githubData := dict -}}
{{- with try (resources.GetRemote $githubURL) -}}
{{- with .Err -}}
{{- warnf "github shortcode: failed to fetch remote resource from %q: %s" $githubURL $.Position -}}
{{- else with .Value -}}
{{- $githubData = . | transform.Unmarshal -}}
{{- else -}}
{{- warnf "github shortcode: unable to get remote resource from %q: %s" $githubURL $.Position -}}
{{- end -}}
{{- end -}}
{{- with $githubData -}}
<div class="github-card-wrapper">
<a id="{{ $id }}" target="_blank" href="{{ .html_url }}" class="cursor-pointer">
<div
class="w-full md:w-auto p-0 m-0 border border-neutral-200 dark:border-neutral-700 border rounded-md shadow-2xl">
{{- if $showThumbnail -}}
<div class="w-full nozoom">
<img
src="{{ $githubThumbnailURL }}"
alt="GitHub Repository Thumbnail"
class="nozoom mt-0 mb-0 w-full h-full object-cover">
</div>
{{- end -}}
<div class="w-full md:w-auto pt-3 p-5">
<div class="flex items-center">
<span class="text-2xl text-neutral-800 dark:text-neutral me-2">
{{ partial "icon.html" "github" }}
</span>
<div
id="{{ $id }}-full_name"
class="m-0 font-bold text-xl text-neutral-800 decoration-primary-500 hover:underline hover:underline-offset-2 dark:text-neutral">
{{ .full_name | markdownify }}
</div>
</div>
<p id="{{ $id }}-description" class="m-0 mt-2 text-md text-neutral-800 dark:text-neutral">
{{ .description | markdownify }}
</p>
<div class="m-0 mt-2 flex items-center">
<span class="mr-1 inline-block h-3 w-3 rounded-full language-dot" data-language="{{ .language | default "default" }}"></span>
<div class="m-0 mr-5 text-md text-neutral-800 dark:text-neutral">
{{ if .language }}{{ .language }}{{ else }}null{{ end }}
</div>
<span class="text-md mr-1 text-neutral-800 dark:text-neutral">
{{ partial "icon.html" "star" }}
</span>
<div id="{{ $id }}-stargazers" class="m-0 mr-5 text-md text-neutral-800 dark:text-neutral">
{{ .stargazers_count }}
</div>
<span class="text-md mr-1 text-neutral-800 dark:text-neutral">
{{ partial "icon.html" "fork" }}
</span>
<div id="{{ $id }}-forks" class="m-0 mr-5 text-md text-neutral-800 dark:text-neutral">
{{ .forks }}
</div>
</div>
</div>
</div>
{{ $fetchRepo := resources.Get "js/fetch-repo.js" }}
{{ $fetchRepo = $fetchRepo | resources.Minify | resources.Fingerprint ($.Site.Params.fingerprintAlgorithm | default "sha512") }}
<script
async
type="text/javascript"
src="{{ $fetchRepo.RelPermalink }}"
integrity="{{ $fetchRepo.Data.Integrity }}"
data-repo-url="{{ $githubURL }}"
data-repo-id="{{ $id }}"></script>
</a>
</div>
{{- else -}}
{{ warnf "github shortcode: unable to fetch %q: %s" $githubURL .Position }}
{{- end -}}