]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
tpl/tplimpl: Throw error when calling twitter/twitter_simple shortcodes
authorJoe Mooring <joe@mooring.com>
Thu, 12 Feb 2026 10:59:09 +0000 (02:59 -0800)
committerGitHub <noreply@github.com>
Thu, 12 Feb 2026 10:59:09 +0000 (11:59 +0100)
Closes #14488

tpl/tplimpl/embedded/templates/_shortcodes/twitter.html
tpl/tplimpl/embedded/templates/_shortcodes/twitter_simple.html
tpl/tplimpl/shortcodes_integration_test.go

index c6200ffd279d99331f4291375e9a37689c736efb..1be6c2d6b70e45a02053f0b3ff7a5cf0f81d9a6c 100644 (file)
@@ -1,30 +1 @@
-{{- warnf "The \"twitter\", \"tweet\", and \"twitter_simple\" shortcodes were deprecated in v0.142.0 and will be removed in a future release. Please use the \"x\" shortcode instead." }}
-{{- $pc := site.Config.Privacy.Twitter -}}
-{{- if not $pc.Disable -}}
-  {{- if $pc.Simple -}}
-    {{- template "_shortcodes/twitter_simple.html" . -}}
-  {{- else -}}
-    {{- $id := or (.Get "id") "" -}}
-    {{- $user := or (.Get "user") "" -}}
-    {{- if and $id $user -}}
-      {{- template "render-tweet" (dict "id" $id "user" $user "dnt" $pc.EnableDNT "ctx" .) -}}
-    {{- else -}}
-      {{- errorf "The %q shortcode requires two named parameters: user and id. See %s" .Name .Position -}}
-    {{- end -}}
-  {{- end -}}
-{{- end -}}
-
-{{- 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 -}}
-  {{- with try (resources.GetRemote $request) -}}
-    {{- with .Err -}}
-      {{- warnidf "shortcode-twitter-getremote" "The %q shortcode was unable to retrieve the remote data: %s. See %s" $.ctx.Name . $.ctx.Position -}}
-    {{- else with .Value -}}
-      {{- (. | transform.Unmarshal).html | safeHTML -}}
-    {{- else -}}
-      {{- warnidf "shortcode-twitter-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" $.ctx.Name $.ctx.Position -}}
-    {{- end -}}
-  {{- end -}}
-{{- end -}}
+{{- errorf "The \"twitter\", \"tweet\", and \"twitter_simple\" shortcodes were deprecated in v0.142.0 and removed in v0.156.0. Please use the \"x\" shortcode instead." }}
index 34150393d06bc4a1962aa154202ffda381502e76..1be6c2d6b70e45a02053f0b3ff7a5cf0f81d9a6c 100644 (file)
@@ -1,61 +1 @@
-{{- warnf "The \"twitter\", \"tweet\", and \"twitter_simple\" shortcodes were deprecated in v0.142.0 and will be removed in a future release. Please use the \"x\" shortcode instead." }}
-{{- if not site.Config.Privacy.Twitter.Disable -}}
-  {{- $id := or (.Get "id") "" -}}
-  {{- $user := or (.Get "user") "" -}}
-  {{- if and $id $user -}}
-    {{- template "render-simple-tweet" (dict "id" $id "user" $user "ctx" .) -}}
-  {{- else -}}
-    {{- errorf "The %q shortcode requires two named parameters: user and id. See %s" .Name .Position -}}
-  {{- end -}}
-{{- end -}}
-
-{{- define "render-simple-tweet" -}}
-  {{- $dnt := site.Config.Privacy.Twitter.EnableDNT }}
-  {{- $url := printf "https://twitter.com/%v/status/%v" .user .id -}}
-  {{- $query := querify "url" $url "dnt" $dnt "omit_script" true -}}
-  {{- $request := printf "https://publish.twitter.com/oembed?%s" $query -}}
-  {{- with try (resources.GetRemote $request) -}}
-    {{- with .Err -}}
-      {{- warnidf "shortcode-twitter-simple-getremote" "The %q shortcode was unable to retrieve the remote data: %s. See %s" $.ctx.Name . $.ctx.Position -}}
-    {{- else with .Value -}}
-      {{- if not site.Config.Services.Twitter.DisableInlineCSS }}
-        {{- template "__h_simple_twitter_css" (dict "ctx" $.ctx) }}
-      {{- end }}
-      {{- (. | transform.Unmarshal).html | safeHTML -}}
-    {{- else -}}
-      {{- warnidf "shortcode-twitter-simple-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" $.ctx.Name $.ctx.Position -}}
-    {{- end -}}
-  {{- end -}}
-{{- end -}}
-
-{{- define "__h_simple_twitter_css" -}}
-  {{- if not (.ctx.Page.Store.Get "__h_simple_twitter_css") -}}
-    {{/* Only include once */}}
-    {{- .ctx.Page.Store.Set "__h_simple_twitter_css" true -}}
-    <style type="text/css">
-      .twitter-tweet {
-        font:
-          14px/1.45 -apple-system,
-          BlinkMacSystemFont,
-          "Segoe UI",
-          Roboto,
-          Oxygen-Sans,
-          Ubuntu,
-          Cantarell,
-          "Helvetica Neue",
-          sans-serif;
-        border-left: 4px solid #2b7bb9;
-        padding-left: 1.5em;
-        color: #555;
-      }
-      .twitter-tweet a {
-        color: #2b7bb9;
-        text-decoration: none;
-      }
-      blockquote.twitter-tweet a:hover,
-      blockquote.twitter-tweet a:focus {
-        text-decoration: underline;
-      }
-    </style>
-  {{- end -}}
-{{- end -}}
+{{- errorf "The \"twitter\", \"tweet\", and \"twitter_simple\" shortcodes were deprecated in v0.142.0 and removed in v0.156.0. Please use the \"x\" shortcode instead." }}
index e6f5668482327f637064ac1d40ba72b0d3349a15..6a0c20c69057c91adb2e69292674c2d437461ded 100644 (file)
@@ -19,7 +19,6 @@ import (
 
        qt "github.com/frankban/quicktest"
        "github.com/gohugoio/hugo/htesting"
-       "github.com/gohugoio/hugo/htesting/hqt"
        "github.com/gohugoio/hugo/hugolib"
 )
 
