From 0cb97716e09a07c625b1c467c571574301d6f9d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6ren=20Weber?= Date: Sun, 1 Sep 2024 13:57:50 +0200 Subject: [PATCH] expand: rename open parameter to expanded #902 --- .../content/basics/migration/_index.en.md | 2 ++ exampleSite/content/shortcodes/expand.en.md | 6 +++--- layouts/partials/shortcodes/expand.html | 19 +++++++++++-------- layouts/shortcodes/expand.html | 11 ++++++----- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/exampleSite/content/basics/migration/_index.en.md b/exampleSite/content/basics/migration/_index.en.md index 805a96b40a..14e67af31d 100644 --- a/exampleSite/content/basics/migration/_index.en.md +++ b/exampleSite/content/basics/migration/_index.en.md @@ -20,6 +20,8 @@ This document shows you what's new in the latest release and flags it with one o ## 6.3.0.beta (XXXX-XX-XX) {#630} +- {{% badge style="note" title=" " %}}Change{{% /badge %}} The [`expand` shortcode](shortcodes/expand) changed the naming of the `open` parameter to `expanded`. You don't need to change anything yet but may get deprecation warnings. + - {{% badge style="note" title=" " %}}Change{{% /badge %}} If the content for the [`notice` shortcode](shortcodes/notice) is empty, now only the title bar will be displayed. Previously an empty content box was displayed. - {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The [`notice` shortcode](shortcodes/notice) has a new parameter `expanded` to make the content collapsible. diff --git a/exampleSite/content/shortcodes/expand.en.md b/exampleSite/content/shortcodes/expand.en.md index ca3290020f..85ce12be50 100644 --- a/exampleSite/content/shortcodes/expand.en.md +++ b/exampleSite/content/shortcodes/expand.en.md @@ -56,7 +56,7 @@ While the examples are using shortcodes with named parameter you are free to use | Name | Position | Default | Notes | |-----------------------|----------|------------------|-------------| | **title** | 1 | `"Expand me..."` | Arbitrary text to appear next to the expand/collapse icon. | -| **open** | 2 | `false` | When `true` the content text will be initially shown as expanded. | +| **expanded** | 2 | `false` | How the content is displayed.

- `true`: the content is initially shown
- `false`: the content is initially hidden | | _**<content>**_ | | _<empty>_ | Arbitrary text to be displayed on expand. | ## Examples @@ -72,10 +72,10 @@ While the examples are using shortcodes with named parameter you are free to use ### Initially Expanded ````go -{{%/* expand title="Expand me..." open="true" */%}}No need to press you!{{%/* /expand */%}} +{{%/* expand title="Expand me..." expanded="true" */%}}No need to press you!{{%/* /expand */%}} ```` -{{% expand title="Expand me..." open="true" %}}No need to press you!{{% /expand %}} +{{% expand title="Expand me..." expanded="true" %}}No need to press you!{{% /expand %}} ### Arbitrary Text diff --git a/layouts/partials/shortcodes/expand.html b/layouts/partials/shortcodes/expand.html index 37d8c4666a..781bd7414a 100644 --- a/layouts/partials/shortcodes/expand.html +++ b/layouts/partials/shortcodes/expand.html @@ -6,20 +6,23 @@ {{- $content := .content }} {{- $title := .title | default (T "Expand-title") }} {{- $title = trim $title " " }} -{{- $expanded := .open | default false }} +{{- $expanded := .expanded | default false }} +{{- if and (isset . "open") (or (ne (printf "%T" .open) "string") (ne (trim .open " " ) "")) }} + {{- warnf "%q: DEPRECATED parameter 'open' for shortcode 'expand' found, use 'expanded' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#630" $page.File.Filename }} + {{- $expanded = .open }} +{{- end }} {{- if eq (printf "%T" $expanded) "string" }} {{- $expanded = (eq $expanded "true") }} {{- end }} {{- $id := cond (or (eq .id nil) (eq .id "")) (partial "make-random-md5.hugo" $page) .id }} {{- with $page }}
- - -
+ + +
{{ if ne "<" (substr (strings.TrimLeft " \n\r\t" $content) 0 1) }}

{{ end }} {{ $content | safeHTML }}

diff --git a/layouts/shortcodes/expand.html b/layouts/shortcodes/expand.html index 14b77be525..598e13ed34 100644 --- a/layouts/shortcodes/expand.html +++ b/layouts/shortcodes/expand.html @@ -1,9 +1,10 @@ {{- $_hugo_config := `{ "version": 1 }` }} {{- $id := "" }} {{- partial "shortcodes/expand.html" (dict - "page" .Page - "content" .Inner - "open" (.Get "open" | default (.Get 1)) - "title" (.Get "title" | default (.Get 0)) - "id" $id + "page" .Page + "content" .Inner + "open" (.Get "open" | default "") + "expanded" (.Get "expanded" | default (.Get 1)) + "title" (.Get "title" | default (.Get 0)) + "id" $id ) }} \ No newline at end of file