diff options
author | Jhaura Wachsman <jhaurawachsman@gmail.com> | 2020-04-19 00:36:30 +0300 |
---|---|---|
committer | Jhaura Wachsman <jhaurawachsman@gmail.com> | 2020-04-19 00:36:30 +0300 |
commit | 294942dbedb380362880611a05563a050455119b (patch) | |
tree | 9ebd36703d95ea5e206152ddaf79124dd2f11adc /layouts | |
parent | bd600d8e397a4c22cbbd3a9ac954737f1e914bdd (diff) |
Refactor to Partial, improve defaults
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/partials/recent-pages.html | 15 | ||||
-rw-r--r-- | layouts/shortcodes/recent-pages.html | 16 |
2 files changed, 21 insertions, 10 deletions
diff --git a/layouts/partials/recent-pages.html b/layouts/partials/recent-pages.html new file mode 100644 index 0000000..11b3c68 --- /dev/null +++ b/layouts/partials/recent-pages.html @@ -0,0 +1,15 @@ +{{- $limit := .limit | default 7 -}} +{{- $sections := "" -}} +{{- with .sections }} +{{- $sections = split . "," -}} +{{- end }} +{{- $sections = $sections | default $.Site.Params.mainSections | default (slice "post" "posts") -}} +{{- $class := .class | default "mt-8" -}} +{{- $style := .style -}} + +{{- $pages := first $limit (where $.Site.RegularPages "Type" "in" $sections) -}} +{{- range $pages }} +<div class="{{ $class }}"{{ with $style }} style="{{ . | safeCSS }}"{{ end }}> + {{ .Render "summary" }} +</div> +{{- end }} diff --git a/layouts/shortcodes/recent-pages.html b/layouts/shortcodes/recent-pages.html index 918e7a6..61cbb06 100644 --- a/layouts/shortcodes/recent-pages.html +++ b/layouts/shortcodes/recent-pages.html @@ -1,20 +1,16 @@ {{- $limit := "" -}} +{{- $sections := "" -}} {{- $class := "" -}} {{- $style := "" -}} {{- if .IsNamedParams }} {{- $limit = .Get "limit" -}} +{{- $sections = .Get "sections" -}} {{- $class = .Get "class" -}} {{- $style = .Get "style" -}} {{- else }} {{- $limit = .Get 0 -}} -{{- $class = .Get 1 -}} -{{- $style = .Get 2 -}} -{{- end }} -{{- $limit = $limit | default 7 -}} -{{- $class = $class | default "mt-8" -}} -{{- $pages := first $limit (where .Site.RegularPages "Type" "in" .Site.Params.mainSections) -}} -{{- range $pages}} -<div class="{{ $class }}"{{ with $style }} style="{{ . | safeCSS }}"{{ end }}> - {{ .Render "summary" }} -</div> +{{- $sections = .Get 1 -}} +{{- $class = .Get 2 -}} +{{- $style = .Get 3 -}} {{- end }} +{{- partial "recent-pages" (dict "Site" $.Site "Page" . "limit" $limit "sections" $sections "class" $class "style" $style) -}} |