mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-29 22:29:56 +02:00
tpl/tplimpl: Deprecate twitter shortcode in favor of x shortcode
Closes #13214
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
60c24fc5ee
commit
1191467c05
@@ -734,3 +734,154 @@ https://gohugo.io"
|
||||
`<img src="/qr_472aab57ec7a6e3d.png" width="132" height="132">`,
|
||||
)
|
||||
}
|
||||
|
||||
// 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()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableKinds = ['home','rss','section','sitemap','taxonomy','term']
|
||||
#CONFIG
|
||||
-- content/p1.md --
|
||||
---
|
||||
title: p1
|
||||
---
|
||||
{{< x user="SanDiegoZoo" id="1453110110599868418" >}}
|
||||
-- content/p2.md --
|
||||
---
|
||||
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/_default/single.html --
|
||||
{{ .Content | strings.TrimSpace | safeHTML }}
|
||||
--
|
||||
`
|
||||
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
// Test x, twitter, and tweet shortcodes
|
||||
want := `<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Owl bet you'll lose this staring contest 🦉 <a href="https://t.co/eJh4f2zncC">pic.twitter.com/eJh4f2zncC</a></p>— 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"),
|
||||
}
|
||||
if !allElementsEqual(htmlFiles) {
|
||||
t.Error("A: expected all files to be equal")
|
||||
}
|
||||
|
||||
// Test x_simple and twitter_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'll lose this staring contest 🦉 <a href=\"https://t.co/eJh4f2zncC\">pic.twitter.com/eJh4f2zncC</a></p>— 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"),
|
||||
}
|
||||
if !allElementsEqual(htmlFiles) {
|
||||
t.Error("B: expected all files to be equal")
|
||||
}
|
||||
|
||||
filesOriginal := files
|
||||
|
||||
// Test privacy.twitter.simple
|
||||
files = strings.ReplaceAll(filesOriginal, "#CONFIG", "privacy.twitter.simple=true")
|
||||
b = hugolib.Test(t, files)
|
||||
htmlFiles = []string{
|
||||
b.FileContent("public/p2/index.html"),
|
||||
b.FileContent("public/p3/index.html"),
|
||||
b.FileContent("public/p5/index.html"),
|
||||
}
|
||||
if !allElementsEqual(htmlFiles) {
|
||||
t.Error("C: expected all files to be equal")
|
||||
}
|
||||
|
||||
// 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"),
|
||||
}
|
||||
if !allElementsEqual(htmlFiles) {
|
||||
t.Error("D: expected all files to be equal")
|
||||
}
|
||||
htmlFiles = []string{
|
||||
b.FileContent("public/p2/index.html"),
|
||||
b.FileContent("public/p3/index.html"),
|
||||
}
|
||||
if !allElementsEqual(htmlFiles) {
|
||||
t.Error("E: expected all files to be equal")
|
||||
}
|
||||
|
||||
// Test privacy.twitter.disable
|
||||
files = strings.ReplaceAll(filesOriginal, "#CONFIG", "privacy.twitter.disable = true")
|
||||
b = hugolib.Test(t, files)
|
||||
b.AssertFileContent("public/p1/index.html", "")
|
||||
htmlFiles = []string{
|
||||
b.FileContent("public/p1/index.html"),
|
||||
b.FileContent("public/p2/index.html"),
|
||||
b.FileContent("public/p3/index.html"),
|
||||
b.FileContent("public/p4/index.html"),
|
||||
b.FileContent("public/p4/index.html"),
|
||||
}
|
||||
if !allElementsEqual(htmlFiles) {
|
||||
t.Error("F: expected all files to be equal")
|
||||
}
|
||||
|
||||
// Test privacy.x.disable
|
||||
files = strings.ReplaceAll(filesOriginal, "#CONFIG", "privacy.x.disable = true")
|
||||
b = hugolib.Test(t, files)
|
||||
b.AssertFileContent("public/p1/index.html", "")
|
||||
htmlFiles = []string{
|
||||
b.FileContent("public/p1/index.html"),
|
||||
b.FileContent("public/p4/index.html"),
|
||||
}
|
||||
if !allElementsEqual(htmlFiles) {
|
||||
t.Error("G: expected all files to be equal")
|
||||
}
|
||||
htmlFiles = []string{
|
||||
b.FileContent("public/p2/index.html"),
|
||||
b.FileContent("public/p3/index.html"),
|
||||
}
|
||||
if !allElementsEqual(htmlFiles) {
|
||||
t.Error("F: expected all files to be equal")
|
||||
}
|
||||
}
|
||||
|
||||
// allElementsEqual reports whether all elements in the given string slice are
|
||||
// equal.
|
||||
func allElementsEqual(slice []string) bool {
|
||||
if len(slice) == 0 {
|
||||
return true
|
||||
}
|
||||
first := slice[0]
|
||||
for _, v := range slice[1:] {
|
||||
if v != first {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
Reference in New Issue
Block a user