Skip to content

Fixed partially styled call-outs #297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions exampleSite/_banners/test-product-intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{<banner "caution" "Under development">}}
<br>
This product on our example site is under development and changes are being added frequently.
<br>
Please reach out to <strong>#friends-of-the-docs</strong> on Slack to ask questions.
{{</banner>}}
5 changes: 5 additions & 0 deletions exampleSite/content/test-product/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ description: Test pages for nginx-hugo-theme
title: Test pages
weight: 100
nd-landing-page: true
cascade:
nd-banner:
enabled: true
start-date: 2025-01-01
md: /_banners/test-product-intro.md
---
{{<card-layout>}}
{{<card-section showAsCards="true">}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ The callout shortcode aims to support both, but **not** in the same shortcode in
## The two callouts below using **unnamed** params

{{<call-out "" "Custom title" "fa fa-check-circle" "true">}}
This callout uses the icon check-circle. **This should be an inline callout.**
This callout uses the icon check-circle. **This should be an sideline callout.**
{{</call-out>}}

{{<call-out "" "Custom title" "fa fa-check-circle" "false">}}
This callout uses the icon check-circle. **This should be an sideline callout.**
This callout uses the icon check-circle. **This should be an inline callout.**
{{</call-out>}}

## The two callouts below using **named** params
This should work exactly the same as the two callouts above

{{<call-out title="Custom title" icon="fa fa-check-circle" inline="true">}}
This callout uses the icon check-circle. **This should be an inline callout.**
{{<call-out title="Custom title" icon="fa fa-check-circle" sideline="true">}}
This callout uses the icon check-circle. **This should be an sideline callout.**
{{</call-out>}}

{{<call-out title="Custom title" icon="fa fa-check-circle" inline="asdas">}}
{{<call-out title="Custom title" icon="fa fa-check-circle" sideline="true">}}
This callout uses the icon check-circle. **This should be an sideline callout.**
{{</call-out>}}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ This assumes the callout text is shorter than the text in the callout.
If the text in the paragraph is shorter than the callout, it's likely
the content needs to be re-written.

{{<call-out "tip inline-callout" "Tip for Automated Reporting" >}}
{{<call-out "tip" "Tip for Automated Reporting" >}}
I am some call out text. Look at me go!
{{</call-out>}}
37 changes: 18 additions & 19 deletions layouts/partials/callout.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
{{ $class := .class | default "" }}
{{ $title := .title | default "" }}
{{ $icon := .icon | default "" }}
{{ $inlineParam := .inline | default "false" | lower }}
{{ $sidelineParam := .sideline | default "false" | lower }}

{{ if not (in (slice "true" "false") $inlineParam) }}
{{ errorf "Invalid parameter 'inline'='%s' passed to blockquote partial from '%s'. Allowed values: true, false" $inlineParam .Page.Path }}
{{ if not (in (slice "true" "false") $sidelineParam) }}
{{ errorf "Invalid parameter 'sideline'='%s' passed to blockquote partial from '%s'. Allowed values: true, false" $sidelineParam .Page.Path }}
{{ end }}

{{/* Figure out inline/side and set class accordingly */}}
{{ $inline := eq $inlineParam "true" }}
{{ $sideline := eq $sidelineParam "true" }}
{{ $sideOption := "side-callout" }}
{{ $inlineOption := "inline-callout" }}

{{ if $inline }}
{{ if $sideline }}
{{ $class = printf "%s %s" $class $sideOption }}
{{ else }}
{{ $class = printf "%s %s" $class $inlineOption }}
Expand All @@ -34,31 +34,30 @@


{{/* Render a different block, if "loud" callouts are used */}}
{{ $type := (index (split $class " ") 0) | strings.FirstUpper }}
{{ $specialTitles := slice "Caution" "Warning" "Deprecated" "Important" }}
{{ $specialTitleIcons := dict
"Caution" "alert-triangle"
"Warning" "alert-octagon"
"Deprecated" "alert-octagon"
"Important" "arrow-right-circle"
}}
{{ $icon := index $specialTitleIcons $title | default "" }}
{{ $icon := index $specialTitleIcons $type | default "" }}

{{ $isSpecialTitle := in $specialTitles $title }}
{{ $isSpecialTitle := in $specialTitles $type }}
{{ if $isSpecialTitle }}
{{/* Loud callouts */}}
{{/* Loud callouts */}}
<blockquote class="{{ $class }}" data-mf="true" style="display: none;">
<div>
<blockquote class="{{ $class }}" data-mf="true" style="display: none;">
<div>
<div class="call-out-type">
{{ partial "feather" (dict "context" . "icon" $icon) .}}
{{ $title }}
</div>
<div class="callout-content">
{{ .content | markdownify }}
</div>
<div class="call-out-type">
{{ partial "feather" (dict "context" . "icon" $icon) .}}
{{ $title }}
</div>
</blockquote>
</div>
<div class="callout-content">
{{ .content | markdownify }}
</div>
</div>
</blockquote>

{{ else }}

Expand Down
5 changes: 3 additions & 2 deletions layouts/shortcodes/banner.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{{- $type := .Get 0 | default (.Get "type") | default "" -}}
{{- $title := .Get 1 | default (.Get "title") | default "" -}}
{{ partial "callout.html" (dict
"class" $type
"class" (printf "%s %s" $type "call-out")
"title" $title
"icon" "fa-solid fa-triangle-exclamation"
"inline" true
"sideline" true
"type" ($type | strings.FirstUpper)
"content" .Inner
) }}
2 changes: 1 addition & 1 deletion layouts/shortcodes/before-you-begin.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"class" "tip"
"title" "Before you begin:"
"icon" ""
"inline" "false"
"sideline" "false"
"content" .Inner
) }}
{{ warnf "'<before-you-begin></before-you-begin>' is being deprecated. Use generic 'call-out' shortcode instead."}}
27 changes: 8 additions & 19 deletions layouts/shortcodes/call-out.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{{/*

Usage:
{{<call-out title="Custom title" icon="fa fa-check-circle" inline="true">}}
This callout uses the icon check-circle. **This should be an inline callout.**
{{<call-out title="Custom title" icon="fa fa-check-circle" sideline="true">}}
This callout uses the icon check-circle. **This should be an sideline callout.**
{{</call-out>}}

Backwards compatibility usage:
{{<call-out "warning" "Custom title" "fa fa-check-circle" "true">}}
This callout uses the icon check-circle. **This should be an inline callout.**
This callout uses the icon check-circle. **This should be an sideline callout.**
{{</call-out>}}

Depends on `callout.html` partial.
Expand All @@ -19,27 +19,16 @@
{{ $icon := .Get 2 | default (.Get "icon") | default "" }}

{{/* Handle different versions of booleans */}}
{{ $inlineParam := (.Get 3) | default (.Get "inline") | default "false" | lower }}
{{ $sidelineParam := (.Get 3) | default (.Get "sideline") | default "false" | lower }}
{{- /* Validate the parameter strictly */ -}}
{{ if not (in (slice "true" "false") $inlineParam) }}
{{ warnf "The '<call-out>' Shortcode parameter 'inline' must be 'true' or 'false', but got: '%s'. This will now default to 'false'" $inlineParam}}
{{ end }}

