docs: call shortcode from partials #277

This commit is contained in:
Sören Weber 2022-06-23 00:03:24 +02:00
parent 5118f1982e
commit aa4d1b77bd
No known key found for this signature in database
GPG key ID: 07D17FF580AE7589
11 changed files with 186 additions and 18 deletions

View file

@ -14,6 +14,10 @@ This document shows you what's new in the latest release. For a detailed list of
--- ---
## 4.2.0
- **New**: All shortcodes can now be also called from your partials. Examples for this are added to the documentation of each shortcode.
## 4.1.0 ## 4.1.0
- **New**: While fixing issues with the search functionality for non latin languages, you can now [configure to have multiple languages on a single page]({{% relref "cont/i18n/#search-with-mixed-language-support" %}}). - **New**: While fixing issues with the search functionality for non latin languages, you can now [configure to have multiple languages on a single page]({{% relref "cont/i18n/#search-with-mixed-language-support" %}}).

View file

@ -5,14 +5,32 @@ title = "Attachments"
The `attachments` shortcode displays a list of files attached to a page with adjustable color, title and icon. The `attachments` shortcode displays a list of files attached to a page with adjustable color, title and icon.
{{% attachments /%}} {{% attachments sort="asc" /%}}
## Usage ## Usage
While the examples are using shortcodes with named parameter you are free to also call this shortcode from your own partials.
{{< tabs groupId="shortcode-parameter">}}
{{% tab name="shortcode" %}}
````go ````go
{{%/* attachments /*/%}} {{%/* attachments sort="asc" /*/%}}
```` ````
{{% /tab %}}
{{% tab name="partial" %}}
````go
{{ partial "shortcodes/attachments.html" (dict
"context" .
"sort" "asc"
)}}
````
{{% /tab %}}
{{< /tabs >}}
The shortcurt lists files found in a specific folder. The shortcurt lists files found in a specific folder.
Currently, it supports two implementations for pages Currently, it supports two implementations for pages

View file

@ -10,11 +10,37 @@ The `button` shortcode displays a clickable button with adjustable color, title
## Usage ## Usage
While the examples are using shortcodes with named parameter you are free to also call this shortcode from your own partials.
{{< tabs groupId="shortcode-parameter">}}
{{% tab name="shortcode" %}}
````go ````go
{{%/* button href="https://gohugo.io/" %}}Get Hugo{{% /button */%}} {{%/* button href="https://gohugo.io/" %}}Get Hugo{{% /button */%}}
{{%/* button href="https://gohugo.io/" style="warning" icon="dragon" %}}Get Hugo{{% /button */%}} {{%/* button href="https://gohugo.io/" style="warning" icon="dragon" %}}Get Hugo{{% /button */%}}
```` ````
{{% /tab %}}
{{% tab name="partial" %}}
````go
{{ partial "shortcodes/button.html" (dict
"context" .
"href" "https://gohugo.io/"
"content" "Get Hugo"
)}}
{{ partial "shortcodes/button.html" (dict
"context" .
"href" "https://gohugo.io/"
"style" "warning"
"icon" "dragon"
"content" "Get Hugo"
)}}
````
{{% /tab %}}
{{< /tabs >}}
Once the button is clicked, it opens another browser tab for the given URL. Once the button is clicked, it opens another browser tab for the given URL.
### Parameter ### Parameter

View file

@ -6,12 +6,31 @@ title = "Children"
The `children` shortcode lists the child pages of a page and its descendants . The `children` shortcode lists the child pages of a page and its descendants .
{{% children sort="weight" %}}
## Usage ## Usage
While the examples are using shortcodes with named parameter you are free to also call this shortcode from your own partials.
{{< tabs groupId="shortcode-parameter">}}
{{% tab name="shortcode" %}}
````go ````go
{{%/* children */%}} {{%/* children sort="weight" */%}}
```` ````
{{% /tab %}}
{{% tab name="partial" %}}
````go
{{ partial "shortcodes/children.html" (dict
"context" .
"sort" "weight"
)}}
````
{{% /tab %}}
{{< /tabs >}}
### Parameter ### Parameter
| Name | Default | Notes | | Name | Default | Notes |

View file

@ -9,22 +9,33 @@ The `expand` shortcode displays an expandable/collapsible section of text.
## Usage ## Usage
While the examples are using named parameter you are free to use positional aswell. While the examples are using shortcodes with named parameter you are free to use positional aswell or also call this shortcode from your own partials.
{{< tabs groupId="shortcode-parameter">}} {{< tabs groupId="shortcode-parameter">}}
{{% tab name="named" %}} {{% tab name="shortcode" %}}
````go ````go
{{%/* expand title="Expand me..." */%}}Thank you!{{%/* /expand */%}} {{%/* expand title="Expand me..." */%}}Thank you!{{%/* /expand */%}}
```` ````
{{% /tab %}} {{% /tab %}}
{{% tab name="positional" %}} {{% tab name="shortcode (positional)" %}}
````go ````go
{{%/* expand "Expand me..." */%}}Thank you!{{%/* /expand */%}} {{%/* expand "Expand me..." */%}}Thank you!{{%/* /expand */%}}
```` ````
{{% /tab %}}
{{% tab name="partial" %}}
````go
{{ partial "shortcodes/expand.html" (dict
"context" .
"title" "Expand me..."
"content" "Thank you!"
)}}
````
{{% /tab %}} {{% /tab %}}
{{< /tabs >}} {{< /tabs >}}

View file

@ -7,10 +7,10 @@ The `include` shortcode includes other files from your project inside of the cur
## Usage ## Usage
While the examples are using named parameter you are free to use positional aswell. While the examples are using shortcodes with named parameter you are free to use positional aswell or also call this shortcode from your own partials.
{{< tabs groupId="shortcode-parameter">}} {{< tabs groupId="shortcode-parameter">}}
{{% tab name="named" %}} {{% tab name="shortcode" %}}
````go ````go
@ -18,12 +18,22 @@ While the examples are using named parameter you are free to use positional aswe
```` ````
{{% /tab %}} {{% /tab %}}
{{% tab name="positional" %}} {{% tab name="shortcode (positional)" %}}
````go ````go
{{%/* include "shortcodes/INCLUDE_ME.md" */%}} {{%/* include "shortcodes/INCLUDE_ME.md" */%}}
```` ````
{{% /tab %}}
{{% tab name="partial" %}}
````go
{{ partial "shortcodes/include .html" (dict
"context" .
"file" "shortcodes/INCLUDE_ME.md"
)}}
````
{{% /tab %}} {{% /tab %}}
{{< /tabs >}} {{< /tabs >}}

View file

@ -21,15 +21,15 @@ Due to limitations with [Mermaid](https://github.com/mermaid-js/mermaid/issues/1
## Usage ## Usage
The generated graphs can be be panned by dragging them and zoomed by using the mousewheel. On mobile devices you can use finger gestures. While the examples are using shortcodes with named parameter it is recommended to use codefences instead. This is because more and more other software supports Mermaid codefences (eg. GitHub) and so your markdown becomes more portable.
While the examples are using shortcode syntax it is recommended to use codefence syntax instead. This is because more and more other software supports Mermaid codefences (eg. GitHub) and so your markdown becomes more portable. You are free to also call this shortcode from your own partials.
{{% notice note %}} {{% notice note %}}
To use codefence syntax you have to turn off `guessSyntax` for the `markup.highlight` setting ([see the configuration section](#configuration)). To use codefence syntax you have to turn off `guessSyntax` for the `markup.highlight` setting ([see the configuration section](#configuration)).
{{% /notice %}} {{% /notice %}}
{{< tabs groupId="shortcode-codefence">}} {{< tabs groupId="shortcode-parameter">}}
{{% tab name="codefence" %}} {{% tab name="codefence" %}}
````plaintext ````plaintext
@ -51,9 +51,22 @@ graph LR;
{{</* /mermaid */>}} {{</* /mermaid */>}}
```` ````
{{% /tab %}}
{{% tab name="partial" %}}
````go
{{ partial "shortcodes/mermaid.html" (dict
"context" .
"content" "graph LR;\nIf --> Then\nThen --> Else"
)}}
````
{{% /tab %}} {{% /tab %}}
{{< /tabs >}} {{< /tabs >}}
The generated graphs can be be panned by dragging them and zoomed by using the mousewheel. On mobile devices you can use finger gestures.
### Parameter ### Parameter
Parameter are only supported when using shortcode syntax. Defaults are used when using codefence syntax. Parameter are only supported when using shortcode syntax. Defaults are used when using codefence syntax.

View file

@ -11,10 +11,10 @@ It is all about the boxes.
## Usage ## Usage
While the examples are using named parameter you are free to use positional aswell. While the examples are using shortcodes with named parameter you are free to use positional aswell or also call this shortcode from your own partials.
{{< tabs groupId="shortcode-parameter">}} {{< tabs groupId="shortcode-parameter">}}
{{% tab name="named" %}} {{% tab name="shortcode" %}}
````go ````go
{{%/* notice style="primary" title="There may be pirates" icon="skull-crossbones" */%}} {{%/* notice style="primary" title="There may be pirates" icon="skull-crossbones" */%}}
@ -23,7 +23,7 @@ It is all about the boxes.
```` ````
{{% /tab %}} {{% /tab %}}
{{% tab name="positional" %}} {{% tab name="shortcode (positional)" %}}
````go ````go
{{%/* notice primary "There may be pirates" "skull-crossbones" */%}} {{%/* notice primary "There may be pirates" "skull-crossbones" */%}}
@ -31,6 +31,19 @@ It is all about the boxes.
{{%/* /notice */%}} {{%/* /notice */%}}
```` ````
{{% /tab %}}
{{% tab name="partial" %}}
````go
{{ partial "shortcodes/notice.html" (dict
"context" .
"style" "primary"
"title" "There may be pirates"
"icon" "skull-crossbones"
"content" "It is all about the boxes."
)}}
````
{{% /tab %}} {{% /tab %}}
{{< /tabs >}} {{< /tabs >}}

View file

@ -7,10 +7,10 @@ The `siteparam` shortcode prints values of site params.
## Usage ## Usage
While the examples are using named parameter you are free to use positional aswell. While the examples are using shortcodes with named parameter you are free to use positional aswell or call this shortcode from your own partials.
{{< tabs groupId="shortcode-parameter">}} {{< tabs groupId="shortcode-parameter">}}
{{% tab name="named" %}} {{% tab name="shortcode" %}}
````go ````go
@ -18,12 +18,22 @@ While the examples are using named parameter you are free to use positional aswe
```` ````
{{% /tab %}} {{% /tab %}}
{{% tab name="positional" %}} {{% tab name="shortcode (positional)" %}}
````go ````go
{{%/* siteparam "editURL" */%}} {{%/* siteparam "editURL" */%}}
```` ````
{{% /tab %}}
{{% tab name="partial" %}}
````go
{{ partial "shortcodes/siteparam.html" (dict
"context" .
"name" "editURL"
)}}
````
{{% /tab %}} {{% /tab %}}
{{< /tabs >}} {{< /tabs >}}

View file

@ -11,11 +11,28 @@ This only works in modern browsers.
## Usage ## Usage
While the examples are using shortcodes with named parameter you are free to also call this shortcode from your own partials.
{{< tabs groupId="shortcode-parameter">}}
{{% tab name="shortcode" %}}
````go ````go
{{</* swagger src="https://petstore3.swagger.io/api/v3/openapi.json" */>}} {{</* swagger src="https://petstore3.swagger.io/api/v3/openapi.json" */>}}
```` ````
{{% /tab %}}
{{% tab name="partial" %}}
````go
{{ partial "shortcodes/swagger.html" (dict
"context" .
"src" "https://petstore3.swagger.io/api/v3/openapi.json"
)}}
````
{{% /tab %}}
{{< /tabs >}}
### Parameter ### Parameter
| Name | Default | Notes | | Name | Default | Notes |

View file

@ -24,6 +24,11 @@ echo "Hello World!"
## Usage ## Usage
While the examples are using shortcodes with named parameter you are free to also call this shortcode from your own partials.
{{< tabs groupId="shortcode-parameter">}}
{{% tab name="shortcode" %}}
````go ````go
{{</* tabs */>}} {{</* tabs */>}}
{{%/* tab name="python" */%}} {{%/* tab name="python" */%}}
@ -39,6 +44,28 @@ echo "Hello World!"
{{</* /tabs */>}} {{</* /tabs */>}}
```` ````
{{% /tab %}}
{{% tab name="partial" %}}
````go
{{ partial "shortcodes/tabs.html" (dict
"context" .
"tabs" (slice
(dict
"name" "python"
"content" ("```python\nprint(\"Hello World!\")\n```" | markdownify)
)
(dict
"name" "bash"
"content" ("```bash\necho \"Hello World!\"\n```" | markdownify)
)
)
)}}
````
{{% /tab %}}
{{< /tabs >}}
### Parameter ### Parameter
| Name | Default | Notes | | Name | Default | Notes |