Skip to content

Commit

Permalink
siteparam: support nested parameters and text formatting #590
Browse files Browse the repository at this point in the history
  • Loading branch information
McShelby committed Jul 26, 2023
1 parent 80c1b4e commit e9d3eb6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 7 deletions.
2 changes: 2 additions & 0 deletions exampleSite/config/_default/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,5 @@ title = "Hugo Relearn Documentation"
# security reasons
mermaidInitialize = "{ \"securityLevel\": \"loose\" }"
mermaidZoom = true
[params.siteparam.test]
text = "A **nested** parameter <b>with</b> formatting"
2 changes: 2 additions & 0 deletions exampleSite/content/basics/migration/_index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ This document shows you what's new in the latest release. For a detailed list of

In addition it offers some extensions. Currently only the `wrap` extension option is provided to control whether a code block should be wrapped or scrolled if to long to fit.

- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The [`siteparam` shortcode]({{% relref "shortcodes/siteparam" %}}) is now capable to display nested params aswell as adding support for text formatting.

---

## 5.16.0 (2023-06-10)
Expand Down
25 changes: 24 additions & 1 deletion exampleSite/content/shortcodes/siteparam.en.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
+++
description = "Get value of site params"
title = "Site Param"
title = "SiteParam"
+++

The `siteparam` shortcode prints values of site params.
Expand Down Expand Up @@ -52,3 +52,26 @@ While the examples are using shortcodes with named parameter you are free to use
```

`editURL` value: {{% siteparam name="editURL" %}}

### Nested parameter with Markdown and HTML formatting

To use formatted parameter, add this in your `config.toml`:

````toml
[markup.goldmark.renderer]
unsafe = true
````

{{% tab title="config.toml" %}}
````toml
[params]
[params.siteparam.test]
text = "A **nested** parameter <b>with</b> formatting"
````
{{% /tab %}}

```go
Formatted parameter: {{%/* siteparam name="siteparam.test.text" */%}}
```

Formatted parameter: {{% siteparam name="siteparam.test.text" %}}
2 changes: 1 addition & 1 deletion exampleSite/content/shortcodes/siteparam.pir.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
+++
descrption = "Get value o' ship parrrams varrriables 'n yer plank"
title = "Ship Param"
title = "SiteParam"
+++
{{< piratify >}}
11 changes: 6 additions & 5 deletions layouts/partials/shortcodes/siteparam.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{{- $context := .context }}
{{- $paramName := .name }}
{{- $paramNames := split .name "." }}
{{- with $context }}
{{- $siteParams := .Site.Params }}
{{- with $paramName }}
{{- with $siteParams }}
{{- index . (lower $paramName) }}
{{- $params := .Site.Params }}
{{- range $paramName := $paramNames }}
{{- with $params }}
{{- $params = index . (lower $paramName) }}
{{- end }}
{{- end }}
{{- $params | .RenderString }}
{{- end }}

0 comments on commit e9d3eb6

Please sign in to comment.