diff options
author | Chen Xianmin <xianmin12@gmail.com> | 2018-05-24 11:11:07 +0300 |
---|---|---|
committer | Chen Xianmin <xianmin12@gmail.com> | 2018-05-24 11:11:07 +0300 |
commit | ad5b5e0583ea304474580f7c07b51d6d849ff1aa (patch) | |
tree | 80cf96b2d44d468e9b2539ba385f1914c921a5dc | |
parent | 18eee9b5606726b92b12a6738d468441eb9e0d74 (diff) |
feat: support series shortcode (#62)
-rw-r--r-- | layouts/shortcodes/series.html | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/layouts/shortcodes/series.html b/layouts/shortcodes/series.html new file mode 100644 index 0000000..d1235b6 --- /dev/null +++ b/layouts/shortcodes/series.html @@ -0,0 +1,50 @@ +<!-- Usage: https://github.com/xianmin/hugo-theme-jane/issues/62 --> + +<!-- reset scratch variables at the start --> +{{ $.Scratch.Set "seriesName" false }} +{{ $.Scratch.Set "tagName" false }} +{{ $.Scratch.Set "categoryName" false }} + +{{ if .IsNamedParams }} + {{ $.Scratch.Set "tagName" (.Get "tag") }} + {{ $.Scratch.Set "categoryName" (.Get "category") }} +{{ else }} + <!-- get series --> + {{ $.Scratch.Set "seriesName" (.Get 0) }} +{{ end }} + +<ul> + {{ with $.Scratch.Get "seriesName" }} + <!-- default series list --> + {{ range $name, $taxonomy := $.Site.Taxonomies.series }} + {{ if eq $name ($.Scratch.Get "seriesName") }} + {{ range $taxonomy.Pages.Reverse }} + <li><a href="{{ .Permalink }}">{{ .Title }}</a></li> + {{ end }} + {{ end }} + {{ end }} + {{ else }} + <!-- else set tag or cotegory --> + {{ with $.Scratch.Get "tagName" }} + <!-- tag list --> + {{ range $name, $taxonomy := $.Site.Taxonomies.tags }} + {{ if eq $name ($.Scratch.Get "tagName") }} + {{ range $taxonomy.Pages.Reverse }} + <li><a href="{{ .Permalink }}">{{ .Title }}</a></li> + {{ end }} + {{ end }} + {{ end }} + {{ end }} + + {{ with $.Scratch.Get "categoryName" }} + <!-- category list --> + {{ range $name, $taxonomy := $.Site.Taxonomies.categories }} + {{ if eq $name ($.Scratch.Get "categoryName") }} + {{ range $taxonomy.Pages.Reverse }} + <li><a href="{{ .Permalink }}">{{ .Title }}</a></li> + {{ end }} + {{ end }} + {{ end }} + {{ end }} + {{ end }} +</ul> |