diff --git a/assets/css/v2/style.css b/assets/css/v2/style.css index 3f61224b..2df9d531 100644 --- a/assets/css/v2/style.css +++ b/assets/css/v2/style.css @@ -1083,6 +1083,10 @@ blockquote { /* Removes negative margins from multi-line codeblocks */ margin: 0; } + + .callout-content { + margin: 0; + } } blockquote.note { @@ -1091,8 +1095,7 @@ blockquote.note { } blockquote.note:before { - content: "Note"; - text-transform: uppercase; + content: attr(data-title); font-size: 1rem; font-weight: 600; font-variation-settings: "wght" 600; @@ -1135,14 +1138,16 @@ li > blockquote { } blockquote.call-out { - padding: 0.5rem; + --padding: 0.75rem; + padding: var(--padding); .call-out-type { display: block; - padding: 0.25rem 0.5rem; - margin: -0.5rem 0 0.5rem -0.5rem; - width: calc(100% + 1rem); font-weight: 500; + margin: calc(-1 * var(--padding)) calc(-1 * var(--padding)) var(--padding) + calc(-1 * var(--padding)); + + padding: 0.25rem var(--padding); } br { @@ -1158,6 +1163,9 @@ blockquote.caution { background-color: oklch(var(--color-callout-caution-shadow)); border-bottom: 1px solid oklch(var(--color-callout-caution-primary)); } + .call-out-type .feather { + color: oklch(var(--color-callout-caution-primary)); + } } blockquote.warning { @@ -1168,6 +1176,9 @@ blockquote.warning { background-color: oklch(var(--color-callout-warning-shadow)); border-bottom: 1px solid oklch(var(--color-callout-warning-primary)); } + .call-out-type .feather { + color: oklch(var(--color-callout-warning-primary)); + } } blockquote.important { diff --git a/exampleSite/content/test-product/call-out/all-callouts.md b/exampleSite/content/test-product/call-out/all-callouts.md index db1bb522..d09f70c2 100644 --- a/exampleSite/content/test-product/call-out/all-callouts.md +++ b/exampleSite/content/test-product/call-out/all-callouts.md @@ -65,6 +65,23 @@ This is a Warning callout with a custom title. There was previously a bug with * {{}} + + +## Old "plain" callouts +The following will not have special styling, but are pre-existing shortcodes. + {{}} -This is a note. In oldframe it should have `note:` in bold, at the start. -{{}} \ No newline at end of file +This is ``. In oldframe it should have `note:` in bold, at the start. +{{}} + +{{}} +This is ``. In oldframe it should have `tip:` in bold, at the start. +{{}} + +{{}} +This is ``. +{{}} + +{{}} +This is ``. +{{}} \ No newline at end of file diff --git a/exampleSite/content/test-product/call-out/call-out-param-types.md b/exampleSite/content/test-product/call-out/call-out-param-types.md new file mode 100644 index 00000000..86e694c3 --- /dev/null +++ b/exampleSite/content/test-product/call-out/call-out-param-types.md @@ -0,0 +1,32 @@ + +--- +description: Callout - Param types +title: Callout - Param types +weight: 100 +--- + +Hugo supports named an unnamed params. +Named are more readable. +The callout shortcode aims to support both, but **not** in the same shortcode instance. + + +## The two callouts below using **unnamed** params + +{{}} +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.** +{{}} + +## The two callouts below using **named** params +This should work exactly the same as the two callouts above + +{{}} +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.** +{{}} diff --git a/layouts/partials/callout.html b/layouts/partials/callout.html new file mode 100644 index 00000000..9cb4796f --- /dev/null +++ b/layouts/partials/callout.html @@ -0,0 +1,80 @@ +{{- /* Extract parameters with defaults and validation */ -}} +{{ $class := .class | default "" }} +{{ $title := .title | default "" }} +{{ $icon := .icon | default "" }} +{{ $inlineParam := .inline | 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 }} +{{ end }} + +{{/* Figure out inline/side and set class accordingly */}} +{{ $inline := eq $inlineParam "true" }} +{{ $sideOption := "side-callout" }} +{{ $inlineOption := "inline-callout" }} + +{{ if $inline }} + {{ $class = printf "%s %s" $class $sideOption }} +{{ else }} + {{ $class = printf "%s %s" $class $inlineOption }} +{{ end }} + + + +{{/* Old frame callout */}} +
+
+ {{ with $icon }} + + {{ end }} + {{ $title }} + {{ .content | markdownify }} +
+
+ + +{{/* Render a different block, if "loud" callouts are used */}} +{{ $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 "" }} + +{{ $isSpecialTitle := in $specialTitles $title }} +{{ if $isSpecialTitle }} + {{/* Loud callouts */}} +
+ +
+ +{{ else }} + +{{/* "Generic" mf callout */}} + +{{ $cleanTitle := strings.TrimSuffix ":" $title}} + + + +{{ end }} \ No newline at end of file diff --git a/layouts/shortcodes/before-you-begin.html b/layouts/shortcodes/before-you-begin.html index cd947956..e3c14fba 100644 --- a/layouts/shortcodes/before-you-begin.html +++ b/layouts/shortcodes/before-you-begin.html @@ -1,3 +1,8 @@ -
-
Before you begin:
{{ .Inner | markdownify }}
-
\ No newline at end of file + {{ partial "callout.html" (dict + "class" "tip" + "title" "Before you begin:" + "icon" "" + "inline" "false" + "content" .Inner +) }} +{{ warnf "'' is being deprecated. Use generic 'call-out' shortcode instead."}} \ No newline at end of file diff --git a/layouts/shortcodes/call-out.html b/layouts/shortcodes/call-out.html index 5aa0a1a9..fe0b3872 100644 --- a/layouts/shortcodes/call-out.html +++ b/layouts/shortcodes/call-out.html @@ -1,23 +1,45 @@ -{{ $class := .Get 0 }} +{{/* + +Usage: +{{}} +This callout uses the icon check-circle. **This should be an inline callout.** +{{}} + +Backwards compatibility usage: +{{}} +This callout uses the icon check-circle. **This should be an inline callout.** +{{}} + +Depends on `callout.html` partial. + +*/}} + +{{ $class := .Get 0 | default (.Get "class") | default "" }} +{{ $title := .Get 1 | default (.Get "title") | default "" }} +{{ $icon := .Get 2 | default (.Get "icon") | default "" }} + +{{/* Handle different versions of booleans */}} +{{ $inlineParam := (.Get 3) | default (.Get "inline") | default "false" | lower }} +{{- /* Validate the parameter strictly */ -}} +{{ if not (in (slice "true" "false") $inlineParam) }} + {{ warnf "The '' 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 and (not (strings.Contains $class $sideOption)) (not (strings.Contains $class $inlineOption)) }} -{{ $class = printf "%s %s" $class $sideOption }} +{{ if $inline }} + {{ $class = printf "%s %s" $class $inlineOption }} +{{ else }} + {{ $class = printf "%s %s" $class $sideOption }} {{ end }} - -
-
- - {{ with .Get 2 }} - - - {{ end }} - - {{ .Get 1 }}
- - {{ .Inner | markdownify }} -
-
\ No newline at end of file +{{ partial "callout.html" (dict + "class" $class + "title" $title + "icon" $icon + "inline" $inline + "content" .Inner +) }} \ No newline at end of file diff --git a/layouts/shortcodes/caution.html b/layouts/shortcodes/caution.html index 7aff8c24..866fba3b 100644 --- a/layouts/shortcodes/caution.html +++ b/layouts/shortcodes/caution.html @@ -1,3 +1,7 @@ -
-
Caution
{{ .Inner | markdownify }}
-
\ No newline at end of file +{{ partial "callout.html" (dict +"class" "caution call-out" +"title" "Caution" +"icon" "" +"inline" "false" +"content" .Inner +) }} \ No newline at end of file diff --git a/layouts/shortcodes/deprecated.html b/layouts/shortcodes/deprecated.html index 9fcd7204..512092d5 100644 --- a/layouts/shortcodes/deprecated.html +++ b/layouts/shortcodes/deprecated.html @@ -1,3 +1,7 @@ -
-
Deprecated
{{ .Inner | markdownify }}
-
\ No newline at end of file +{{ partial "callout.html" (dict +"class" "warning call-out" +"title" "Deprecated" +"icon" "" +"inline" "false" +"content" .Inner +) }} \ No newline at end of file diff --git a/layouts/shortcodes/important.html b/layouts/shortcodes/important.html index 55f6ade8..ee48cd7b 100644 --- a/layouts/shortcodes/important.html +++ b/layouts/shortcodes/important.html @@ -1,3 +1,7 @@ -
-
Important
{{ .Inner | markdownify }}
-
+{{ partial "callout.html" (dict +"class" "important call-out" +"title" "Important" +"icon" "" +"inline" "false" +"content" .Inner +) }} \ No newline at end of file diff --git a/layouts/shortcodes/note.html b/layouts/shortcodes/note.html index 95b0ebf2..08f1209d 100644 --- a/layouts/shortcodes/note.html +++ b/layouts/shortcodes/note.html @@ -1,3 +1,8 @@ -
-
Note:
{{ .Inner | markdownify }}
-
+{{ partial "callout.html" (dict +"class" "note" +"title" "Note:" +"icon" "" +"inline" "false" +"content" .Inner +) }} +{{ warnf "'' is being deprecated. Use generic 'call-out' shortcode instead."}} \ No newline at end of file diff --git a/layouts/shortcodes/see-also.html b/layouts/shortcodes/see-also.html index fdd71603..505f94dc 100644 --- a/layouts/shortcodes/see-also.html +++ b/layouts/shortcodes/see-also.html @@ -1,3 +1,8 @@ -
-
See Also:
{{ .Inner | markdownify }}
-
+{{ partial "callout.html" (dict +"class" "tip" +"title" "See Also:" +"icon" "" +"inline" "false" +"content" .Inner +) }} +{{ warnf "'' is being deprecated. Use generic 'call-out' shortcode instead."}} \ No newline at end of file diff --git a/layouts/shortcodes/tip.html b/layouts/shortcodes/tip.html index 93ec44b0..a0659e9d 100644 --- a/layouts/shortcodes/tip.html +++ b/layouts/shortcodes/tip.html @@ -1,3 +1,8 @@ -
-
Tip:
{{ .Inner | markdownify }}
-
+{{ partial "callout.html" (dict +"class" "tip" +"title" "Tip:" +"icon" "" +"inline" "false" +"content" .Inner +) }} +{{ warnf "'' is being deprecated. Use generic 'call-out' shortcode instead."}} \ No newline at end of file diff --git a/layouts/shortcodes/warning.html b/layouts/shortcodes/warning.html index 9e036855..ca08971f 100644 --- a/layouts/shortcodes/warning.html +++ b/layouts/shortcodes/warning.html @@ -1,3 +1,7 @@ -
-
Warning
{{ .Inner | markdownify }}
-
+{{ partial "callout.html" (dict +"class" "warning call-out" +"title" "Warning" +"icon" "" +"inline" "false" +"content" .Inner +) }} \ No newline at end of file