feat: add option to sort items in properties shortcode (#527)
BREAKING CHANGE: To enable sorting of elements in the `properties` shortcode, it was necessary to change the structure of the properties file. Due to this change, the `properties` object now requires a list of maps instead of a map. A [sample file](https://raw.githubusercontent.com/thegeeklab/hugo-geekdoc/main/exampleSite/data/properties/demo.yaml) can be found in the repository.
This commit is contained in:
parent
73c5f6a6b2
commit
128a55e974
3 changed files with 38 additions and 13 deletions
|
@ -1,21 +1,27 @@
|
|||
{{- $name := .Get "name" -}}
|
||||
{{- $sort := .Get "sort" -}}
|
||||
{{- $order := default "asc" (.Get "order") -}}
|
||||
|
||||
{{- if .Site.Data.properties }}
|
||||
<dl class="gdoc-props">
|
||||
{{- with (index .Site.Data.properties (split $name ".")) }}
|
||||
{{- range $key, $value := .properties }}
|
||||
{{- $properties := .properties }}
|
||||
{{- with $sort }}
|
||||
{{- $properties = (sort $properties . $order) }}
|
||||
{{- end }}
|
||||
{{- range $properties }}
|
||||
<dt class="flex flex-wrap align-center gdoc-props__meta">
|
||||
<span class="gdoc-props__title">{{ $key }}</span>
|
||||
{{- if $value.required }}
|
||||
<span class="gdoc-props__title">{{ .name }}</span>
|
||||
{{- if .required }}
|
||||
<span class="gdoc-props__tag warning">{{ i18n "propertylist_required" | lower }}</span>
|
||||
{{ else }}
|
||||
<span class="gdoc-props__tag tip">{{ i18n "propertylist_optional" | lower }}</span>
|
||||
{{- end }}
|
||||
{{- with $value.type }}
|
||||
{{- with .type }}
|
||||
<span class="gdoc-props__tag note">{{ . }}</span>
|
||||
{{- end }}
|
||||
|
||||
{{- with $value.tags }}
|
||||
{{- with .tags }}
|
||||
{{- $tags := . }}
|
||||
{{- if reflect.IsMap $tags }}
|
||||
{{- $tags = (index $tags $.Site.Language.Lang) }}
|
||||
|
@ -27,7 +33,7 @@
|
|||
</dt>
|
||||
<dd>
|
||||
<div class="gdoc-props__description">
|
||||
{{- with $value.description }}
|
||||
{{- with .description }}
|
||||
{{- $desc := . }}
|
||||
{{- if reflect.IsMap $desc }}
|
||||
{{- $desc = (index $desc $.Site.Language.Lang) }}
|
||||
|
@ -37,7 +43,7 @@
|
|||
{{ end }}
|
||||
</div>
|
||||
<div class="gdoc-props__default">
|
||||
{{- with default "none" ($value.defaultValue | string) }}
|
||||
{{- with default "none" (.defaultValue | string) }}
|
||||
<span>{{ i18n "propertylist_default" | title }}:</span>
|
||||
<span>{{ . }}</span>
|
||||
{{- end }}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue