| 1 |
// Copyright 2025 The Hugo Authors. All rights reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 7 |
// |
| 8 |
// Unless required by applicable law or agreed to in writing, software |
| 9 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 |
// See the License for the specific language governing permissions and |
| 12 |
// limitations under the License. |
| 13 |
|
| 14 |
package tplimpl_test |
| 15 |
|
| 16 |
import ( |
| 17 |
"strings" |
| 18 |
"testing" |
| 19 |
|
| 20 |
qt "github.com/frankban/quicktest" |
| 21 |
"github.com/gohugoio/hugo/htesting" |
| 22 |
"github.com/gohugoio/hugo/hugolib" |
| 23 |
) |
| 24 |
|
| 25 |
func TestCommentShortcode(t *testing.T) { |
| 26 |
// This cannot be parallel as it depends on output from the global logger. |
| 27 |
|
| 28 |
files := ` |
| 29 |
-- hugo.toml -- |
| 30 |
disableKinds = ['page','rss','section','sitemap','taxonomy','term'] |
| 31 |
-- layouts/home.html -- |
| 32 |
{{ .Content }} |
| 33 |
-- content/_index.md -- |
| 34 |
--- |
| 35 |
title: home |
| 36 |
--- |
| 37 |
a{{< comment >}}b{{< /comment >}}c |
| 38 |
` |
| 39 |
|
| 40 |
b := hugolib.Test(t, files, hugolib.TestOptWarn()) |
| 41 |
b.AssertFileContent("public/index.html", "<p>ac</p>") |
| 42 |
b.AssertLogContains(`WARN The "comment" shortcode was deprecated in v0.143.0 and will be removed in a future release. Please use HTML comments instead.`) |
| 43 |
} |
| 44 |
|
| 45 |
func TestDetailsShortcode(t *testing.T) { |
| 46 |
t.Parallel() |
| 47 |
|
| 48 |
files := ` |
| 49 |
-- hugo.toml -- |
| 50 |
disableKinds = ['page','rss','section','sitemap','taxonomy','term'] |
| 51 |
-- layouts/home.html -- |
| 52 |
{{ .Content }} |
| 53 |
-- content/_index.md -- |
| 54 |
--- |
| 55 |
title: home |
| 56 |
--- |
| 57 |
{{< details >}} |
| 58 |
A: An _emphasized_ word. |
| 59 |
{{< /details >}} |
| 60 |
|
| 61 |
{{< details |
| 62 |
class="my-class" |
| 63 |
name="my-name" |
| 64 |
open=true |
| 65 |
summary="A **bold** word" |
| 66 |
title="my-title" |
| 67 |
>}} |
| 68 |
B: An _emphasized_ word. |
| 69 |
{{< /details >}} |
| 70 |
|
| 71 |
{{< details open=false >}} |
| 72 |
C: An _emphasized_ word. |
| 73 |
{{< /details >}} |
| 74 |
|
| 75 |
{{< details open="false" >}} |
| 76 |
D: An _emphasized_ word. |
| 77 |
{{< /details >}} |
| 78 |
|
| 79 |
{{< details open=0 >}} |
| 80 |
E: An _emphasized_ word. |
| 81 |
{{< /details >}} |
| 82 |
` |
| 83 |
b := hugolib.Test(t, files) |
| 84 |
|
| 85 |
b.AssertFileContent("public/index.html", |
| 86 |
"<details>\n <summary>Details</summary>\n <p>A: An <em>emphasized</em> word.</p>\n</details>", |
| 87 |
"<details class=\"my-class\" name=\"my-name\" open title=\"my-title\">\n <summary>A <strong>bold</strong> word</summary>\n <p>B: An <em>emphasized</em> word.</p>\n</details>", |
| 88 |
"<details>\n <summary>Details</summary>\n <p>C: An <em>emphasized</em> word.</p>\n</details>", |
| 89 |
"<details>\n <summary>Details</summary>\n <p>D: An <em>emphasized</em> word.</p>\n</details>", |
| 90 |
"<details>\n <summary>Details</summary>\n <p>D: An <em>emphasized</em> word.</p>\n</details>", |
| 91 |
) |
| 92 |
} |
| 93 |
|
| 94 |
func TestFigureShortcode(t *testing.T) { |
| 95 |
t.Parallel() |
| 96 |
|
| 97 |
files := ` |
| 98 |
-- hugo.toml -- |
| 99 |
disableKinds = ['page','rss','section','sitemap','taxonomy','term'] |
| 100 |
-- content/_index.md -- |
| 101 |
--- |
| 102 |
title: home |
| 103 |
--- |
| 104 |
{{< figure |
| 105 |
src="a.jpg" |
| 106 |
alt="alternate text" |
| 107 |
width=600 |
| 108 |
height=400 |
| 109 |
loading="lazy" |
| 110 |
class="my-class" |
| 111 |
link="https://example.org" |
| 112 |
target="_blank" |
| 113 |
rel="noopener" |
| 114 |
title="my-title" |
| 115 |
caption="a **bold** word" |
| 116 |
attr="an _emphasized_ word" |
| 117 |
attrlink="https://example.org/foo" |
| 118 |
>}} |
| 119 |
-- layouts/home.html -- |
| 120 |
Hash: {{ .Content | hash.XxHash }} |
| 121 |
Content: {{ .Content }} |
| 122 |
` |
| 123 |
|
| 124 |
b := hugolib.Test(t, files) |
| 125 |
b.AssertFileContent("public/index.html", "c18e12c59a2f9bdb") |
| 126 |
} |
| 127 |
|
| 128 |
func TestHighlightShortcode(t *testing.T) { |
| 129 |
t.Parallel() |
| 130 |
|
| 131 |
files := ` |
| 132 |
-- hugo.toml -- |
| 133 |
disableKinds = ['home','rss','section','sitemap','taxonomy','term'] |
| 134 |
-- layouts/single.html -- |
| 135 |
Hash: {{ .Content | hash.XxHash }} |
| 136 |
Content: {{ .Content }} |
| 137 |
-- content/p1.md -- |
| 138 |
--- |
| 139 |
title: p1 |
| 140 |
--- |
| 141 |
{{< highlight go >}} |
| 142 |
func main() { |
| 143 |
for i := 0; i < 3; i++ { |
| 144 |
fmt.Println("Value of i:", i) |
| 145 |
} |
| 146 |
} |
| 147 |
{{< /highlight >}} |
| 148 |
-- content/p2.md -- |
| 149 |
--- |
| 150 |
title: p2 |
| 151 |
--- |
| 152 |
{{< highlight go "noClasses=false" >}} |
| 153 |
func main() { |
| 154 |
for i := 0; i < 3; i++ { |
| 155 |
fmt.Println("Value of i:", i) |
| 156 |
} |
| 157 |
} |
| 158 |
{{< /highlight >}} |
| 159 |
-- content/p3.md -- |
| 160 |
--- |
| 161 |
title: p3 |
| 162 |
--- |
| 163 |
{{< highlight go "lineNos=inline" >}} |
| 164 |
func main() { |
| 165 |
for i := 0; i < 3; i++ { |
| 166 |
fmt.Println("Value of i:", i) |
| 167 |
} |
| 168 |
} |
| 169 |
{{< /highlight >}} |
| 170 |
-- content/p4.md -- |
| 171 |
--- |
| 172 |
title: p4 |
| 173 |
--- |
| 174 |
{{< highlight go "lineNos=table" >}} |
| 175 |
func main() { |
| 176 |
for i := 0; i < 3; i++ { |
| 177 |
fmt.Println("Value of i:", i) |
| 178 |
} |
| 179 |
} |
| 180 |
{{< /highlight >}} |
| 181 |
-- content/p5.md -- |
| 182 |
--- |
| 183 |
title: p5 |
| 184 |
--- |
| 185 |
{{< highlight go "anchorLineNos=true, hl_Lines=2-4, lineAnchors=foo, lineNoStart=42, lineNos=true, lineNumbersInTable=false, style=emacs, wrapperClass=my-class" >}} |
| 186 |
func main() { |
| 187 |
for i := 0; i < 3; i++ { |
| 188 |
fmt.Println("Value of i:", i) |
| 189 |
} |
| 190 |
} |
| 191 |
{{< /highlight >}} |
| 192 |
-- content/p6.md -- |
| 193 |
--- |
| 194 |
title: p6 |
| 195 |
--- |
| 196 |
{{< highlight go "anchorlinenos=true, hl_lines=2-4, lineanchors=foo, linenostart=42, linenos=true, linenumbersintable=false, style=emacs, wrapperclass=my-class" >}} |
| 197 |
func main() { |
| 198 |
for i := 0; i < 3; i++ { |
| 199 |
fmt.Println("Value of i:", i) |
| 200 |
} |
| 201 |
} |
| 202 |
{{< /highlight >}} |
| 203 |
-- content/p7.md -- |
| 204 |
--- |
| 205 |
title: p7 |
| 206 |
--- |
| 207 |
An inline {{< highlight go "hl_inline=true" >}}fmt.Println("Value of i:", i)Hello world!{{< /highlight >}} statement. |
| 208 |
` |
| 209 |
|
| 210 |
b := hugolib.Test(t, files) |
| 211 |
|
| 212 |
b.AssertFileContent("public/p1/index.html", "4f7e70e3bc7702fc") |
| 213 |
b.AssertFileContent("public/p2/index.html", "3f97c98e654f23a2") |
| 214 |
b.AssertFileContent("public/p3/index.html", "21d109753ff1b086") |
| 215 |
b.AssertFileContent("public/p4/index.html", "a6df524f21db7044") |
| 216 |
b.AssertFileContent("public/p5/index.html", "db2d5cc19d163217") |
| 217 |
b.AssertFileContent("public/p6/index.html", "db2d5cc19d163217") |
| 218 |
b.AssertFileContent("public/p7/index.html", "f12eeaa4d6d9c7ac") |
| 219 |
} |
| 220 |
|
| 221 |
func TestInstagramShortcode(t *testing.T) { |
| 222 |
t.Parallel() |
| 223 |
|
| 224 |
files := ` |
| 225 |
-- hugo.toml -- |
| 226 |
disableKinds = ['page','rss','section','sitemap','taxonomy','term'] |
| 227 |
privacy.instagram.simple = false |
| 228 |
-- content/_index.md -- |
| 229 |
--- |
| 230 |
title: home |
| 231 |
--- |
| 232 |
{{< instagram CxOWiQNP2MO >}} |
| 233 |
-- layouts/home.html -- |
| 234 |
Hash: {{ .Content | hash.XxHash }} |
| 235 |
Content: {{ .Content }} |
| 236 |
` |
| 237 |
|
| 238 |
// Regular mode |
| 239 |
b := hugolib.Test(t, files) |
| 240 |
b.AssertFileContent("public/index.html", "336bb64b13c24575") |
| 241 |
|
| 242 |
// Simple mode |
| 243 |
files = strings.ReplaceAll(files, "privacy.instagram.simple = false", "privacy.instagram.simple = true") |
| 244 |
b = hugolib.Test(t, files) |
| 245 |
b.AssertFileContent("public/index.html", "4c094707f37b2340") |
| 246 |
} |
| 247 |
|
| 248 |
func TestParamShortcode(t *testing.T) { |
| 249 |
t.Parallel() |
| 250 |
|
| 251 |
files := ` |
| 252 |
-- hugo.toml -- |
| 253 |
disableKinds = ['page','rss','section','sitemap','taxonomy','term'] |
| 254 |
[params] |
| 255 |
b = 2 |
| 256 |
-- layouts/home.html -- |
| 257 |
{{ .Content }} |
| 258 |
-- content/_index.md -- |
| 259 |
--- |
| 260 |
title: home |
| 261 |
params: |
| 262 |
a: 1 |
| 263 |
--- |
| 264 |
A: {{% param "a" %}} |
| 265 |
B: {{% param "b" %}} |
| 266 |
` |
| 267 |
|
| 268 |
b := hugolib.Test(t, files) |
| 269 |
|
| 270 |
b.AssertFileExists("public/index.html", true) |
| 271 |
b.AssertFileContent("public/index.html", |
| 272 |
"A: 1", |
| 273 |
"B: 2", |
| 274 |
) |
| 275 |
} |
| 276 |
|
| 277 |
func TestQRShortcode(t *testing.T) { |
| 278 |
t.Parallel() |
| 279 |
|
| 280 |
files := ` |
| 281 |
-- hugo.toml -- |
| 282 |
disableKinds = ['page','rss','section','sitemap','taxonomy','term'] |
| 283 |
-- layouts/home.html -- |
| 284 |
{{ .Content }} |
| 285 |
-- content/_index.md -- |
| 286 |
--- |
| 287 |
title: home |
| 288 |
--- |
| 289 |
{{< qr |
| 290 |
text="https://gohugo.io" |
| 291 |
level="high" |
| 292 |
scale=4 |
| 293 |
targetDir="codes" |
| 294 |
alt="QR code linking to https://gohugo.io" |
| 295 |
class="my-class" |
| 296 |
id="my-id" |
| 297 |
title="My Title" |
| 298 |
/>}} |
| 299 |
|
| 300 |
{{< qr >}} |
| 301 |
https://gohugo.io" |
| 302 |
{{< /qr >}} |
| 303 |
` |
| 304 |
|
| 305 |
b := hugolib.Test(t, files) |
| 306 |
|
| 307 |
b.AssertFileContent("public/index.html", |
| 308 |
`<img src="/codes/qr_be5d263c2671bcbd.png" width="148" height="148" alt="QR code linking to https://gohugo.io" class="my-class" id="my-id" title="My Title">`, |
| 309 |
`<img src="/qr_472aab57ec7a6e3d.png" width="132" height="132">`, |
| 310 |
) |
| 311 |
} |
| 312 |
|
| 313 |
func TestRefShortcode(t *testing.T) { |
| 314 |
t.Parallel() |
| 315 |
|
| 316 |
files := ` |
| 317 |
-- hugo.toml -- |
| 318 |
baseURL = 'https://example.org/' |
| 319 |
disableKinds = ['rss','section','sitemap','taxonomy','term'] |
| 320 |
defaultContentLanguageInSubdir = true |
| 321 |
[markup.goldmark.extensions] |
| 322 |
linkify = false |
| 323 |
[languages.en] |
| 324 |
weight = 1 |
| 325 |
[languages.de] |
| 326 |
weight = 2 |
| 327 |
[outputs] |
| 328 |
page = ['html','json'] |
| 329 |
-- layouts/home.html -- |
| 330 |
{{ .Content }} |
| 331 |
-- layouts/single.html.html -- |
| 332 |
{{ .Title }} |
| 333 |
-- layouts/single.json.json -- |
| 334 |
{{ .Title }} |
| 335 |
-- content/_index.en.md -- |
| 336 |
--- |
| 337 |
title: home |
| 338 |
--- |
| 339 |
A: {{% ref "/s1/p1.md" %}} |
| 340 |
|
| 341 |
B: {{% ref path="/s1/p1.md" %}} |
| 342 |
|
| 343 |
C: {{% ref path="/s1/p1.md" lang="en" %}} |
| 344 |
|
| 345 |
D: {{% ref path="/s1/p1.md" lang="de" %}} |
| 346 |
|
| 347 |
E: {{% ref path="/s1/p1.md" lang="en" outputFormat="html" %}} |
| 348 |
|
| 349 |
F: {{% ref path="/s1/p1.md" lang="de" outputFormat="html" %}} |
| 350 |
|
| 351 |
G: {{% ref path="/s1/p1.md" lang="en" outputFormat="json" %}} |
| 352 |
|
| 353 |
H: {{% ref path="/s1/p1.md" lang="de" outputFormat="json" %}} |
| 354 |
-- content/s1/p1.en.md -- |
| 355 |
--- |
| 356 |
title: p1 (en) |
| 357 |
--- |
| 358 |
-- content/s1/p1.de.md -- |
| 359 |
--- |
| 360 |
title: p1 (de) |
| 361 |
--- |
| 362 |
` |
| 363 |
|
| 364 |
b := hugolib.Test(t, files) |
| 365 |
|
| 366 |
b.AssertFileContent("public/en/index.html", |
| 367 |
`p>A: https://example.org/en/s1/p1/</p>`, |
| 368 |
`p>B: https://example.org/en/s1/p1/</p>`, |
| 369 |
`p>C: https://example.org/en/s1/p1/</p>`, |
| 370 |
`p>D: https://example.org/de/s1/p1/</p>`, |
| 371 |
`p>E: https://example.org/en/s1/p1/</p>`, |
| 372 |
`p>F: https://example.org/de/s1/p1/</p>`, |
| 373 |
`p>G: https://example.org/en/s1/p1/index.json</p>`, |
| 374 |
`p>H: https://example.org/de/s1/p1/index.json</p>`, |
| 375 |
) |
| 376 |
} |
| 377 |
|
| 378 |
func TestRelRefShortcode(t *testing.T) { |
| 379 |
t.Parallel() |
| 380 |
|
| 381 |
files := ` |
| 382 |
-- hugo.toml -- |
| 383 |
baseURL = 'https://example.org/' |
| 384 |
disableKinds = ['rss','section','sitemap','taxonomy','term'] |
| 385 |
defaultContentLanguageInSubdir = true |
| 386 |
[markup.goldmark.extensions] |
| 387 |
linkify = false |
| 388 |
[languages.en] |
| 389 |
weight = 1 |
| 390 |
[languages.de] |
| 391 |
weight = 2 |
| 392 |
[outputs] |
| 393 |
page = ['html','json'] |
| 394 |
-- layouts/home.html -- |
| 395 |
{{ .Content }} |
| 396 |
-- layouts/single.html.html -- |
| 397 |
{{ .Title }} |
| 398 |
-- layouts/single.json.json -- |
| 399 |
{{ .Title }} |
| 400 |
-- content/_index.en.md -- |
| 401 |
--- |
| 402 |
title: home |
| 403 |
--- |
| 404 |
A: {{% relref "/s1/p1.md" %}} |
| 405 |
|
| 406 |
B: {{% relref path="/s1/p1.md" %}} |
| 407 |
|
| 408 |
C: {{% relref path="/s1/p1.md" lang="en" %}} |
| 409 |
|
| 410 |
D: {{% relref path="/s1/p1.md" lang="de" %}} |
| 411 |
|
| 412 |
E: {{% relref path="/s1/p1.md" lang="en" outputFormat="html" %}} |
| 413 |
|
| 414 |
F: {{% relref path="/s1/p1.md" lang="de" outputFormat="html" %}} |
| 415 |
|
| 416 |
G: {{% relref path="/s1/p1.md" lang="en" outputFormat="json" %}} |
| 417 |
|
| 418 |
H: {{% relref path="/s1/p1.md" lang="de" outputFormat="json" %}} |
| 419 |
-- content/s1/p1.en.md -- |
| 420 |
--- |
| 421 |
title: p1 (en) |
| 422 |
--- |
| 423 |
-- content/s1/p1.de.md -- |
| 424 |
--- |
| 425 |
title: p1 (de) |
| 426 |
--- |
| 427 |
` |
| 428 |
|
| 429 |
b := hugolib.Test(t, files) |
| 430 |
|
| 431 |
b.AssertFileContent("public/en/index.html", |
| 432 |
`p>A: /en/s1/p1/</p>`, |
| 433 |
`p>B: /en/s1/p1/</p>`, |
| 434 |
`p>C: /en/s1/p1/</p>`, |
| 435 |
`p>D: /de/s1/p1/</p>`, |
| 436 |
`p>E: /en/s1/p1/</p>`, |
| 437 |
`p>F: /de/s1/p1/</p>`, |
| 438 |
`p>G: /en/s1/p1/index.json</p>`, |
| 439 |
`p>H: /de/s1/p1/index.json</p>`, |
| 440 |
) |
| 441 |
} |
| 442 |
|
| 443 |
func TestVimeoShortcode(t *testing.T) { |
| •444 |
t.Skip("This tests needs internet access") |
| 445 |
t.Parallel() |
| 446 |
|
| 447 |
files := ` |
| 448 |
-- hugo.toml -- |
| 449 |
disableKinds = ['home','rss','section','sitemap','taxonomy','term'] |
| 450 |
privacy.vimeo.simple = false |
| 451 |
-- content/p1.md -- |
| 452 |
--- |
| 453 |
title: p1 |
| 454 |
--- |
| 455 |
{{< vimeo 19899678 >}} |
| 456 |
-- content/p2.md -- |
| 457 |
--- |
| 458 |
title: p2 |
| 459 |
--- |
| 460 |
{{< vimeo id=19899678 allowFullScreen=true >}} |
| 461 |
-- content/p3.md -- |
| 462 |
--- |
| 463 |
title: p3 |
| 464 |
--- |
| 465 |
{{< vimeo id=19899678 allowFullScreen=false >}} |
| 466 |
-- layouts/single.html -- |
| 467 |
Hash: {{ .Content | hash.XxHash }} |
| 468 |
Content: {{ .Content }} |
| 469 |
` |
| 470 |
|
| 471 |
// Regular mode |
| 472 |
b := hugolib.Test(t, files) |
| 473 |
b.AssertFileContent("public/p1/index.html", "2144844b57ee39d8") |
| 474 |
b.AssertFileContent("public/p2/index.html", "2144844b57ee39d8") |
| 475 |
b.AssertFileContent("public/p3/index.html", "a131e93ce53bc318") |
| 476 |
|
| 477 |
// Simple mode |
| 478 |
files = strings.ReplaceAll(files, "privacy.vimeo.simple = false", "privacy.vimeo.simple = true") |
| 479 |
b = hugolib.Test(t, files) |
| 480 |
b.AssertFileContent("public/p1/index.html", "582bde2225dc43c0") |
| 481 |
|
| 482 |
// Simple mode with non-existent id |
| 483 |
files = strings.ReplaceAll(files, "{{< vimeo 19899678 >}}", "{{< vimeo __id_does_not_exist__ >}}") |
| 484 |
b = hugolib.Test(t, files, hugolib.TestOptWarn()) |
| 485 |
b.AssertLogContains(`WARN The "vimeo" shortcode was unable to retrieve the remote data.`) |
| 486 |
} |
| 487 |
|
| 488 |
func TestXShortcodes(t *testing.T) { |
| •489 |
t.Skip("This tests needs internet access") |
| 490 |
t.Parallel() |
| 491 |
htesting.SkipSlowTestUnlessCI(t) |
| 492 |
|
| 493 |
files := ` |
| 494 |
-- hugo.toml -- |
| 495 |
disableKinds = ['home','rss','section','sitemap','taxonomy','term'] |
| 496 |
#CONFIG |
| 497 |
-- content/p1.md -- |
| 498 |
--- |
| 499 |
title: p1 |
| 500 |
--- |
| 501 |
{{< x user="SanDiegoZoo" id="1453110110599868418" >}} |
| 502 |
-- content/p2.md -- |
| 503 |
--- |
| 504 |
title: p2 |
| 505 |
--- |
| 506 |
{{< x_simple user="SanDiegoZoo" id="1453110110599868418" >}} |
| 507 |
-- layouts/single.html -- |
| 508 |
{{ .Content | strings.TrimSpace | safeHTML }} |
| 509 |
-- |
| 510 |
` |
| 511 |
|
| 512 |
b := hugolib.Test(t, files) |
| 513 |
|
| 514 |
// Test x shortcode |
| 515 |
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://x.com/sandiegozoo/status/1453110110599868418?ref_src=twsrc%5Etfw">October 26, 2021</a></blockquote> |
| 516 |
<script async src="https://platform.x.com/widgets.js" charset="utf-8"></script>` |
| 517 |
b.AssertFileContent("public/p1/index.html", want) |
| 518 |
|
| 519 |
// Test x_simple shortcodes |
| 520 |
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://x.com/sandiegozoo/status/1453110110599868418?ref_src=twsrc%5Etfw\">October 26, 2021</a></blockquote>\n--" |
| 521 |
b.AssertFileContent("public/p2/index.html", wantSimple) |
| 522 |
|
| 523 |
// Test privacy.x.simple |
| 524 |
f := strings.ReplaceAll(files, "#CONFIG", "privacy.x.simple=true") |
| 525 |
b = hugolib.Test(t, f) |
| 526 |
b.AssertFileContent("public/p1/index.html", wantSimple) |
| 527 |
b.AssertFileContent("public/p2/index.html", wantSimple) |
| 528 |
|
| 529 |
// Test privacy.x.disable |
| 530 |
f = strings.ReplaceAll(files, "#CONFIG", "privacy.x.disable = true") |
| 531 |
b = hugolib.Test(t, f) |
| 532 |
b.AssertFileContent("public/p1/index.html", "") |
| 533 |
b.AssertFileContent("public/p2/index.html", "") |
| 534 |
|
| 535 |
// Test warnings |
| 536 |
files = ` |
| 537 |
-- hugo.toml -- |
| 538 |
disableKinds = ['page','rss','section','sitemap','taxonomy','term'] |
| 539 |
-- content/_index.md -- |
| 540 |
--- |
| 541 |
title: home |
| 542 |
--- |
| 543 |
{{< x user="__user_does_not_exist__" id="__id_does_not_exist__" >}} |
| 544 |
{{< x_simple user="__user_does_not_exist__" id="__id_does_not_exist__" >}} |
| 545 |
-- layouts/home.html -- |
| 546 |
{{ .Content }} |
| 547 |
` |
| 548 |
|
| 549 |
b = hugolib.Test(t, files, hugolib.TestOptWarn()) |
| 550 |
b.AssertLogContains( |
| 551 |
`WARN The "x" shortcode was unable to retrieve the remote data.`, |
| 552 |
`WARN The "x_simple" shortcode was unable to retrieve the remote data.`, |
| 553 |
) |
| 554 |
} |
| 555 |
|
| 556 |
func TestYouTubeShortcode(t *testing.T) { |
| 557 |
t.Parallel() |
| 558 |
|
| 559 |
files := ` |
| 560 |
-- hugo.toml -- |
| 561 |
disableKinds = ['home','rss','section','sitemap','taxonomy','term'] |
| 562 |
privacy.youtube.privacyEnhanced = false |
| 563 |
-- layouts/single.html -- |
| 564 |
Hash: {{ .Content | hash.XxHash }} |
| 565 |
Content: {{ .Content }} |
| 566 |
-- content/p1.md -- |
| 567 |
--- |
| 568 |
title: p1 |
| 569 |
--- |
| 570 |
{{< youtube 0RKpf3rK57I >}} |
| 571 |
-- content/p2.md -- |
| 572 |
--- |
| 573 |
title: p2 |
| 574 |
--- |
| 575 |
{{< youtube |
| 576 |
id="0RKpf3rK57I" |
| 577 |
allowFullScreen=false |
| 578 |
autoplay=true |
| 579 |
class="my-class" |
| 580 |
controls="false" |
| 581 |
end=42 |
| 582 |
loading="lazy" |
| 583 |
loop=true |
| 584 |
mute=true |
| 585 |
start=6 |
| 586 |
title="my title" |
| 587 |
>}} |
| 588 |
` |
| 589 |
|
| 590 |
b := hugolib.Test(t, files) |
| 591 |
|
| 592 |
b.AssertFileContent("public/p1/index.html", "365fe481b0377cd9") |
| 593 |
b.AssertFileContent("public/p2/index.html", "82d7f05fb1fefb3b") |
| 594 |
|
| 595 |
files = strings.ReplaceAll(files, "privacy.youtube.privacyEnhanced = false", "privacy.youtube.privacyEnhanced = true") |
| 596 |
|
| 597 |
b = hugolib.Test(t, files) |
| 598 |
b.AssertFileContent("public/p1/index.html", "48398992f5ff0afc") |
| 599 |
b.AssertFileContent("public/p2/index.html", "116436ffc3f62191") |
| 600 |
} |
| 601 |
|
| 602 |
func TestShortcodePlainTextVsHTMLTemplateIssue13698(t *testing.T) { |
| 603 |
t.Parallel() |
| 604 |
|
| 605 |
filesTemplate := ` |
| 606 |
-- hugo.toml -- |
| 607 |
markup.goldmark.renderer.unsafe = true |
| 608 |
-- layouts/all.html -- |
| 609 |
Content: {{ .Content }}| |
| 610 |
-- layouts/_shortcodes/mymarkdown.md -- |
| 611 |
<div>Foo bar</div> |
| 612 |
-- content/p1.md -- |
| 613 |
--- |
| 614 |
title: p1 |
| 615 |
--- |
| 616 |
## A shortcode |
| 617 |
|
| 618 |
SHORTCODE |
| 619 |
|
| 620 |
` |
| 621 |
|
| 622 |
files := strings.ReplaceAll(filesTemplate, "SHORTCODE", "{{% mymarkdown %}}") |
| 623 |
b := hugolib.Test(t, files) |
| 624 |
b.AssertFileContent("public/p1/index.html", "<div>Foo bar</div>") |
| 625 |
|
| 626 |
files = strings.ReplaceAll(filesTemplate, "SHORTCODE", "{{< mymarkdown >}}") |
| 627 |
|
| 628 |
var err error |
| 629 |
b, err = hugolib.TestE(t, files) |
| 630 |
b.Assert(err, qt.IsNotNil) |
| 631 |
b.Assert(err.Error(), qt.Contains, `no compatible template found for shortcode "mymarkdown" in [/_shortcodes/mymarkdown.md]; note that to use plain text template shortcodes in HTML you need to use the shortcode {{% delimiter`) |
| 632 |
} |
| 633 |
|
| 634 |
func TestShortcodeOnlyLanguageInBaseIssue13699And13740(t *testing.T) { |
| 635 |
t.Parallel() |
| 636 |
|
| 637 |
files := ` |
| 638 |
-- hugo.toml -- |
| 639 |
baseURL = 'https://example.org/' |
| 640 |
disableLanguages = ['de'] |
| 641 |
[languages] |
| 642 |
[languages.en] |
| 643 |
weight = 1 |
| 644 |
[languages.de] |
| 645 |
weight = 2 |
| 646 |
-- layouts/_shortcodes/de.html -- |
| 647 |
de.html |
| 648 |
-- layouts/all.html -- |
| 649 |
{{ .Content }} |
| 650 |
-- content/_index.md -- |
| 651 |
--- |
| 652 |
title: home |
| 653 |
--- |
| 654 |
{{< de >}} |
| 655 |
|
| 656 |
` |
| 657 |
b := hugolib.Test(t, files) |
| 658 |
|
| 659 |
b.AssertFileContent("public/index.html", "de.html") |
| 660 |
} |
| 661 |
|
| 662 |
func TestShortcodeLanguage13767(t *testing.T) { |
| 663 |
t.Parallel() |
| 664 |
|
| 665 |
files := ` |
| 666 |
-- hugo.toml -- |
| 667 |
defaultContentLanguage = 'pl' |
| 668 |
defaultContentLanguageInSubdir = true |
| 669 |
[languages.pl] |
| 670 |
weight = 1 |
| 671 |
[languages.en] |
| 672 |
weight = 2 |
| 673 |
-- content/_index.md -- |
| 674 |
--- |
| 675 |
title: dom |
| 676 |
--- |
| 677 |
{{< myshortcode >}} |
| 678 |
-- content/_index.en.md -- |
| 679 |
--- |
| 680 |
title: home |
| 681 |
--- |
| 682 |
{{< myshortcode >}} |
| 683 |
-- layouts/_shortcodes/myshortcode.html -- |
| 684 |
myshortcode.html |
| 685 |
-- layouts/_shortcodes/myshortcode.en.html -- |
| 686 |
myshortcode.en.html |
| 687 |
-- layouts/all.html -- |
| 688 |
{{ .Content }} |
| 689 |
|
| 690 |
|
| 691 |
` |
| 692 |
|
| 693 |
b := hugolib.Test(t, files) |
| 694 |
|
| 695 |
b.AssertFileContent("public/pl/index.html", "myshortcode.html") |
| 696 |
b.AssertFileContent("public/en/index.html", "myshortcode.en.html") |
| 697 |
} |
| 698 |
|
| 699 |
func TestHasShortcodeSamePageSourceDifferentShortcodes(t *testing.T) { |
| 700 |
t.Parallel() |
| 701 |
|
| 702 |
files := ` |
| 703 |
-- hugo.toml -- |
| 704 |
disableKinds = ['home','rss','section','sitemap','taxonomy','term', '404'] |
| 705 |
defaultContentLanguage = 'en' |
| 706 |
defaultContentLanguageInSubdir = true |
| 707 |
markup.goldmark.renderer.unsafe = true |
| 708 |
|
| 709 |
[languages] |
| 710 |
[languages.en] |
| 711 |
weight = 1 |
| 712 |
[languages.sv] |
| 713 |
weight = 2 |
| 714 |
-- content/inc/i1.md -- |
| 715 |
--- |
| 716 |
headless: true |
| 717 |
sites: |
| 718 |
matrix: |
| 719 |
languages: |
| 720 |
- '**' |
| 721 |
--- |
| 722 |
{{% sc1 %}} |
| 723 |
-- content/inc/i2.md -- |
| 724 |
--- |
| 725 |
headless: true |
| 726 |
sites: |
| 727 |
matrix: |
| 728 |
languages: |
| 729 |
- '**' |
| 730 |
--- |
| 731 |
{{% sc2 %}} |
| 732 |
-- content/p1.md -- |
| 733 |
--- |
| 734 |
title: p1 |
| 735 |
--- |
| 736 |
P1. |
| 737 |
{{% inc %}} |
| 738 |
-- content/p1.sv.md -- |
| 739 |
--- |
| 740 |
title: p1 sv |
| 741 |
--- |
| 742 |
P1. |
| 743 |
{{% inc %}} |
| 744 |
-- layouts/_shortcodes/sc1.html -- |
| 745 |
sc1 |
| 746 |
-- layouts/_shortcodes/sc2.html -- |
| 747 |
sc2 |
| 748 |
-- layouts/_shortcodes/inc.html -- |
| 749 |
{{ with site.GetPage "inc/i1.md" }}i1.RenderShortcodes: {{ .RenderShortcodes }}{{ end }} |
| 750 |
-- layouts/_shortcodes/inc.sv.html -- |
| 751 |
{{ with site.GetPage "inc/i2.md" }}i1.RenderShortcodes: {{ .RenderShortcodes }}{{ end }} |
| 752 |
-- layouts/all.html -- |
| 753 |
Content: {{ .Content }}|sc1: {{ .HasShortcode "sc1" }}|sc2: {{ .HasShortcode "sc2" }}|inc: {{ .HasShortcode "inc" }}| |
| 754 |
|
| 755 |
` |
| 756 |
|
| 757 |
b := hugolib.Test(t, files) |
| 758 |
|
| 759 |
b.AssertFileContent("public/en/p1/index.html", " |sc1: true|sc2: false|inc: true|") |
| 760 |
b.AssertFileContent("public/sv/p1/index.html", " |sc1: false|sc2: true|inc: true|") |
| 761 |
} |
| 762 |
|
| 763 |
func TestShortcodeMultilingualHTML(t *testing.T) { |
| 764 |
t.Parallel() |
| 765 |
|
| 766 |
files := ` |
| 767 |
-- hugo.toml -- |
| 768 |
baseURL = 'https://example.org/' |
| 769 |
defaultContentLanguage = 'tr' |
| 770 |
defaultContentLanguageInSubdir = true |
| 771 |
[languages.tr] |
| 772 |
weight = 1 |
| 773 |
[languages.en] |
| 774 |
weight = 2 |
| 775 |
-- content/posts/test-post.tr.md -- |
| 776 |
+++ |
| 777 |
title = 'Test Post TR' |
| 778 |
+++ |
| 779 |
|
| 780 |
{{< myhtml >}} |
| 781 |
-- content/posts/test-post.en.md -- |
| 782 |
+++ |
| 783 |
title = 'Test Post EN' |
| 784 |
+++ |
| 785 |
|
| 786 |
{{< myhtml >}} |
| 787 |
-- layouts/_shortcodes/myhtml.en.html -- |
| 788 |
HTML-EN |
| 789 |
-- layouts/_shortcodes/myhtml.tr.html -- |
| 790 |
HTML-TR |
| 791 |
-- layouts/_default/single.html -- |
| 792 |
{{ .Content }} |
| 793 |
` |
| 794 |
|
| 795 |
b := hugolib.Test(t, files) |
| 796 |
|
| 797 |
b.AssertFileContent("public/tr/posts/test-post/index.html", |
| 798 |
"HTML-TR", |
| 799 |
) |
| 800 |
|
| 801 |
b.AssertFileContent("public/en/posts/test-post/index.html", |
| 802 |
"HTML-EN", |
| 803 |
) |
| 804 |
} |
| 805 |
|
| 806 |
func TestShortcodeMultilingualMarkdown(t *testing.T) { |
| 807 |
t.Parallel() |
| 808 |
|
| 809 |
files := ` |
| 810 |
-- hugo.toml -- |
| 811 |
baseURL = 'https://example.org/' |
| 812 |
defaultContentLanguage = 'tr' |
| 813 |
defaultContentLanguageInSubdir = true |
| 814 |
[languages.tr] |
| 815 |
weight = 1 |
| 816 |
[languages.en] |
| 817 |
weight = 2 |
| 818 |
-- content/posts/test-post.tr.md -- |
| 819 |
+++ |
| 820 |
title = 'Test Post TR' |
| 821 |
+++ |
| 822 |
|
| 823 |
{{% mymd %}} |
| 824 |
-- content/posts/test-post.en.md -- |
| 825 |
+++ |
| 826 |
title = 'Test Post EN' |
| 827 |
+++ |
| 828 |
|
| 829 |
{{% mymd %}} |
| 830 |
-- layouts/_shortcodes/mymd.en.md -- |
| 831 |
MD-EN |
| 832 |
-- layouts/_shortcodes/mymd.tr.md -- |
| 833 |
MD-TR |
| 834 |
-- layouts/_default/single.html -- |
| 835 |
{{ .Content }} |
| 836 |
` |
| 837 |
|
| 838 |
b := hugolib.Test(t, files) |
| 839 |
|
| 840 |
b.AssertFileContent("public/tr/posts/test-post/index.html", |
| 841 |
"MD-TR", |
| 842 |
) |
| 843 |
|
| 844 |
b.AssertFileContent("public/en/posts/test-post/index.html", |
| 845 |
"MD-EN", |
| 846 |
) |
| 847 |
} |
| 848 |
|
| 849 |
// Issue 14488 |
| 850 |
func TestTwitterShortcodeDeprecationError14488(t *testing.T) { |
| 851 |
t.Parallel() |
| 852 |
|
| 853 |
files := ` |
| 854 |
-- hugo.toml -- |
| 855 |
disableKinds = ['home','rss','section','sitemap','taxonomy','term'] |
| 856 |
-- content/p1.md -- |
| 857 |
--- |
| 858 |
title: p1 |
| 859 |
--- |
| 860 |
{{< SHORTCODE user="SanDiegoZoo" id="1453110110599868418" >}} |
| 861 |
-- layouts/page.html -- |
| 862 |
{{ .Content }} |
| 863 |
` |
| 864 |
|
| 865 |
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.` |
| 866 |
|
| 867 |
shortcodes := []string{"twitter", "twitter_simple", "tweet"} |
| 868 |
for _, sc := range shortcodes { |
| 869 |
f := strings.ReplaceAll(files, "SHORTCODE", sc) |
| 870 |
b, err := hugolib.TestE(t, f, hugolib.TestOptWarn()) |
| 871 |
b.Assert(err, qt.IsNotNil) |
| 872 |
b.AssertLogContains(want) |
| 873 |
} |
| 874 |
} |
| 875 |
|
| 876 |
// Issue 14491 |
| 877 |
func TestGistShortcodeDeprecationError14491(t *testing.T) { |
| 878 |
t.Parallel() |
| 879 |
|
| 880 |
files := ` |
| 881 |
-- hugo.toml -- |
| 882 |
disableKinds = ['page','rss','section','sitemap','taxonomy','term'] |
| 883 |
-- layouts/home.html -- |
| 884 |
{{ .Content }} |
| 885 |
-- content/_index.md -- |
| 886 |
--- |
| 887 |
title: home |
| 888 |
--- |
| 889 |
{{< gist user 23932424365401ffa5e9d9810102a477 >}} |
| 890 |
` |
| 891 |
|
| 892 |
b, err := hugolib.TestE(t, files, hugolib.TestOptWarn()) |
| 893 |
b.Assert(err, qt.IsNotNil) |
| 894 |
b.AssertLogContains(`ERROR The "gist" shortcode was deprecated in v0.143.0 and removed in v0.156.0.`) |
| 895 |
} |