{{ $inline := eq $inlineParam "true" }}

{{ $sideOption := "side-callout" }}
{{ $inlineOption := "inline-callout" }}

{{ if $inline }}
{{ $class = printf "%s %s" $class $inlineOption }}
{{ else }}
{{ $class = printf "%s %s" $class $sideOption }}
{{ if not (in (slice "true" "false") $sidelineParam) }}
{{ warnf "The '<call-out>' Shortcode parameter 'sideline' must be 'true' or 'false', but got: '%s'. This will now default to 'false'" $sidelineParam}}
{{ end }}

{{ partial "callout.html" (dict
"class" $class
"class" (printf "%s %s" $class "call-out")
"title" $title
"icon" $icon
"inline" $inline
"sideline" $sidelineParam
"content" .Inner
) }}
2 changes: 1 addition & 1 deletion layouts/shortcodes/caution.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"class" "caution call-out"
"title" "Caution"
"icon" ""
"inline" "false"
"sideline" "false"
"content" .Inner
) }}
2 changes: 1 addition & 1 deletion layouts/shortcodes/deprecated.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"class" "warning call-out"
"title" "Deprecated"
"icon" ""
"inline" "false"
"sideline" "false"
"content" .Inner
) }}
2 changes: 1 addition & 1 deletion layouts/shortcodes/important.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"class" "important call-out"
"title" "Important"
"icon" ""
"inline" "false"
"sideline" "false"
"content" .Inner
) }}
2 changes: 1 addition & 1 deletion layouts/shortcodes/note.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"class" "note"
"title" "Note:"
"icon" ""
"inline" "false"
"sideline" "false"
"content" .Inner
) }}
{{ warnf "'<note></note>' is being deprecated. Use generic 'call-out' shortcode instead."}}
2 changes: 1 addition & 1 deletion layouts/shortcodes/see-also.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"class" "tip"
"title" "See Also:"
"icon" ""
"inline" "false"
"sideline" "false"
"content" .Inner
) }}
{{ warnf "'<see-also></see-also>' is being deprecated. Use generic 'call-out' shortcode instead."}}
2 changes: 1 addition & 1 deletion layouts/shortcodes/tip.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"class" "tip"
"title" "Tip:"
"icon" ""
"inline" "false"
"sideline" "false"
"content" .Inner
) }}
{{ warnf "'<tip></tip>' is being deprecated. Use generic 'call-out' shortcode instead."}}
2 changes: 1 addition & 1 deletion layouts/shortcodes/warning.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"class" "warning call-out"
"title" "Warning"
"icon" ""
"inline" "false"
"sideline" "false"
"content" .Inner
) }}
Loading