refactor social-quote-tweet and social_links to use social_quote_tweet partial

This commit is contained in:
Reorx 2022-05-18 14:24:29 +08:00
parent 7c253d3fee
commit ecaf84c7c7
3 changed files with 19 additions and 34 deletions

View File

@ -1,20 +1,7 @@
<div class="social-links"> <div class="social-links">
{{ with .Params.socialLinks.twitter }} {{- with .Params.socialLinks.twitter }}
{{ if (and .id .user) }} {{- if (and .id .user) }}
<div class="tweet social-quote"> {{ partial "social_quote_tweet.html" (dict "user" .user "id" .id "title" "Discuss on Twitter") }}
<div class="title"> {{- end }}
Discuss on twitter {{- end }}
</div>
{{- template "render-tweet" (dict "id" .id "user" .user "dnt" true) -}}
</div>
{{ end }}
{{ end }}
</div> </div>
{{- define "render-tweet" -}}
{{- $url := printf "https://twitter.com/%v/status/%v" .user .id -}}
{{- $query := querify "url" $url "dnt" .dnt -}}
{{- $request := printf "https://publish.twitter.com/oembed?%s" $query -}}
{{- $json := getJSON $request -}}
{{- replaceRE "<script.+/script>" "" $json.html | safeHTML -}}
{{- end -}}

View File

@ -0,0 +1,13 @@
<div class="tweet social-quote">
<div class="title">
{{ safeHTML (index site.Data.svg "twitter-simple") }}
{{ with .title }}<span>{{ . }}</span>{{ end }}
</div>
{{ $dnt := true }}
{{- $url := printf "https://twitter.com/%v/status/%v" .user .id -}}
{{- $query := querify "url" $url "dnt" $dnt -}}
{{- $request := printf "https://publish.twitter.com/oembed?%s" $query -}}
{{- $json := getJSON $request -}}
{{- replaceRE "<script.+/script>" "" $json.html | safeHTML -}}
</div>

View File

@ -1,16 +1 @@
<div class="tweet social-quote"> {{ partial "social_quote_tweet.html" (dict "user" (.Get "user") "id" (.Get "id") "title" .Inner) }}
<div class="title">
{{ safeHTML (index $.Site.Data.svg "twitter-simple") }}
{{ with .Inner }}<span>{{ . }}</span>{{ end }}
</div>
{{ $user := .Get "user" }}
{{ $id := .Get "id" }}
{{ $dnt := true }}
{{- .Inner -}}{{/* not required, only to not break Obsidian highlight by adding `/` before `>` */}}
{{- $url := printf "https://twitter.com/%v/status/%v" $user $id -}}
{{- $query := querify "url" $url "dnt" $dnt -}}
{{- $request := printf "https://publish.twitter.com/oembed?%s" $query -}}
{{- $json := getJSON $request -}}
{{- replaceRE "<script.+/script>" "" $json.html | safeHTML -}}
</div>