From: Joe Mooring Date: Thu, 12 Feb 2026 10:59:09 +0000 (-0800) Subject: tpl/tplimpl: Throw error when calling twitter/twitter_simple shortcodes X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=55d136dd6664e5ca5249f73efbe885a52475f059;p=brevno-suite%2Fhugo tpl/tplimpl: Throw error when calling twitter/twitter_simple shortcodes Closes #14488 --- diff --git a/tpl/tplimpl/embedded/templates/_shortcodes/twitter.html b/tpl/tplimpl/embedded/templates/_shortcodes/twitter.html index c6200ffd2..1be6c2d6b 100644 --- a/tpl/tplimpl/embedded/templates/_shortcodes/twitter.html +++ b/tpl/tplimpl/embedded/templates/_shortcodes/twitter.html @@ -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." }} diff --git a/tpl/tplimpl/embedded/templates/_shortcodes/twitter_simple.html b/tpl/tplimpl/embedded/templates/_shortcodes/twitter_simple.html index 34150393d..1be6c2d6b 100644 --- a/tpl/tplimpl/embedded/templates/_shortcodes/twitter_simple.html +++ b/tpl/tplimpl/embedded/templates/_shortcodes/twitter_simple.html @@ -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 -}} - - {{- 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." }} diff --git a/tpl/tplimpl/shortcodes_integration_test.go b/tpl/tplimpl/shortcodes_integration_test.go index e6f566848..6a0c20c69 100644 --- a/tpl/tplimpl/shortcodes_integration_test.go +++ b/tpl/tplimpl/shortcodes_integration_test.go @@ -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 := `

Owl bet you'll lose this staring contest 🦉 pic.twitter.com/eJh4f2zncC

— San Diego Zoo Wildlife Alliance (@sandiegozoo) October 26, 2021
` 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 := "

Owl bet you'll lose this staring contest 🦉 pic.twitter.com/eJh4f2zncC

— San Diego Zoo Wildlife Alliance (@sandiegozoo) October 26, 2021
\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) + } +}