Customizable name for the List shortcode

This commit is contained in:
Nuno Coração 2023-01-24 22:39:45 +00:00
parent abfbdb8a4a
commit fa19f8c4d0
2 changed files with 9 additions and 7 deletions

View file

@ -326,8 +326,9 @@ When life gives you lemons, make lemonade.
<!-- prettier-ignore-start --> <!-- prettier-ignore-start -->
| Parameter | Description | | Parameter | Description |
| --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `limit` | **Required.** the number of recent articles to display. | | `limit` | **Required.** the number of recent articles to display. |
| `title` | Optional title for the list, default is `Recent` |
| `where` | The variable to be used for the query of articles e.g. `Type` | | `where` | The variable to be used for the query of articles e.g. `Type` |
| `value` | The value that will need to match the parameter defined in `where` for the query of articles e.g. for `where` == `Type` a valid value could be `sample` | | `value` | The value that will need to match the parameter defined in `where` for the query of articles e.g. for `where` == `Type` a valid value could be `sample` |
@ -348,10 +349,10 @@ The `where` and `value` values are used in the following query `where .Site.Regu
**Example #2:** **Example #2:**
```md ```md
{{</* list limit=5 where="Type" value="sample" */>}} {{</* list title="Samples" limit=5 where="Type" value="sample" */>}}
``` ```
{{< list limit=5 where="Type" value="sample">}} {{< list title="Samples" limit=5 where="Type" value="sample">}}
<br/><br/><br/> <br/><br/><br/>

View file

@ -1,9 +1,10 @@
{{ $limit := .Get "limit" | default 1 }} {{ $limit := .Get "limit" | default 1 }}
{{ $title := .Get "title" | default (i18n "shortcode.recent_articles" | emojify) }}
{{ $parent := .Page.RelPermalink }} {{ $parent := .Page.RelPermalink }}
{{ $where := .Get "where" }} {{ $where := .Get "where" }}
{{ $value := .Get "value" }} {{ $value := .Get "value" }}
<h2 class="mt-20 text-2xl font-extrabold mb-10">{{ i18n "shortcode.recent_articles" | emojify }}</h2> <h2 class="mt-20 text-2xl font-extrabold mb-10">{{ $title }}</h2>
<section class="space-y-10 w-full mt-10 mb-10"> <section class="space-y-10 w-full mt-10 mb-10">
{{ if $where }} {{ if $where }}
{{ range ( where .Site.RegularPages $where $value | first $limit ) }} {{ range ( where .Site.RegularPages $where $value | first $limit ) }}