Debian Codegraph @

tpl/tplimpl/shortcodes_integration_test.go

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
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.Parallel()
445
446 files := `
447 -- hugo.toml --
448 disableKinds = ['home','rss','section','sitemap','taxonomy','term']
449 privacy.vimeo.simple = false
450 -- content/p1.md --
451 ---
452 title: p1
453 ---
454 {{< vimeo 19899678 >}}
455 -- content/p2.md --
456 ---
457 title: p2
458 ---
459 {{< vimeo id=19899678 allowFullScreen=true >}}
460 -- content/p3.md --
461 ---
462 title: p3
463 ---
464 {{< vimeo id=19899678 allowFullScreen=false >}}
465 -- layouts/single.html --
466 Hash: {{ .Content | hash.XxHash }}
467 Content: {{ .Content }}
468 `
469
470 // Regular mode
471 b := hugolib.Test(t, files)
472 b.AssertFileContent("public/p1/index.html", "2144844b57ee39d8")
473 b.AssertFileContent("public/p2/index.html", "2144844b57ee39d8")
474 b.AssertFileContent("public/p3/index.html", "a131e93ce53bc318")
475
476 // Simple mode
477 files = strings.ReplaceAll(files, "privacy.vimeo.simple = false", "privacy.vimeo.simple = true")
478 b = hugolib.Test(t, files)
479 b.AssertFileContent("public/p1/index.html", "582bde2225dc43c0")
480
481 // Simple mode with non-existent id
482 files = strings.ReplaceAll(files, "{{< vimeo 19899678 >}}", "{{< vimeo __id_does_not_exist__ >}}")
483 b = hugolib.Test(t, files, hugolib.TestOptWarn())
484 b.AssertLogContains(`WARN The "vimeo" shortcode was unable to retrieve the remote data.`)
485 }
486
487 func TestXShortcodes(t *testing.T) {
488 t.Parallel()
489 htesting.SkipSlowTestUnlessCI(t)
490
491 files := `
492 -- hugo.toml --
493 disableKinds = ['home','rss','section','sitemap','taxonomy','term']
494 #CONFIG
495 -- content/p1.md --
496 ---
497 title: p1
498 ---
499 {{< x user="SanDiegoZoo" id="1453110110599868418" >}}
500 -- content/p2.md --
501 ---
502 title: p2
503 ---
504 {{< x_simple user="SanDiegoZoo" id="1453110110599868418" >}}
505 -- layouts/single.html --
506 {{ .Content | strings.TrimSpace | safeHTML }}
507 --
508 `
509
510 b := hugolib.Test(t, files)
511
512 // Test x shortcode
513 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://x.com/sandiegozoo/status/1453110110599868418?ref_src=twsrc%5Etfw">October 26, 2021</a></blockquote>
514 <script async src="https://platform.x.com/widgets.js" charset="utf-8"></script>`
515 b.AssertFileContent("public/p1/index.html", want)
516
517 // Test x_simple shortcodes
518 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://x.com/sandiegozoo/status/1453110110599868418?ref_src=twsrc%5Etfw\">October 26, 2021</a></blockquote>\n--"
519 b.AssertFileContent("public/p2/index.html", wantSimple)
520
521 // Test privacy.x.simple
522 f := strings.ReplaceAll(files, "#CONFIG", "privacy.x.simple=true")
523 b = hugolib.Test(t, f)
524 b.AssertFileContent("public/p1/index.html", wantSimple)
525 b.AssertFileContent("public/p2/index.html", wantSimple)
526
527 // Test privacy.x.disable
528 f = strings.ReplaceAll(files, "#CONFIG", "privacy.x.disable = true")
529 b = hugolib.Test(t, f)
530 b.AssertFileContent("public/p1/index.html", "")
531 b.AssertFileContent("public/p2/index.html", "")
532
533 // Test warnings
534 files = `
535 -- hugo.toml --
536 disableKinds = ['page','rss','section','sitemap','taxonomy','term']
537 -- content/_index.md --
538 ---
539 title: home
540 ---
541 {{< x user="__user_does_not_exist__" id="__id_does_not_exist__" >}}
542 {{< x_simple user="__user_does_not_exist__" id="__id_does_not_exist__" >}}
543 -- layouts/home.html --
544 {{ .Content }}
545 `
546
547 b = hugolib.Test(t, files, hugolib.TestOptWarn())
548 b.AssertLogContains(
549 `WARN The "x" shortcode was unable to retrieve the remote data.`,
550 `WARN The "x_simple" shortcode was unable to retrieve the remote data.`,
551 )
552 }
553
554 func TestYouTubeShortcode(t *testing.T) {
555 t.Parallel()
556
557 files := `
558 -- hugo.toml --
559 disableKinds = ['home','rss','section','sitemap','taxonomy','term']
560 privacy.youtube.privacyEnhanced = false
561 -- layouts/single.html --
562 Hash: {{ .Content | hash.XxHash }}
563 Content: {{ .Content }}
564 -- content/p1.md --
565 ---
566 title: p1
567 ---
568 {{< youtube 0RKpf3rK57I >}}
569 -- content/p2.md --
570 ---
571 title: p2
572 ---
573 {{< youtube
574 id="0RKpf3rK57I"
575 allowFullScreen=false
576 autoplay=true
577 class="my-class"
578 controls="false"
579 end=42
580 loading="lazy"
581 loop=true
582 mute=true
583 start=6
584 title="my title"
585 >}}
586 `
587
588 b := hugolib.Test(t, files)
589
590 b.AssertFileContent("public/p1/index.html", "365fe481b0377cd9")
591 b.AssertFileContent("public/p2/index.html", "82d7f05fb1fefb3b")
592
593 files = strings.ReplaceAll(files, "privacy.youtube.privacyEnhanced = false", "privacy.youtube.privacyEnhanced = true")
594
595 b = hugolib.Test(t, files)
596 b.AssertFileContent("public/p1/index.html", "48398992f5ff0afc")
597 b.AssertFileContent("public/p2/index.html", "116436ffc3f62191")
598 }
599
600 func TestShortcodePlainTextVsHTMLTemplateIssue13698(t *testing.T) {
601 t.Parallel()
602
603 filesTemplate := `
604 -- hugo.toml --
605 markup.goldmark.renderer.unsafe = true
606 -- layouts/all.html --
607 Content: {{ .Content }}|
608 -- layouts/_shortcodes/mymarkdown.md --
609 <div>Foo bar</div>
610 -- content/p1.md --
611 ---
612 title: p1
613 ---
614 ## A shortcode
615
616 SHORTCODE
617
618 `
619
620 files := strings.ReplaceAll(filesTemplate, "SHORTCODE", "{{% mymarkdown %}}")
621 b := hugolib.Test(t, files)
622 b.AssertFileContent("public/p1/index.html", "<div>Foo bar</div>")
623
624 files = strings.ReplaceAll(filesTemplate, "SHORTCODE", "{{< mymarkdown >}}")
625
626 var err error
627 b, err = hugolib.TestE(t, files)
628 b.Assert(err, qt.IsNotNil)
629 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`)
630 }
631
632 func TestShortcodeOnlyLanguageInBaseIssue13699And13740(t *testing.T) {
633 t.Parallel()
634
635 files := `
636 -- hugo.toml --
637 baseURL = 'https://example.org/'
638 disableLanguages = ['de']
639 [languages]
640 [languages.en]
641 weight = 1
642 [languages.de]
643 weight = 2
644 -- layouts/_shortcodes/de.html --
645 de.html
646 -- layouts/all.html --
647 {{ .Content }}
648 -- content/_index.md --
649 ---
650 title: home
651 ---
652 {{< de >}}
653
654 `
655 b := hugolib.Test(t, files)
656
657 b.AssertFileContent("public/index.html", "de.html")
658 }
659
660 func TestShortcodeLanguage13767(t *testing.T) {
661 t.Parallel()
662
663 files := `
664 -- hugo.toml --
665 defaultContentLanguage = 'pl'
666 defaultContentLanguageInSubdir = true
667 [languages.pl]
668 weight = 1
669 [languages.en]
670 weight = 2
671 -- content/_index.md --
672 ---
673 title: dom
674 ---
675 {{< myshortcode >}}
676 -- content/_index.en.md --
677 ---
678 title: home
679 ---
680 {{< myshortcode >}}
681 -- layouts/_shortcodes/myshortcode.html --
682 myshortcode.html
683 -- layouts/_shortcodes/myshortcode.en.html --
684 myshortcode.en.html
685 -- layouts/all.html --
686 {{ .Content }}
687
688
689 `
690
691 b := hugolib.Test(t, files)
692
693 b.AssertFileContent("public/pl/index.html", "myshortcode.html")
694 b.AssertFileContent("public/en/index.html", "myshortcode.en.html")
695 }
696
697 func TestHasShortcodeSamePageSourceDifferentShortcodes(t *testing.T) {
698 t.Parallel()
699
700 files := `
701 -- hugo.toml --
702 disableKinds = ['home','rss','section','sitemap','taxonomy','term', '404']
703 defaultContentLanguage = 'en'
704 defaultContentLanguageInSubdir = true
705 markup.goldmark.renderer.unsafe = true
706
707 [languages]
708 [languages.en]
709 weight = 1
710 [languages.sv]
711 weight = 2
712 -- content/inc/i1.md --
713 ---
714 headless: true
715 sites:
716 matrix:
717 languages:
718 - '**'
719 ---
720 {{% sc1 %}}
721 -- content/inc/i2.md --
722 ---
723 headless: true
724 sites:
725 matrix:
726 languages:
727 - '**'
728 ---
729 {{% sc2 %}}
730 -- content/p1.md --
731 ---
732 title: p1
733 ---
734 P1.
735 {{% inc %}}
736 -- content/p1.sv.md --
737 ---
738 title: p1 sv
739 ---
740 P1.
741 {{% inc %}}
742 -- layouts/_shortcodes/sc1.html --
743 sc1
744 -- layouts/_shortcodes/sc2.html --
745 sc2
746 -- layouts/_shortcodes/inc.html --
747 {{ with site.GetPage "inc/i1.md" }}i1.RenderShortcodes: {{ .RenderShortcodes }}{{ end }}
748 -- layouts/_shortcodes/inc.sv.html --
749 {{ with site.GetPage "inc/i2.md" }}i1.RenderShortcodes: {{ .RenderShortcodes }}{{ end }}
750 -- layouts/all.html --
751 Content: {{ .Content }}|sc1: {{ .HasShortcode "sc1" }}|sc2: {{ .HasShortcode "sc2" }}|inc: {{ .HasShortcode "inc" }}|
752
753 `
754
755 b := hugolib.Test(t, files)
756
757 b.AssertFileContent("public/en/p1/index.html", " |sc1: true|sc2: false|inc: true|")
758 b.AssertFileContent("public/sv/p1/index.html", " |sc1: false|sc2: true|inc: true|")
759 }
760
761 func TestShortcodeMultilingualHTML(t *testing.T) {
762 t.Parallel()
763
764 files := `
765 -- hugo.toml --
766 baseURL = 'https://example.org/'
767 defaultContentLanguage = 'tr'
768 defaultContentLanguageInSubdir = true
769 [languages.tr]
770 weight = 1
771 [languages.en]
772 weight = 2
773 -- content/posts/test-post.tr.md --
774 +++
775 title = 'Test Post TR'
776 +++
777
778 {{< myhtml >}}
779 -- content/posts/test-post.en.md --
780 +++
781 title = 'Test Post EN'
782 +++
783
784 {{< myhtml >}}
785 -- layouts/_shortcodes/myhtml.en.html --
786 HTML-EN
787 -- layouts/_shortcodes/myhtml.tr.html --
788 HTML-TR
789 -- layouts/_default/single.html --
790 {{ .Content }}
791 `
792
793 b := hugolib.Test(t, files)
794
795 b.AssertFileContent("public/tr/posts/test-post/index.html",
796 "HTML-TR",
797 )
798
799 b.AssertFileContent("public/en/posts/test-post/index.html",
800 "HTML-EN",
801 )
802 }
803
804 func TestShortcodeMultilingualMarkdown(t *testing.T) {
805 t.Parallel()
806
807 files := `
808 -- hugo.toml --
809 baseURL = 'https://example.org/'
810 defaultContentLanguage = 'tr'
811 defaultContentLanguageInSubdir = true
812 [languages.tr]
813 weight = 1
814 [languages.en]
815 weight = 2
816 -- content/posts/test-post.tr.md --
817 +++
818 title = 'Test Post TR'
819 +++
820
821 {{% mymd %}}
822 -- content/posts/test-post.en.md --
823 +++
824 title = 'Test Post EN'
825 +++
826
827 {{% mymd %}}
828 -- layouts/_shortcodes/mymd.en.md --
829 MD-EN
830 -- layouts/_shortcodes/mymd.tr.md --
831 MD-TR
832 -- layouts/_default/single.html --
833 {{ .Content }}
834 `
835
836 b := hugolib.Test(t, files)
837
838 b.AssertFileContent("public/tr/posts/test-post/index.html",
839 "MD-TR",
840 )
841
842 b.AssertFileContent("public/en/posts/test-post/index.html",
843 "MD-EN",
844 )
845 }
846
847 // Issue 14488
848 func TestTwitterShortcodeDeprecationError14488(t *testing.T) {
849 t.Parallel()
850
851 files := `
852 -- hugo.toml --
853 disableKinds = ['home','rss','section','sitemap','taxonomy','term']
854 -- content/p1.md --
855 ---
856 title: p1
857 ---
858 {{< SHORTCODE user="SanDiegoZoo" id="1453110110599868418" >}}
859 -- layouts/page.html --
860 {{ .Content }}
861 `
862
863 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.`
864
865 shortcodes := []string{"twitter", "twitter_simple", "tweet"}
866 for _, sc := range shortcodes {
867 f := strings.ReplaceAll(files, "SHORTCODE", sc)
868 b, err := hugolib.TestE(t, f, hugolib.TestOptWarn())
869 b.Assert(err, qt.IsNotNil)
870 b.AssertLogContains(want)
871 }
872 }
873
874 // Issue 14491
875 func TestGistShortcodeDeprecationError14491(t *testing.T) {
876 t.Parallel()
877
878 files := `
879 -- hugo.toml --
880 disableKinds = ['page','rss','section','sitemap','taxonomy','term']
881 -- layouts/home.html --
882 {{ .Content }}
883 -- content/_index.md --
884 ---
885 title: home
886 ---
887 {{< gist user 23932424365401ffa5e9d9810102a477 >}}
888 `
889
890 b, err := hugolib.TestE(t, files, hugolib.TestOptWarn())
891 b.Assert(err, qt.IsNotNil)
892 b.AssertLogContains(`ERROR The "gist" shortcode was deprecated in v0.143.0 and removed in v0.156.0.`)
893 }