From 7efb9fc3ac7dde1aba98411e93adefdaba0499be Mon Sep 17 00:00:00 2001 From: Cell <1024@lruihao.cn> Date: Tue, 23 Dec 2025 11:10:38 +0800 Subject: [PATCH] perf: add bluesky shortcode with remote JSON retrieval and styling --- assets/css/_shortcodes/_bluesky.scss | 3 +++ assets/css/_shortcodes/_index.scss | 1 + .../_partials/function/get-remote-json.html | 21 ++++++++++++------- layouts/_partials/init/index.html | 2 +- layouts/_shortcodes/bluesky.html | 8 +++---- 5 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 assets/css/_shortcodes/_bluesky.scss diff --git a/assets/css/_shortcodes/_bluesky.scss b/assets/css/_shortcodes/_bluesky.scss new file mode 100644 index 00000000..82e4e9d3 --- /dev/null +++ b/assets/css/_shortcodes/_bluesky.scss @@ -0,0 +1,3 @@ +.bluesky-embed { + margin: 1rem auto; +} diff --git a/assets/css/_shortcodes/_index.scss b/assets/css/_shortcodes/_index.scss index e63b3003..2e5cbf4e 100644 --- a/assets/css/_shortcodes/_index.scss +++ b/assets/css/_shortcodes/_index.scss @@ -1,5 +1,6 @@ @import '_admonition'; @import '_bilibili'; +@import '_bluesky'; @import '_douyin'; @import '_cardlink'; @import '_center-quote'; diff --git a/layouts/_partials/function/get-remote-json.html b/layouts/_partials/function/get-remote-json.html index 0f7deb7d..e1c4d6bb 100644 --- a/layouts/_partials/function/get-remote-json.html +++ b/layouts/_partials/function/get-remote-json.html @@ -1,11 +1,18 @@ {{- $response := dict -}} -{{- with try (resources.GetRemote .URL .OPTIONS) -}} - {{- with .Err -}} - {{- erroridf "error-get-remote-json" "%s" . -}} - {{- else with .Value -}} - {{- $response = .Content | transform.Unmarshal -}} - {{- else -}} - {{- erroridf "error-get-remote-json" "Unable to get remote resource %q" $.URL -}} +{{- $url := .URL -}} +{{- $options := .OPTIONS | default dict -}} + +{{- if $url -}} + {{- $cacheKey := print $url (now.Format "2006-01-02") -}} + {{- $options = $options | merge (dict "key" $cacheKey) -}} + {{- with try (resources.GetRemote $url $options) -}} + {{- with .Err -}} + {{- erroridf "error-get-remote-json" "%s" . -}} + {{- else with .Value -}} + {{- $response = .Content | transform.Unmarshal -}} + {{- else -}} + {{- erroridf "error-get-remote-json" "Failed to get remote JSON %q" $url -}} + {{- end -}} {{- end -}} {{- end -}} diff --git a/layouts/_partials/init/index.html b/layouts/_partials/init/index.html index b251ce4f..29bd627b 100644 --- a/layouts/_partials/init/index.html +++ b/layouts/_partials/init/index.html @@ -1,4 +1,4 @@ -{{- hugo.Store.Set "version" "v0.4.0-alpha.3-20251222094907-1bb21fcb" -}} +{{- hugo.Store.Set "version" "v0.4.0-alpha.3-20251223031039-a78c07f7" -}} {{- .Store.Set "this" dict -}} {{- partial "init/detection-env.html" . -}} diff --git a/layouts/_shortcodes/bluesky.html b/layouts/_shortcodes/bluesky.html index 2246caa4..a34f08ee 100644 --- a/layouts/_shortcodes/bluesky.html +++ b/layouts/_shortcodes/bluesky.html @@ -1,7 +1,5 @@ -{{- $link := .Get "link" -}} +{{- $link := .Get "link" -}} {{- $query := querify "url" $link -}} {{- $request := printf "https://embed.bsky.app/oembed?%s" $query -}} -{{- $jsonOembed := resources.GetRemote $request -}} -{{- $jsonOembed = $jsonOembed | transform.Unmarshal -}} -{{- $jsonOHTML := $jsonOembed.html -}} -{{- $jsonOHTML | safeHTML -}} +{{- $jsonOembed := partial "function/get-remote-json" (dict "URL" $request) -}} +{{- $jsonOembed.html | safeHTML -}}