Skip to content

Commit

Permalink
Merge pull request #22 from khusika/oembed
Browse files Browse the repository at this point in the history
Update oEmbed Twitter
  • Loading branch information
Khusika Dhamar Gusti authored Jun 27, 2021
2 parents 1d70fd0 + b5a4de5 commit 3a88126
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 50 deletions.
2 changes: 1 addition & 1 deletion assets/css/_partial/_single/_oembed.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
iframe.instagram-media {
iframe.instagram-media, #twitter-widget-0 {
min-width: 100px !important;
[theme=dark] & {
border: none !important;
Expand Down
7 changes: 5 additions & 2 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,13 @@ ignoreErrors = ["err-missing-comment-accesstoken", "err-missing-oembed-accesstok

# oEmbed config for Facebook and Instagram
[params.oembed]
# Facebook Aplication Identity and Client Token (<APPID>|<CLIENTTOKEN>)
accessToken = ""
# Privacy config (https://gohugo.io/about/hugo-and-gdpr/)
privacy = false
[params.oembed.facebook]
# Facebook Aplication Identity and Client Token (<APPID>|<CLIENTTOKEN>)
accessToken = ""
[params.oembed.twitter]
enableDNT = false

# Page config
# 文章页面配置
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,15 @@ Please open the code block below to view the complete sample configuration :(far
# default behavior when you don't set "hiddenFromHomePage" in front matter
defaultHiddenFromHomePage = false

# {{< version 1.0.1 changed >}} oEmbed config for Facebook and Instagram
# {{< version 1.0.1 changed >}} oEmbed config
[params.oembed]
# Facebook Aplication Identity and Client Token (<APPID>|<CLIENTTOKEN>)
accessToken = ""
# Privacy config (https://gohugo.io/about/hugo-and-gdpr/)
privacy = false
[params.oembed.facebook]
# Facebook Aplication Identity and Client Token (<APPID>|<CLIENTTOKEN>)
accessToken = ""
[params.oembed.twitter]
enableDNT = false

# Social config about the author
[params.social]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,15 @@ Please open the code block below to view the complete sample configuration :(far
# default behavior when you don't set "hiddenFromHomePage" in front matter
defaultHiddenFromHomePage = false

# {{< version 1.0.1 changed >}} oEmbed config for Facebook and Instagram
# {{< version 1.0.1 changed >}} oEmbed config
[params.oembed]
# Facebook Aplication Identity and Client Token (<APPID>|<CLIENTTOKEN>)
accessToken = ""
# Privacy config (https://gohugo.io/about/hugo-and-gdpr/)
privacy = false
[params.oembed.facebook]
# Facebook Aplication Identity and Client Token (<APPID>|<CLIENTTOKEN>)
accessToken = ""
[params.oembed.twitter]
enableDNT = false

# Social config about the author
[params.social]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,15 @@ hugo
# 当你没有在文章前置参数中设置 "hiddenFromHomePage" 时的默认行为
defaultHiddenFromHomePage = false

# {{< version 1.0.1 changed >}} oEmbed config for Facebook and Instagram
# {{< version 1.0.1 changed >}} oEmbed config
[params.oembed]
# Facebook Aplication Identity and Client Token (<APPID>|<CLIENTTOKEN>)
accessToken = ""
# Privacy config (https://gohugo.io/about/hugo-and-gdpr/)
privacy = false
[params.oembed.facebook]
# Facebook Aplication Identity and Client Token (<APPID>|<CLIENTTOKEN>)
accessToken = ""
[params.oembed.twitter]
enableDNT = false

# 作者的社交信息设置
[params.social]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,9 @@ The rendered output looks like this:

## 7 tweet

[Documentation of `tweet`](https://gohugo.io/content-management/shortcodes#tweet)
{{< version 1.0.1 changed >}}

Example `tweet` input:

```markdown
{{</* tweet 877500564405444608 */>}}
```

The rendered output looks like this:

{{< tweet 877500564405444608 >}}
This method was moved with the newest API in the [extended shortcode documentation](https://feelit.khusika.com/theme-documentation-extended-shortcodes/#123-oembed-twitter).

## 8 vimeo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,9 @@ The rendered output looks like this:

## 7 tweet

[Documentation of `tweet`](https://gohugo.io/content-management/shortcodes#tweet)
{{< version 1.0.1 changed >}}

Example `tweet` input:

```markdown
{{</* tweet 877500564405444608 */>}}
```

The rendered output looks like this:

{{< tweet 877500564405444608 >}}
This method was moved with the newest API in the [extended shortcode documentation](https://feelit.khusika.com/theme-documentation-extended-shortcodes/#123-oembed-twitter).

## 8 vimeo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,9 @@ At the moment, Hugo using deprecated [oEmbed-legacy](https://developers.facebook

## 7 tweet

[`tweet` 的文档](https://gohugo.io/content-management/shortcodes#tweet)
{{< version 1.0.1 changed >}}

一个 `tweet` 示例:

```markdown
{{</* tweet 877500564405444608 */>}}
```

呈现的输出效果如下:

{{< tweet 877500564405444608 >}}
This method was moved with the newest API in the [extended shortcode documentation](https://feelit.khusika.com/theme-documentation-extended-shortcodes/#123-oembed-twitter).

## 8 vimeo

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1394,3 +1394,16 @@ Sample input of Instagram TV
Sample output of Instagram TV

{{< oembed "ig" "tv" "BkQUbR8h1sp" "hidecaption" >}}

### 12.3 oEmbed Twitter
{{< version 1.0.1 >}}

Sample input of 'oembed tweet'

```markdown
{{</* oembed "tweet" "https://twitter.com/GoHugoIO/status/877500564405444608" */>}}
```

Sample output of 'oembed tweet'

{{< oembed "tweet" "https://twitter.com/GoHugoIO/status/877500564405444608" >}}
Original file line number Diff line number Diff line change
Expand Up @@ -1399,3 +1399,16 @@ Sample input of Instagram TV
Sample output of Instagram TV

{{< oembed "ig" "tv" "BkQUbR8h1sp" "hidecaption" >}}

### 12.3 oEmbed Twitter
{{< version 1.0.1 >}}

Sample input of 'oembed tweet'

```markdown
{{</* oembed "tweet" "https://twitter.com/GoHugoIO/status/877500564405444608" */>}}
```

Sample output of 'oembed tweet'

{{< oembed "tweet" "https://twitter.com/GoHugoIO/status/877500564405444608" >}}
Original file line number Diff line number Diff line change
Expand Up @@ -1396,3 +1396,16 @@ Sample input of Instagram TV
Sample output of Instagram TV

{{< oembed "ig" "tv" "BkQUbR8h1sp" "hidecaption" >}}

### 12.3 oEmbed Twitter
{{< version 1.0.1 >}}

Sample input of 'oembed tweet'

```markdown
{{</* oembed "tweet" "https://twitter.com/GoHugoIO/status/877500564405444608" */>}}
```

Sample output of 'oembed tweet'

{{< oembed "tweet" "https://twitter.com/GoHugoIO/status/877500564405444608" >}}
21 changes: 14 additions & 7 deletions layouts/shortcodes/oembed.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{{- $oe := .Site.Params.oembed -}}
{{- $accessToken := getenv "HUGO_OEMBED_ACCESSTOKEN" | default $oe.accessToken -}}

{{- if not $accessToken -}}
{{- erroridf "err-missing-oembed-accesstoken" "oembed shortcode: Missing config value for .Site.Params.oembed.accessToken. This can be set in config.toml, but it is recommended to configure this via the HUGO_OEMBED_ACCESSTOKEN OS environment variable. If you are using a Client Access Token, remember that you must combine it with your App ID using a pipe symbol (<APPID>|<CLIENTTOKEN>) otherwise the request will fail." -}}
{{- else -}}
{{- if not $oe.privacy -}}
{{ $host := .Get 0 }}
{{ $host := .Get 0 }}
{{- if not $oe.privacy -}}
{{- if or (eq $host "ig") (eq $host "fb") -}}
{{- $accessToken := getenv "HUGO_OEMBED_ACCESSTOKEN" | default $oe.facebook.accessToken -}}
{{- if not $accessToken -}}
{{- erroridf "err-missing-oembed-accesstoken" "oembed shortcode: Missing config value for .Site.Params.oembed.accessToken. This can be set in config.toml, but it is recommended to configure this via the HUGO_OEMBED_ACCESSTOKEN OS environment variable. If you are using a Client Access Token, remember that you must combine it with your App ID using a pipe symbol (<APPID>|<CLIENTTOKEN>) otherwise the request will fail." -}}
{{- else -}}
{{ $type := .Get 1 }}
{{ $id := .Get 2 }}
{{- if eq $host "ig" -}}
Expand All @@ -25,4 +25,11 @@
{{- end -}}
{{- end -}}
{{- end -}}
{{- else if (eq $host "tweet") -}}
{{ $url := .Get 1 }}
{{- $dnt := $oe.twitter.enableDNT | default false -}}
{{ with getJSON "https://publish.twitter.com/oembed" "?url=" $url "&dnt=" $dnt }}
{{ .html | safeHTML }}
{{ end }}
{{- end -}}
{{- end -}}

Large diffs are not rendered by default.

0 comments on commit 3a88126

Please sign in to comment.