Skip to content

Commit fa1091b

Browse files
committed
update twitter shortcode to use x api
1 parent 75b572f commit fa1091b

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

assets/css/custom.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ img {
33
}
44

55
.twitter-tweet > iframe {
6-
border-radius: 13px;
6+
border-radius: 0.75rem;
7+
border: 0.5px solid var(--color-gray-10);
78
}
89

910
.counter {

config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,7 @@ weight = 2
4444

4545
[outputs]
4646
home = ["HTML", "JSON"]
47+
48+
[privacy]
49+
[privacy.x]
50+
enableDNT = true

content/posts/09-snips-retro.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ images:
1212
- /content/snips-retro/preview.png
1313
---
1414

15-
{{< tweet "1657139515557920770" >}}
15+
{{< xweet user="robherley" id="1657139515557920770" >}}
1616

1717
## What the snip?
1818

@@ -89,9 +89,9 @@ While it's nice to keep things as simple as can be, like anything with software
8989

9090
As it turns out, people like easy to use software:
9191

92-
{{< tweet "1657456167524917248" >}}
92+
{{< xweet user="ArnabSen1729" id="1657456167524917248" >}}
9393

94-
{{< tweet "1657477244158189570" >}}
94+
{{< xweet user="silasmorkgard" id="1657477244158189570" >}}
9595

9696
## The technology
9797

layouts/shortcodes/tweet.html

Lines changed: 0 additions & 8 deletions
This file was deleted.

layouts/shortcodes/xweet.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{{- $pc := site.Config.Privacy.X -}}
2+
{{- if not $pc.Disable -}}
3+
{{- if $pc.Simple -}}
4+
{{- template "_shortcodes/x_simple.html" . -}}
5+
{{- else -}}
6+
{{- $id := or (.Get "id") "" -}}
7+
{{- $user := or (.Get "user") "" -}}
8+
{{- if and $id $user -}}
9+
{{- template "render-x" (dict "id" $id "user" $user "dnt" $pc.EnableDNT "ctx" .) -}}
10+
{{- else -}}
11+
{{- errorf "The %q shortcode requires two named parameters: user and id. See %s" .Name .Position -}}
12+
{{- end -}}
13+
{{- end -}}
14+
{{- end -}}
15+
16+
{{- define "render-x" -}}
17+
{{- $url := printf "https://x.com/%v/status/%v" .user .id -}}
18+
{{- $query := querify "url" $url "dnt" .dnt "theme" "dark" "align" "center" -}}
19+
{{- $request := printf "https://publish.x.com/oembed?%s" $query -}}
20+
{{- with try (resources.GetRemote $request) -}}
21+
{{- with .Err -}}
22+
{{- warnidf "shortcode-x-getremote" "The %q shortcode was unable to retrieve the remote data: %s. See %s" $.ctx.Name . $.ctx.Position -}}
23+
{{- else with .Value -}}
24+
{{- (. | transform.Unmarshal).html | safeHTML -}}
25+
{{- else -}}
26+
{{- warnidf "shortcode-x-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" $.ctx.Name $.ctx.Position -}}
27+
{{- end -}}
28+
{{- end -}}
29+
{{- end -}}

0 commit comments

Comments
 (0)