@@ -505,9 +504,6 @@ Content: {{ .Content }}
        b.AssertLogContains(`WARN  The "vimeo" shortcode was unable to retrieve the remote data.`)
 }
 
-// Issue 13214
-// We deprecated the twitter, tweet (alias of twitter), and twitter_simple
-// shortcodes in v0.141.0, replacing them with x and x_simple.
 func TestXShortcodes(t *testing.T) {
        t.Parallel()
        htesting.SkipSlowTestUnlessCI(t)
@@ -525,22 +521,7 @@ title: p1
 ---
 title: p2
 ---
-{{< twitter user="SanDiegoZoo" id="1453110110599868418" >}}
--- content/p3.md --
----
-title: p3
----
-{{< tweet user="SanDiegoZoo" id="1453110110599868418" >}}
--- content/p4.md --
----
-title: p4
----
 {{< x_simple user="SanDiegoZoo" id="1453110110599868418" >}}
--- content/p5.md --
----
-title: p5
----
-{{< twitter_simple user="SanDiegoZoo" id="1453110110599868418" >}}
 -- layouts/single.html --
 {{ .Content | strings.TrimSpace | safeHTML }}
 --
@@ -548,62 +529,26 @@ title: p5
 
        b := hugolib.Test(t, files)
 
-       // Test x, twitter, and tweet shortcodes
+       // Test x shortcode
        want := `<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Owl bet you&#39;ll lose this staring contest ðŸ¦‰ <a href="https://t.co/eJh4f2zncC">pic.twitter.com/eJh4f2zncC</a></p>&mdash; San Diego Zoo Wildlife Alliance (@sandiegozoo) <a href="https://twitter.com/sandiegozoo/status/1453110110599868418?ref_src=twsrc%5Etfw">October 26, 2021</a></blockquote>
        <script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>`
        b.AssertFileContent("public/p1/index.html", want)
 
-       htmlFiles := []string{
-               b.FileContent("public/p1/index.html"),
-               b.FileContent("public/p2/index.html"),
-               b.FileContent("public/p3/index.html"),
-       }
-
-       b.Assert(htmlFiles, hqt.IsAllElementsEqual)
-
-       // Test x_simple and twitter_simple shortcodes
+       // Test x_simple shortcodes
        wantSimple := "<style type=\"text/css\">\n      .twitter-tweet {\n        font:\n          14px/1.45 -apple-system,\n          BlinkMacSystemFont,\n          \"Segoe UI\",\n          Roboto,\n          Oxygen-Sans,\n          Ubuntu,\n          Cantarell,\n          \"Helvetica Neue\",\n          sans-serif;\n        border-left: 4px solid #2b7bb9;\n        padding-left: 1.5em;\n        color: #555;\n      }\n      .twitter-tweet a {\n        color: #2b7bb9;\n        text-decoration: none;\n      }\n      blockquote.twitter-tweet a:hover,\n      blockquote.twitter-tweet a:focus {\n        text-decoration: underline;\n      }\n    </style><blockquote class=\"twitter-tweet\"><p lang=\"en\" dir=\"ltr\">Owl bet you&#39;ll lose this staring contest ðŸ¦‰ <a href=\"https://t.co/eJh4f2zncC\">pic.twitter.com/eJh4f2zncC</a></p>&mdash; San Diego Zoo Wildlife Alliance (@sandiegozoo) <a href=\"https://twitter.com/sandiegozoo/status/1453110110599868418?ref_src=twsrc%5Etfw\">October 26, 2021</a></blockquote>\n--"
-       b.AssertFileContent("public/p4/index.html", wantSimple)
-
-       htmlFiles = []string{
-               b.FileContent("public/p4/index.html"),
-               b.FileContent("public/p5/index.html"),
-       }
-       b.Assert(htmlFiles, hqt.IsAllElementsEqual)
-
-       filesOriginal := files
+       b.AssertFileContent("public/p2/index.html", wantSimple)
 
        // Test privacy.x.simple
-       files = strings.ReplaceAll(filesOriginal, "#CONFIG", "privacy.x.simple=true")
-       b = hugolib.Test(t, files)
-       htmlFiles = []string{
-               b.FileContent("public/p1/index.html"),
-               b.FileContent("public/p4/index.html"),
-               b.FileContent("public/p4/index.html"),
-       }
-       b.Assert(htmlFiles, hqt.IsAllElementsEqual)
-
-       htmlFiles = []string{
-               b.FileContent("public/p2/index.html"),
-               b.FileContent("public/p3/index.html"),
-       }
-       b.Assert(htmlFiles, hqt.IsAllElementsEqual)
+       f := strings.ReplaceAll(files, "#CONFIG", "privacy.x.simple=true")
+       b = hugolib.Test(t, f)
+       b.AssertFileContent("public/p1/index.html", wantSimple)
+       b.AssertFileContent("public/p2/index.html", wantSimple)
 
        // Test privacy.x.disable
-       files = strings.ReplaceAll(filesOriginal, "#CONFIG", "privacy.x.disable = true")
-       b = hugolib.Test(t, files)
+       f = strings.ReplaceAll(files, "#CONFIG", "privacy.x.disable = true")
+       b = hugolib.Test(t, f)
        b.AssertFileContent("public/p1/index.html", "")
-       htmlFiles = []string{
-               b.FileContent("public/p1/index.html"),
-               b.FileContent("public/p4/index.html"),
-       }
-       b.Assert(htmlFiles, hqt.IsAllElementsEqual)
-
-       htmlFiles = []string{
-               b.FileContent("public/p2/index.html"),
-               b.FileContent("public/p3/index.html"),
-       }
-       b.Assert(htmlFiles, hqt.IsAllElementsEqual)
+       b.AssertFileContent("public/p2/index.html", "")
 
        // Test warnings
        files = `
@@ -615,8 +560,6 @@ title: home
 ---
 {{< x user="__user_does_not_exist__" id="__id_does_not_exist__" >}}
 {{< x_simple user="__user_does_not_exist__" id="__id_does_not_exist__" >}}
-{{< twitter user="__user_does_not_exist__" id="__id_does_not_exist__" >}}
-{{< twitter_simple user="__user_does_not_exist__" id="__id_does_not_exist__" >}}
 -- layouts/home.html --
 {{ .Content }}
 `
@@ -625,9 +568,6 @@ title: home
        b.AssertLogContains(
                `WARN  The "x" shortcode was unable to retrieve the remote data.`,
                `WARN  The "x_simple" shortcode was unable to retrieve the remote data.`,
-               `WARN  The "twitter", "tweet", and "twitter_simple" shortcodes were deprecated in v0.142.0 and will be removed in a future release.`,
-               `WARN  The "twitter" shortcode was unable to retrieve the remote data.`,
-               `WARN  The "twitter_simple" shortcode was unable to retrieve the remote data.`,
        )
 }
 
@@ -923,3 +863,30 @@ MD-TR
                "MD-EN",
        )
 }
+
+// Issue 14488
+func TestTwitterShortcodeDeprecationError14488(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+disableKinds = ['home','rss','section','sitemap','taxonomy','term']
+-- content/p1.md --
+---
+title: p1
+---
+{{< SHORTCODE user="SanDiegoZoo" id="1453110110599868418" >}}
+-- layouts/page.html --
+{{ .Content }}
+`
+
+       want := `ERROR The "twitter", "tweet", and "twitter_simple" shortcodes were deprecated in v0.142.0 and removed in v0.156.0. Please use the "x" shortcode instead.`
+
+       shortcodes := []string{"twitter", "twitter_simple", "tweet"}
+       for _, sc := range shortcodes {
+               f := strings.ReplaceAll(files, "SHORTCODE", sc)
+               b, err := hugolib.TestE(t, f, hugolib.TestOptWarn())
+               b.Assert(err, qt.IsNotNil)
+               b.AssertLogContains(want)
+       }
+}