mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-24 21:56:05 +02:00
committed by
Bjørn Erik Pedersen
parent
1f5a15aba0
commit
8de4ffb294
@@ -6,7 +6,6 @@ import (
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/gohugoio/hugo/htesting/hqt"
|
||||
"github.com/gohugoio/hugo/hugolib"
|
||||
"github.com/gohugoio/hugo/tpl"
|
||||
)
|
||||
@@ -586,71 +585,6 @@ title: p5
|
||||
)
|
||||
}
|
||||
|
||||
func TestCommentShortcode(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
||||
-- layouts/index.html --
|
||||
{{ .Content }}
|
||||
-- content/_index.md --
|
||||
a{{< comment >}}b{{< /comment >}}c
|
||||
`
|
||||
|
||||
b := hugolib.Test(t, files)
|
||||
b.AssertFileContent("public/index.html", "<p>ac</p>")
|
||||
}
|
||||
|
||||
func TestDetailsShortcode(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
||||
-- layouts/index.html --
|
||||
{{ .Content }}
|
||||
-- content/_index.md --
|
||||
---
|
||||
title: home
|
||||
---
|
||||
{{< details >}}
|
||||
A: An _emphasized_ word.
|
||||
{{< /details >}}
|
||||
|
||||
{{< details
|
||||
class="my-class"
|
||||
name="my-name"
|
||||
open=true
|
||||
summary="A **bold** word"
|
||||
title="my-title"
|
||||
>}}
|
||||
B: An _emphasized_ word.
|
||||
{{< /details >}}
|
||||
|
||||
{{< details open=false >}}
|
||||
C: An _emphasized_ word.
|
||||
{{< /details >}}
|
||||
|
||||
{{< details open="false" >}}
|
||||
D: An _emphasized_ word.
|
||||
{{< /details >}}
|
||||
|
||||
{{< details open=0 >}}
|
||||
E: An _emphasized_ word.
|
||||
{{< /details >}}
|
||||
`
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html",
|
||||
"<details>\n <summary>Details</summary>\n <p>A: An <em>emphasized</em> word.</p>\n</details>",
|
||||
"<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>",
|
||||
"<details>\n <summary>Details</summary>\n <p>C: An <em>emphasized</em> word.</p>\n</details>",
|
||||
"<details>\n <summary>Details</summary>\n <p>D: An <em>emphasized</em> word.</p>\n</details>",
|
||||
"<details>\n <summary>Details</summary>\n <p>D: An <em>emphasized</em> word.</p>\n</details>",
|
||||
)
|
||||
}
|
||||
|
||||
// Issue 12963
|
||||
func TestEditBaseofParseAfterExecute(t *testing.T) {
|
||||
files := `
|
||||
@@ -699,162 +633,3 @@ Home!
|
||||
b.BuildPartial("/mybundle1/")
|
||||
b.AssertFileContent("public/mybundle1/index.html", "Baseof!!")
|
||||
}
|
||||
|
||||
func TestQRShortcode(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
disableKinds = ['page','rss','section','sitemap','taxonomy','term']
|
||||
-- layouts/index.html --
|
||||
{{ .Content }}
|
||||
-- content/_index.md --
|
||||
---
|
||||
title: home
|
||||
---
|
||||
{{< qr
|
||||
text="https://gohugo.io"
|
||||
level="high"
|
||||
scale=4
|
||||
targetDir="codes"
|
||||
alt="QR code linking to https://gohugo.io"
|
||||
class="my-class"
|
||||
id="my-id"
|
||||
title="My Title"
|
||||
/>}}
|
||||
|
||||
{{< qr >}}
|
||||
https://gohugo.io"
|
||||
{{< /qr >}}
|
||||
`
|
||||
|
||||
b := hugolib.Test(t, files)
|
||||
|
||||
b.AssertFileContent("public/index.html",
|
||||
`<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">`,
|
||||
`<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"),
|
||||
}
|
||||
|
||||
b.Assert(htmlFiles, hqt.IsAllElementsEqual)
|
||||
|
||||
// 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"),
|
||||
}
|
||||
b.Assert(htmlFiles, hqt.IsAllElementsEqual)
|
||||
|
||||
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"),
|
||||
}
|
||||
b.Assert(htmlFiles, hqt.IsAllElementsEqual)
|
||||
|
||||
// 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)
|
||||
|
||||
// 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"),
|
||||
}
|
||||
b.Assert(htmlFiles, hqt.IsAllElementsEqual)
|
||||
|
||||
// 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"),
|
||||
}
|
||||
b.Assert(htmlFiles, hqt.IsAllElementsEqual)
|
||||
|
||||
htmlFiles = []string{
|
||||
b.FileContent("public/p2/index.html"),
|
||||
b.FileContent("public/p3/index.html"),
|
||||
}
|
||||
b.Assert(htmlFiles, hqt.IsAllElementsEqual)
|
||||
}
|
||||
|
Reference in New Issue
Block a user