Remove superfluous shortcode param

This commit is contained in:
Joe Mooring
2023-11-07 14:06:01 -08:00
committed by Joe Mooring
parent 2a0544757c
commit 45ec53fe00
27 changed files with 49 additions and 49 deletions
+4 -4
View File
@@ -22,13 +22,13 @@ Some shortcodes support positional parameters, some support named parameters, an
This shortcode call uses positional parameters:
{{< code file="content/about.md" lang=md copy=false >}}
{{< code file="content/about.md" lang=md >}}
{{</* myshortcode "Hello" "world" */>}}
{{< /code >}}
To retrieve parameters by position:
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
{{ printf "%s %s." (.Get 0) (.Get 1) }} → Hello world.
{{< /code >}}
@@ -36,13 +36,13 @@ To retrieve parameters by position:
This shortcode call uses named parameters:
{{< code file="content/about.md" lang=md copy=false >}}
{{< code file="content/about.md" lang=md >}}
{{</* myshortcode greeting="Hello" firstName="world" */>}}
{{< /code >}}
To retrieve parameters by name:
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
{{ printf "%s %s." (.Get "greeting") (.Get "firstName") }} → Hello world.
{{< /code >}}
+6 -6
View File
@@ -15,7 +15,7 @@ action:
This content:
{{< code file="content/services.md" lang=md copy=false >}}
{{< code file="content/services.md" lang=md >}}
{{</* card title="Product Design" */>}}
We design the **best** widgets in the world.
{{</* /card */>}}
@@ -23,7 +23,7 @@ We design the **best** widgets in the world.
With this shortcode:
{{< code file="layouts/shortcodes/card.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/card.html" lang=go-html-template >}}
<div class="card">
{{ with .Get "title" }}
<div class="card-title">{{ . }}</div>
@@ -62,7 +62,7 @@ Let's modify the example above to pass the value returned by `Inner` through the
[`RenderString`]: /methods/page/renderstring
{{< code file="layouts/shortcodes/card.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/card.html" lang=go-html-template >}}
<div class="card">
{{ with .Get "title" }}
<div class="card-title">{{ . }}</div>
@@ -93,7 +93,7 @@ You can use the [`markdownify`] function instead of the `RenderString` method, b
Instead of calling the shortcode with the `{{</* */>}}` notation, use the `{{%/* */%}}` notation:
{{< code file="content/services.md" lang=md copy=false >}}
{{< code file="content/services.md" lang=md >}}
{{%/* card title="Product Design" */%}}
We design the **best** widgets in the world.
{{%/* /card */%}}
@@ -103,7 +103,7 @@ When you use the `{{%/* */%}}` notation, Hugo renders the entire shortcode as ma
First, configure the renderer to allow raw HTML within markdown:
{{< code-toggle file=hugo copy=false >}}
{{< code-toggle file=hugo >}}
[markup.goldmark.renderer]
unsafe = true
{{< /code-toggle >}}
@@ -112,7 +112,7 @@ This configuration is not unsafe if _you_ control the content. Read more about H
Second, because we are rendering the entire shortcode as markdown, we must adhere to the rules governing [indentation] and inclusion of [raw HTML blocks] as provided in the [CommonMark] specification.
{{< code file="layouts/shortcodes/card.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/card.html" lang=go-html-template >}}
<div class="card">
{{ with .Get "title" }}
<div class="card-title">{{ . }}</div>
@@ -16,7 +16,7 @@ This allows us to effectively bypass the rules governing [indentation] as provid
Consider this markdown, an unordered list with a small gallery of thumbnail images within each list item:
{{< code file="content/about.md" lang=md copy=false >}}
{{< code file="content/about.md" lang=md >}}
- Gallery one
{{</* gallery */>}}
@@ -36,7 +36,7 @@ In the example above, notice that the content between the opening and closing sh
With this shortcode, calling `Inner` instead of `InnerDeindent`:
{{< code file="layouts/shortcodes/gallery.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/gallery.html" lang=go-html-template >}}
<div class="gallery">
{{ trim .Inner "\r\n" | .Page.RenderString }}
</div>
@@ -67,7 +67,7 @@ Hugo renders the markdown to:
Although technically correct per the CommonMark specification, this is not what we want. If we remove the indentation using the `InnerDeindent` method:
{{< code file="layouts/shortcodes/gallery.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/gallery.html" lang=go-html-template >}}
<div class="gallery">
{{ trim .InnerDeindent "\r\n" | .Page.RenderString }}
</div>
@@ -14,7 +14,7 @@ To support both positional and named parameters when calling a shortcode, use th
With this shortcode template:
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
{{ if .IsNamedParams }}
{{ printf "%s %s." (.Get "greeting") (.Get "firstName") }}
{{ else }}
@@ -24,7 +24,7 @@ With this shortcode template:
Both of these calls return the same value:
{{< code file="content/about.md" lang=md copy=false >}}
{{< code file="content/about.md" lang=md >}}
{{</* myshortcode greeting="Hello" firstName="world" */>}}
{{</* myshortcode "Hello" "world" */>}}
{{< /code >}}
+1 -1
View File
@@ -13,7 +13,7 @@ action:
The `Name` method is useful for error reporting. For example, if your shortcode requires a "greeting" parameter:
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
{{ $greeting := "" }}
{{ with .Get "greeting" }}
{{ $greeting = . }}
+2 -2
View File
@@ -13,7 +13,7 @@ The `Ordinal` method returns the zero-based ordinal of the shortcode in relation
This method is useful for, among other things, assigning unique element IDs when a shortcode is called two or more times from the same page. For example:
{{< code file="content/about.md" lang=md copy=false >}}
{{< code file="content/about.md" lang=md >}}
{{</* img src="images/a.jpg" */>}}
{{</* img src="images/b.jpg" */>}}
@@ -21,7 +21,7 @@ This method is useful for, among other things, assigning unique element IDs when
This shortcode performs error checking, then renders an HTML `img` element with a unique `id` attribute:
{{< code file="layouts/shortcodes/img.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/img.html" lang=go-html-template >}}
{{ $src := "" }}
{{ with .Get "src" }}
{{ $src = . }}
+2 -2
View File
@@ -11,7 +11,7 @@ action:
With this content:
{{< code-toggle file=content/books/les-miserables.md copy=false fm=true >}}
{{< code-toggle file=content/books/les-miserables.md fm=true >}}
title = 'Les Misérables'
author = 'Victor Hugo'
published = 1862
@@ -26,7 +26,7 @@ Calling this shortcode:
We can access the front matter values using the `Page` method:
{{< code file="layouts/shortcodes/book-details.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/book-details.html" lang=go-html-template >}}
<ul>
<li>Title: {{ .Page.Title }}</li>
<li>Author: {{ .Page.Params.author }}</li>
+4 -4
View File
@@ -12,22 +12,22 @@ action:
When you call a shortcode using positional parameters, the `Params` method returns a slice.
{{< code file="content/about.md" lang=md copy=false >}}
{{< code file="content/about.md" lang=md >}}
{{</* myshortcode "Hello" "world" */>}}
{{< /code >}}
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
{{ index .Params 0 }} → Hello
{{ index .Params 1 }} → world
{{< /code >}}
When you call a shortcode using named parameters, the `Params` method returns a map.
{{< code file="content/about.md" lang=md copy=false >}}
{{< code file="content/about.md" lang=md >}}
{{</* myshortcode greeting="Hello" name="world" */>}}
{{< /code >}}
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
{{ .Params.greeting }} → Hello
{{ .Params.name }} → world
{{< /code >}}
+3 -3
View File
@@ -13,19 +13,19 @@ This is useful for inheritance of common shortcode parameters from the root.
In this contrived example, the "greeting" shortcode is the parent, and the "now" shortcode is child.
{{< code file="content/welcome.md" lang=md copy=false >}}
{{< code file="content/welcome.md" lang=md >}}
{{</* greeting dateFormat="Jan 2, 2006" */>}}
Welcome. Today is {{</* now */>}}.
{{</* /greeting */>}}
{{< /code >}}
{{< code file="layouts/shortcodes/greeting.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/greeting.html" lang=go-html-template >}}
<div class="greeting">
{{ trim .Inner "\r\n" | .Page.RenderString }}
</div>
{{< /code >}}
{{< code file="layouts/shortcodes/now.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/now.html" lang=go-html-template >}}
{{- $dateFormat := "January 2, 2006 15:04:05" }}
{{- with .Params }}
+1 -1
View File
@@ -13,7 +13,7 @@ action:
The `Position` method is useful for error reporting. For example, if your shortcode requires a "greeting" parameter:
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template copy=false >}}
{{< code file="layouts/shortcodes/myshortcode.html" lang=go-html-template >}}
{{ $greeting := "" }}
{{ with .Get "greeting" }}
{{ $greeting = . }}