Files
FixIt/layouts/_shortcodes/version.html
T
Cell d55d53741d fix: dict type page parameters fall back to site parameters using merge behavior (#670)
> The `Param` method on a `Page` object looks for the given `KEY` in page parameters, and returns the corresponding value. If it cannot find the `KEY `in page parameters, it looks for the `KEY` in site parameters. If it cannot find the `KEY` in either location, the Param method returns `nil`.
>
> See: https://gohugo.io/methods/page/param/

So `.Page.Param` is only suitable for simple types.
2025-12-30 11:23:25 +08:00

24 lines
1.2 KiB
HTML

{{- $rvc := .Page.Params.repoVersion | merge .Page.Site.Params.repoVersion -}}
{{- $version := .Get 0 -}}
{{- $type := .Get 1 | default "new" | lower -}}
{{- $label := T (printf "version.%v" $type) | default (upper $type) -}}
{{- $isCJK := partial "function/is-cjk.html" . -}}
{{- $url := printf "%v%v" (.Get 2 | default $rvc.url) $version -}}
{{- $colorMap := dict
"new" "00b1ff"
"changed" "81bd65"
"deleted" "ff5252"
"deprecated" "ff9101"
-}}
{{- $color := index $colorMap $type | default (index $colorMap "new") -}}
{{- $repoName := .Get 3 | default $rvc.name -}}
{{- $pathTemplate := cond hugo.IsMultilingual (printf "images/version/%%v-%%v.%v.svg" .Page.Language.Lang) "images/version/%v-%v.svg" -}}
{{- $path := printf $pathTemplate $version $type -}}
{{- $resource := resources.Get "images/version.template.svg" -}}
{{- $resource = $resource | resources.ExecuteAsTemplate $path (dict "version" $version "label" $label "color" $color "isCJK" $isCJK) | minify -}}
{{- $alt := printf "%v %v | %v" $repoName $version $label -}}
<a href="{{ $url }}" rel="external" target="_blank" class="version-link">
{{- dict "Src" $resource.RelPermalink "Alt" $alt "Class" "version" | partial "plugin/image.html" -}}
</a>
{{- /* EOF */ -}}