diff --git a/tpl/tplimpl/embedded/templates/shortcodes/qr.html b/tpl/tplimpl/embedded/templates/shortcodes/qr.html
index 818f6656d..05e8dbde9 100644
--- a/tpl/tplimpl/embedded/templates/shortcodes/qr.html
+++ b/tpl/tplimpl/embedded/templates/shortcodes/qr.html
@@ -9,7 +9,7 @@ Encodes the given text into a QR code using the specified options and renders th
@param {string} [class] The class attribute of the img element.
@param {string} [id] The id attribute of the img element.
@param {string} [title] The title attribute of the img element.
-@param {string} [loading] The loading attribute of the img element, one of lazy, or eager.
+@param {string} [loading] The loading attribute of the img element, one of lazy or eager.
@returns {template.HTML}
@@ -49,7 +49,6 @@ Encodes the given text into a QR code using the specified options and renders th
{{- $title := or (.Get "title") "" }}
{{- $loading := or (.Get "loading") "" }}
-
{{- /* Validate arguments. */}}
{{- $errors := false}}
{{- if not $text }}
diff --git a/tpl/tplimpl/embedded/templates/shortcodes/twitter.html b/tpl/tplimpl/embedded/templates/shortcodes/twitter.html
index 7a4adea5d..ce356559d 100644
--- a/tpl/tplimpl/embedded/templates/shortcodes/twitter.html
+++ b/tpl/tplimpl/embedded/templates/shortcodes/twitter.html
@@ -1,5 +1,5 @@
{{- 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 := .Page.Site.Config.Privacy.Twitter -}}
+{{- $pc := site.Config.Privacy.Twitter -}}
{{- if not $pc.Disable -}}
{{- if $pc.Simple -}}
{{- template "_internal/shortcodes/twitter_simple.html" . -}}
@@ -7,7 +7,7 @@
{{- $id := or (.Get "id") "" -}}
{{- $user := or (.Get "user") "" -}}
{{- if and $id $user -}}
- {{- template "render-tweet" (dict "id" $id "user" $user "dnt" $pc.EnableDNT "name" .Name "position" .Position) -}}
+ {{- 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 -}}
@@ -24,7 +24,7 @@
{{- else with .Value -}}
{{- (. | transform.Unmarshal).html | safeHTML -}}
{{- else -}}
- {{- warnidf "shortcode-twitter-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
+ {{- warnidf "shortcode-twitter-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" $.ctx.Name $.ctx.Position -}}
{{- end -}}
{{- end -}}
{{- end -}}
diff --git a/tpl/tplimpl/embedded/templates/shortcodes/twitter_simple.html b/tpl/tplimpl/embedded/templates/shortcodes/twitter_simple.html
index 7251f64e3..e9dcc76ba 100644
--- a/tpl/tplimpl/embedded/templates/shortcodes/twitter_simple.html
+++ b/tpl/tplimpl/embedded/templates/shortcodes/twitter_simple.html
@@ -23,7 +23,7 @@
{{- 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 -}}
+ {{- warnidf "shortcode-twitter-simple-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" $.ctx.Name $.ctx.Position -}}
{{- end -}}
{{- end -}}
{{- end -}}
diff --git a/tpl/tplimpl/embedded/templates/shortcodes/vimeo.html b/tpl/tplimpl/embedded/templates/shortcodes/vimeo.html
index 8ddad9b43..b3fc781a3 100644
--- a/tpl/tplimpl/embedded/templates/shortcodes/vimeo.html
+++ b/tpl/tplimpl/embedded/templates/shortcodes/vimeo.html
@@ -1,4 +1,4 @@
-{{- $pc := .Page.Site.Config.Privacy.Vimeo -}}
+{{- $pc := site.Config.Privacy.Vimeo -}}
{{- if not $pc.Disable -}}
{{- if $pc.Simple -}}
{{ template "_internal/shortcodes/vimeo_simple.html" . }}
@@ -11,4 +11,4 @@
{{ end }}
{{- end -}}
-{{- end -}}
\ No newline at end of file
+{{- end -}}
diff --git a/tpl/tplimpl/embedded/templates/shortcodes/vimeo_simple.html b/tpl/tplimpl/embedded/templates/shortcodes/vimeo_simple.html
index 7f7940b80..11f19b1f6 100644
--- a/tpl/tplimpl/embedded/templates/shortcodes/vimeo_simple.html
+++ b/tpl/tplimpl/embedded/templates/shortcodes/vimeo_simple.html
@@ -1,6 +1,6 @@
-{{- $pc := .Page.Site.Config.Privacy.Vimeo -}}
+{{- $pc := site.Config.Privacy.Vimeo -}}
{{- if not $pc.Disable -}}
- {{- $ctx := dict "page" .Page "pc" $pc "name" .Name "position" .Position }}
+ {{- $ctx := dict "ctx" . }}
{{- if .IsNamedParams -}}
{{- with .Get "id" -}}
{{- $ctx = merge $ctx (dict "id" . "class" ($.Get "class")) -}}
@@ -19,7 +19,7 @@
{{- end -}}
{{- define "render-vimeo" -}}
- {{- $dnt := cond .pc.EnableDNT 1 0 -}}
+ {{- $dnt := cond site.Config.Privacy.Vimeo.EnableDNT 1 0 -}}
{{- $url := urls.JoinPath "https://vimeo.com" .id -}}
{{- $query := querify "url" $url "dnt" $dnt -}}
{{- $request := printf "https://vimeo.com/api/oembed.json?%s" $query -}}
@@ -32,7 +32,7 @@
{{- with $.class -}}
{{- $class = printf "%s %s" "s_video_simple" . -}}
{{- else -}}
- {{ template "__h_simple_css" $.page }}
+ {{ template "__h_simple_css" $.ctx.Page }}
{{- end -}}
{{- $thumbnail := .thumbnail_url -}}
{{- $original := $thumbnail | replaceRE "(_.*\\.)" "." -}}
@@ -40,13 +40,13 @@
ac
") +} + +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", + "A: An emphasized word.
\nB: An emphasized word.
\nC: An emphasized word.
\nD: An emphasized word.
\nD: An emphasized word.
\n+ ` + 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 := "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 + + // 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) + + // Test warnings + files = ` +-- hugo.toml -- +disableKinds = ['page','rss','section','sitemap','taxonomy','term'] +-- content/_index.md -- +--- +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/index.html -- +{{ .Content }} +` + + b = hugolib.Test(t, files, hugolib.TestOptWarn()) + 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.`, + ) +} diff --git a/tpl/tplimpl/tplimpl_integration_test.go b/tpl/tplimpl/tplimpl_integration_test.go index d1e214ce2..9b30466e8 100644 --- a/tpl/tplimpl/tplimpl_integration_test.go +++ b/tpl/tplimpl/tplimpl_integration_test.go @@ -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", "Owl bet you'll lose this staring contest 🦉 pic.twitter.com/eJh4f2zncC
— San Diego Zoo Wildlife Alliance (@sandiegozoo) October 26, 2021
ac
") -} - -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", - "A: An emphasized word.
\nB: An emphasized word.
\nC: An emphasized word.
\nD: An emphasized word.
\nD: An emphasized word.
\n- ` - 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 := "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 - - // 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) -}Owl bet you'll lose this staring contest 🦉 pic.twitter.com/eJh4f2zncC
— San Diego Zoo Wildlife Alliance (@sandiegozoo) October 26, 2021