icon: add style and color options #1068

This commit is contained in:
Sören Weber 2025-03-24 15:59:19 +01:00
parent a5b517d1aa
commit 42ccc9d636
No known key found for this signature in database
GPG Key ID: BEC6D55545451B6D
6 changed files with 35 additions and 16 deletions

View File

@ -1825,7 +1825,9 @@ html[dir='rtl'] .expand[open] > .box-label > i.expander-icon {
margin-inline-end: 3px; margin-inline-end: 3px;
} }
.list-tree i.cstyle { /* icons with style attribute */
i.cstyle {
color: var(--VARIABLE-BOX-color); color: var(--VARIABLE-BOX-color);
} }

View File

@ -14,6 +14,8 @@ weight = -6
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The new [`tree` shortcode](shortcodes/tree) displays lists as nicely formatted trees with configurable icon and icon color. - {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The new [`tree` shortcode](shortcodes/tree) displays lists as nicely formatted trees with configurable icon and icon color.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The [`icon` shortcode](shortcodes/icon) has learned the `style` and `color` options known from other shortcodes.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme [supports versioning](configuration/sitemanagement/versioning) now, where you can keep older versions of your site accessible via a version switcher at the top of the menu. - {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The theme [supports versioning](configuration/sitemanagement/versioning) now, where you can keep older versions of your site accessible via a version switcher at the top of the menu.
- {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The menu configuration for the main menu area, [introduced in 7.1.0](introduction/releasenotes/7/1), is extended to the non-scrolling menu header area between search box and main scrolling area using the `sidebarheadermenus` option and to the menu footer area using the `sidebarfootermenus` option. - {{% badge style="info" icon="plus-circle" title=" " %}}New{{% /badge %}} The menu configuration for the main menu area, [introduced in 7.1.0](introduction/releasenotes/7/1), is extended to the non-scrolling menu header area between search box and main scrolling area using the `sidebarheadermenus` option and to the menu footer area using the `sidebarfootermenus` option.

View File

@ -6,9 +6,9 @@ title = 'Icon'
The `icon` shortcode displays icons using the [Font Awesome](https://fontawesome.com) library. The `icon` shortcode displays icons using the [Font Awesome](https://fontawesome.com) library.
{{% icon exclamation-triangle %}}
{{% icon angle-double-up %}}
{{% icon skull-crossbones %}} {{% icon skull-crossbones %}}
{{% icon style="warning" %}}
{{% icon icon="angle-double-up" color="blue" %}}
## Usage ## Usage
@ -16,18 +16,18 @@ The `icon` shortcode displays icons using the [Font Awesome](https://fontawesome
{{% tab title="shortcode" %}} {{% tab title="shortcode" %}}
````go ````go
{{%/* icon icon="exclamation-triangle" */%}}
{{%/* icon icon="angle-double-up" */%}}
{{%/* icon icon="skull-crossbones" */%}} {{%/* icon icon="skull-crossbones" */%}}
{{%/* icon style="warning" */%}}
{{%/* icon icon="angle-double-up" color="blue" */%}}
```` ````
{{% /tab %}} {{% /tab %}}
{{% tab title="shortcode (positional)" %}} {{% tab title="shortcode (positional)" %}}
````go ````go
{{%/* icon skull-crossbones */%}}
{{%/* icon exclamation-triangle */%}} {{%/* icon exclamation-triangle */%}}
{{%/* icon angle-double-up */%}} {{%/* icon angle-double-up */%}}
{{%/* icon skull-crossbones */%}}
```` ````
{{% /tab %}} {{% /tab %}}
@ -36,15 +36,16 @@ The `icon` shortcode displays icons using the [Font Awesome](https://fontawesome
````go ````go
{{ partial "shortcodes/icon.html" (dict {{ partial "shortcodes/icon.html" (dict
"page" . "page" .
"icon" "exclamation-triangle" "icon" "skull-crossbones"
)}}
{{ partial "shortcodes/icon.html" (dict
"page" .
"style" "warning"
)}} )}}
{{ partial "shortcodes/icon.html" (dict {{ partial "shortcodes/icon.html" (dict
"page" . "page" .
"icon" "angle-double-up" "icon" "angle-double-up"
)}} "color" "blue"
{{ partial "shortcodes/icon.html" (dict
"page" .
"icon" "skull-crossbones"
)}} )}}
```` ````
@ -56,6 +57,8 @@ The `icon` shortcode displays icons using the [Font Awesome](https://fontawesome
| Name | Position | Default | Notes | | Name | Position | Default | Notes |
|-----------------------|----------|-----------------|-------------| |-----------------------|----------|-----------------|-------------|
| **icon** | 1 | _<empty>_ | [Font Awesome icon name](#finding-an-icon) to be displayed. It will be displayed in the text color of its according context. | | **icon** | 1 | _<empty>_ | [Font Awesome icon name](#finding-an-icon) to be displayed. It will be displayed in the text color of its according context. |
| **style** | | _&lt;empty&gt;_ | The style scheme used for the icon.<br><br>- by severity: `caution`, `important`, `info`, `note`, `tip`, `warning`<br>- by brand color: `primary`, `secondary`, `accent`<br>- by color: `blue`, `cyan`, `green`, `grey`, `magenta`, `orange`, `red`<br>- by special color: `default`, `transparent`, `code`<br><br>You can also [define your own styles](shortcodes/notice#defining-own-styles). |
| **color** | | _&lt;empty&gt;_ | The [CSS color value](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value) to be used. If not set, the chosen color depends on the **style**. Any given value will overwrite the default.<br><br>- for severity styles: a nice matching color for the severity<br>- for all other styles: the corresponding color<br><br> |
### Finding an icon ### Finding an icon
@ -63,7 +66,7 @@ Browse through the available icons in the [Font Awesome Gallery](https://fontawe
Once on the Font Awesome page for a specific icon, for example the page for the [heart](https://fontawesome.com/v6/icons/heart?s=solid), copy the icon name and paste into the Markdown content. Once on the Font Awesome page for a specific icon, for example the page for the [heart](https://fontawesome.com/v6/icons/heart?s=solid), copy the icon name and paste into the Markdown content.
### Customising Icons ### Customizing Icons
Font Awesome provides many ways to modify the icon Font Awesome provides many ways to modify the icon
@ -84,6 +87,14 @@ Built with {{%/* icon heart */%}} by Relearn and Hugo
Built with {{% icon heart %}} by Relearn and Hugo Built with {{% icon heart %}} by Relearn and Hugo
### With color
````go
Built with {{%/* icon icon="heart" style="red" */%}} by Relearn and Hugo
````
Built with {{% icon icon="heart" style="red" %}} by Relearn and Hugo
### Advanced HTML Usage ### Advanced HTML Usage
While the shortcode simplifies using standard icons, the icon customization and other advanced features of the Font Awesome library require you to use HTML directly. Paste the `<i>` HTML into markup, and Font Awesome will load the relevant icon. While the shortcode simplifies using standard icons, the icon customization and other advanced features of the Font Awesome library require you to use HTML directly. Paste the `<i>` HTML into markup, and Font Awesome will load the relevant icon.

View File

@ -4,13 +4,15 @@
{{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }} {{- $filepath := "[virtual file]" }}{{ with and $page $page.File $page.File.Filename }}{{ $filepath = . }}{{ end }}
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'icon' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/5/#5-18-0" $filepath }} {{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'icon' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/introduction/releasenotes/5/#5-18-0" $filepath }}
{{- end }} {{- end }}
{{- $icon := .icon | default "" }} {{- $color := .color | default "" }}
{{- $icon = trim $icon " " }} {{- $style := .style | default "" }}
{{- $boxStyle := partial "_relearn/boxStyle.gotmpl" (dict "style" $style "icon" .icon) }}
{{- $icon := trim ($boxStyle.icon) " " }}
{{- if and $icon (not (findRE ".*?\\bfa-\\w.*?" $icon)) }} {{- if and $icon (not (findRE ".*?\\bfa-\\w.*?" $icon)) }}
{{- $icon = printf "fa-fw fas fa-%s" $icon }} {{- $icon = printf "fa-fw fas fa-%s" $icon }}
{{- end }} {{- end }}
{{- with $page }} {{- with $page }}
{{- if $icon -}} {{- if $icon -}}
<i class="{{ $icon }}"></i> <i class="{{ $icon }}{{ if $style }} cstyle {{ $style }}{{ end }}"{{ if $color }} style="color: {{ $color }};"{{ end }}></i>
{{- end }} {{- end }}
{{- end }} {{- end }}

View File

@ -1 +1 @@
7.5.0+64c314c65460adb4477a7001dae028ccc241bcc2 7.5.0+a5b517d1aadb9c5feb6e5fed9f848527763e35e7

View File

@ -2,4 +2,6 @@
{{- partial "shortcodes/icon.html" (dict {{- partial "shortcodes/icon.html" (dict
"page" .Page "page" .Page
"icon" (.Get "icon" | default (.Get 0)) "icon" (.Get "icon" | default (.Get 0))
"style" (.Get "style" )
"color" (.Get "color" )
) }} ) }}