-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resources: new shortcode to deprecate attachments shortcode #22
- Loading branch information
Showing
17 changed files
with
197 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
+++ | ||
descrption = "Th' Attachments shorrrtcode displays a list o' files attached t' a plank" | ||
hidden = "true" | ||
title = "Attachments" | ||
+++ | ||
{{% attachments /%}} | ||
{{% attachments sort="asc" /%}} | ||
|
||
{{< piratify >}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Nothing to see here :-( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Harrr, me found a trrreasure!!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Nothing to see here :-( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Harrr, me found a trrreasure!!! |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
+++ | ||
description = "List resources contained in a page bundle" | ||
title = "Resources" | ||
[[resources]] | ||
name = 'MaybeTreasure.txt' | ||
src = 'MaybeTreasure.en.txt' | ||
+++ | ||
|
||
The `resources` shortcode displays the [titles](https://gohugo.io/methods/resource/title/) of resources contained in a [page bundle](https://gohugo.io/content-management/page-bundles/). | ||
|
||
{{% resources sort="asc" /%}} | ||
|
||
## Usage | ||
|
||
While the examples are using shortcodes with named parameter you are free to also call this shortcode from your own partials. | ||
|
||
{{< tabs groupid="shortcode-parameter">}} | ||
{{% tab title="shortcode" %}} | ||
|
||
````go | ||
{{%/* resources sort="asc" /*/%}} | ||
```` | ||
|
||
{{% /tab %}} | ||
{{% tab title="partial" %}} | ||
|
||
````go | ||
{{ partial "shortcodes/resources.html" (dict | ||
"page" . | ||
"sort" "asc" | ||
)}} | ||
```` | ||
|
||
{{% /tab %}} | ||
{{< /tabs >}} | ||
|
||
Multilanguage features are not supported directly by the shortcode but rely on Hugo's handling for resource translations applied when the theme iterates over all available resources. | ||
|
||
### Parameter | ||
|
||
| Name | Default | Notes | | ||
|-------------|-----------------|-------------| | ||
| **style** | `transparent` | The style scheme used for the box.<br><br>- by severity: `info`, `note`, `tip`, `warning`<br>- by brand color: `primary`, `secondary`, `accent`<br>- by color: `blue`, `green`, `grey`, `orange`, `red`<br>- by special color: `default`, `transparent`, `code` | | ||
| **color** | see notes | 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 | | ||
| **title** | see notes | Arbitrary text for the box title. Depending on the **style** there may be a default title. Any given value will overwrite the default.<br><br>- for severity styles: the matching title for the severity<br>- for all other styles: `Resources`<br><br>If you want no title for a severity style, you have to set this parameter to `" "` (a non empty string filled with spaces) | | ||
| **icon** | see notes | [Font Awesome icon name](shortcodes/icon#finding-an-icon) set to the left of the title. Depending on the **style** there may be a default icon. Any given value will overwrite the default.<br><br>- for severity styles: a nice matching icon for the severity<br>- for all other styles: `paperclip`<br><br>If you want no icon, you have to set this parameter to `" "` (a non empty d with spaces) | | ||
| **sort** | `asc` | Sorting the output in `asc`ending or `desc`ending order. | | ||
| **pattern** | `.*` | A [regular expressions](https://en.wikipedia.org/wiki/Regular_expression), used to filter the resources [by name](https://gohugo.io/methods/resource/name/). For example:<br><br>- to match a file suffix of 'jpg', use `.*\.jpg` (not `*.\.jpg`)<br>- to match file names ending in `jpg` or `png`, use `.*\.(jpg\|png)` | | ||
|
||
## Examples | ||
|
||
### Custom Title, List of Resources Ending in png, jpg or gif | ||
|
||
````go | ||
{{%/* resources title="Related **files**" pattern=".*\.(png|jpg|gif)" /*/%}} | ||
```` | ||
|
||
{{% resources title="Related **files**" pattern=".*\.(png|jpg|gif)" /%}} | ||
|
||
### Info Styled Box, Descending Sort Order | ||
|
||
````go | ||
{{%/* resources style="info" sort="desc" /*/%}} | ||
```` | ||
|
||
{{% resources style="info" sort="desc" /%}} | ||
|
||
### With User-Defined Color and Font Awesome Brand Icon | ||
|
||
````go | ||
{{%/* resources color="fuchsia" icon="fab fa-hackerrank" /*/%}} | ||
```` | ||
|
||
{{% resources color="fuchsia" icon="fab fa-hackerrank" /%}} | ||
|
||
### Style, Color, Title and Icons | ||
|
||
For further examples for **style**, **color**, **title** and **icon**, see the [`notice` shortcode](shortcodes/notice) documentation. The parameter are working the same way for both shortcodes, besides having different defaults. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
+++ | ||
descrption = "List Rrresources shorrrtcode contained in a plank bundle" | ||
title = "Resources" | ||
[[resources]] | ||
name = 'MaybeTreasure.txt' | ||
src = 'MaybeTreasure.pir.txt' | ||
+++ | ||
{{% resources /%}} | ||
|
||
{{< piratify >}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{{- $page := .page }} | ||
{{- if and (not $page) .context }} | ||
{{- $page = .context }} | ||
{{- warnf "%q: DEPRECATED parameter 'context' for shortcode 'resources' found, use 'page' instead; see https://mcshelby.github.io/hugo-theme-relearn/basics/migration#5180" $page.File.Filename }} | ||
{{- end }} | ||
{{- $color := .color | default "" }} | ||
{{- $content := .content }} | ||
{{- $style := .style | default "default" }} | ||
{{- if and (not $color) (eq (len $color) 0) }} | ||
{{- $style = .style | default "transparent" }} | ||
{{- end }} | ||
{{- $title := .title }} | ||
{{- if not $title }} | ||
{{- if eq $style "info" }}{{ $title = $style | T }}{{ end }} | ||
{{- if eq $style "warning" }}{{ $title = $style | T }}{{ end }} | ||
{{- if eq $style "note" }}{{ $title = $style | T }}{{ end }} | ||
{{- if eq $style "tip" }}{{ $title = $style | T }}{{ end }} | ||
{{- end }} | ||
{{- $title = trim ($title | default ("Attachments-label" | T)) " " }} | ||
{{- $icon := .icon | default "" }} | ||
{{- if and (not $icon) (eq (len $icon) 0) }} | ||
{{- $icon = "paperclip" }} | ||
{{- if eq $style "info" }}{{ $icon = default "info-circle" }}{{ end }} | ||
{{- if eq $style "warning" }}{{ $icon = default "exclamation-triangle" }}{{ end }} | ||
{{- if eq $style "note" }}{{ $icon = default "exclamation-circle" }}{{ end }} | ||
{{- if eq $style "tip" }}{{ $icon = default "lightbulb" }}{{ end }} | ||
{{- end }} | ||
{{- $icon = trim $icon " " }} | ||
{{- if and $icon (not (findRE ".*?\\bfa-\\w.*?" $icon)) }} | ||
{{- $icon = printf "fa-fw fas fa-%s" $icon }} | ||
{{- end }} | ||
{{- $sort := .sort | default "asc" }} | ||
{{- $pattern := .pattern | default "" }} | ||
{{- with $page }} | ||
{{- if eq .BundleType "" }} | ||
{{- warnf "%q: UNSUPPORTED usage of 'resources' shortcode found, use a page bundle instead" $page.File.Filename }} | ||
{{- end }} | ||
<div class="box attachments cstyle {{ $style }}"{{ if $color }} style="--VARIABLE-BOX-color: {{ $color }};"{{ end }}> | ||
<div class="box-label">{{ if $icon }}<i class="{{ $icon }}"></i>{{ end }}{{ if and $icon $title }} {{ end }}{{ $title | .RenderString }}</div> | ||
<ul class="box-content attachments-files"> | ||
{{- range sort .Resources "Name" $sort }} | ||
{{- if findRE $pattern .Name }} | ||
{{- $size := len .Content }} | ||
{{- $unit := "Byte-symbol" }} | ||
{{- if ge $size 1024 }} | ||
{{- $size = div $size 1024 }} | ||
{{- $unit = "Kilobyte-symbol" }} | ||
{{- end }} | ||
{{- if ge $size 1024 }} | ||
{{- $size = div $size 1024 }} | ||
{{- $unit = "Megabyte-symbol" }} | ||
{{- end }} | ||
{{- $unitsymbol := $unit | T }} | ||
<li><a href="{{ .RelPermalink }}">{{.Name}}</a> ({{$size}} {{$unitsymbol}})</li> | ||
{{- end }} | ||
{{- end }} | ||
</ul> | ||
{{- $content }} | ||
</div> | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{- $_hugo_config := `{ "version": 1 }` }} | ||
{{- partial "shortcodes/resources.html" (dict | ||
"page" .Page | ||
"color" (.Get "color") | ||
"content" .Inner | ||
"icon" (.Get "icon") | ||
"pattern" (.Get "pattern") | ||
"style" (.Get "style") | ||
"sort" (.Get "sort") | ||
"title" (.Get "title") | ||
) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters