🐛 Fix: invalid Mastodon configuration and icon function param error (#601)

* 🐛 Fix: parameter case exception in icon function

* 🐛 Fix: invalid Mastodon configuration
This commit is contained in:
Cell
2025-05-09 11:51:49 +08:00
committed by GitHub
parent 74f999995f
commit 2cb4bb2966
4 changed files with 28 additions and 35 deletions
-33
View File
@@ -37,39 +37,6 @@
<link rel="alternate" type="application/feed+json" href="{{ .Permalink }}" title="{{ $title }}" />
{{- end -}}
{{- /* Mastodon Validation for the site */ -}}
{{- with .Site.Params.social.Mastodon -}}
{{- $mastodonConfig := . -}}
{{- $id := "" -}}
{{- $prefix := "https://mastodon.social/" -}}
{{- /* Check if Mastodon is a string */ -}}
{{- if printf "%T" $mastodonConfig | eq "string" -}}
{{- $id = strings.TrimPrefix "@" $mastodonConfig -}}
{{- /* Check if Mastodon is a map/object */ -}}
{{- else if printf "%T" $mastodonConfig | eq "map[string]interface {}" -}}
{{- $id = .Id | default .id | default "" | strings.TrimPrefix "@" -}}
{{- $prefix = .Prefix | default .prefix | default $prefix -}}
{{- /* If it's neither a string nor a map, do nothing */ -}}
{{- else -}}
{{- errorf "Invalid Mastodon configuration: %#v" $mastodonConfig -}}
{{- end -}}
{{- /* Remove trailing slash from prefix */ -}}
{{- $prefix = strings.TrimSuffix "/" $prefix -}}
{{- /* Construct profile URL */ -}}
{{- $profileUrl := printf "%s/@%s" $prefix $id -}}
{{- /* Only proceed if we have a valid ID */ -}}
{{- if $id -}}
<link rel="me" href="{{ $profileUrl }}" />
<meta name="fediverse:creator" content="{{ $id }}@{{ (urls.Parse $prefix).Host }}" />
{{- end -}}
{{- end -}}
{{- /* style.min.css */ -}}
{{- $options := dict "Source" "css/style.scss" "Fingerprint" $fingerprint -}}
{{- $toCSS := dict "targetPath" "css/style.min.css" "enableSourceMap" true -}}
+16
View File
@@ -36,3 +36,19 @@
{{- with .Site.Params.app.tileColor -}}
<meta name="msapplication-TileColor" content="{{ . }}">
{{- end -}}
{{- /* Mastodon Validation for the site */ -}}
{{- with .Site.Params.social.Mastodon -}}
{{- $id := "" -}}
{{- $prefix := "https://mastodon.social/" -}}
{{- if reflect.IsMap . -}}
{{- $id = .Id | default .id -}}
{{- $prefix = .Prefix | default .prefix | default $prefix -}}
{{- end -}}
{{- if $id | and $prefix -}}
{{- $link := printf "%s/%s" $prefix $id -}}
{{- $email := printf "%s@%s" (strings.TrimPrefix "@" $id) (urls.Parse $prefix).Host -}}
<link rel="me" href="{{ $link }}" />
<meta name="fediverse:creator" content="{{ $email }}" />
{{- end -}}
{{- end -}}
+11 -1
View File
@@ -89,7 +89,17 @@
{{- $social = dict "Newtab" . | merge $social -}}
{{- end -}}
{{- with $value.icon -}}
{{- $social = dict "Icon" . | merge $social -}}
{{- $icon := dict -}}
{{- with .class -}}
{{- $icon = dict "Class" . | merge $icon -}}
{{- end -}}
{{- with .simpleicons -}}
{{- $icon = dict "Simpleicons" . | merge $icon -}}
{{- end -}}
{{- with .src -}}
{{- $icon = dict "Src" . | merge $icon -}}
{{- end -}}
{{- $social = dict "Icon" $icon | merge $social -}}
{{- end -}}
{{- else if ne $value true -}}
{{- $social = dict "Id" $value | merge $social -}}
+1 -1
View File
@@ -8,7 +8,7 @@
{{- end -}}
{{- if not $src -}}
{{- errorf "Icon src is missing" -}}
{{- errorf "Icon src is missing: %s" templates.Current.Filename -}}
{{- end -}}
{{- if (urls.Parse $src).Host | not -}}