Skip to content

Commit

Permalink
Add series taxonomy (#258)
Browse files Browse the repository at this point in the history
* Add series taxonomy
Thanks to @igor-baiborodine for this new feature!
  • Loading branch information
igor-baiborodine authored Oct 6, 2020
1 parent dad026f commit 553a452
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ The headings that are taken into account for a TOC are from _H2_ (##) to _H5_ (#
{{< toc >}}
```

### Series Taxonomy ###
In case you want to group some articles as a series, you have to add the `series` front matter variable to each article and set its value to the name of the series, for example, `series: "My New Super Series"`.

The page at `<site-base-url>/series/` will list all the series. To list all articles for a particular series within markdown, you can use the `series` shortcode with the series name in question, for instance:
```markdown
{{< series "My New Super Series" >}}
```

### Comments
Currently [Commento](https://commento.io/) and [Disqus](https://disqus.com) are supported.

Expand Down
1 change: 1 addition & 0 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ disqusShortname = ""
author = "author"
tag = "tags"
category = "categories"
series = "series"

[outputs]
home = [ "HTML", "JSON", "RSS" ]
Expand Down
2 changes: 2 additions & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ other = "{{.Count}} min read"
[tableOfContents]
other = "Table of Contents"

[series]
other = "Series"
30 changes: 30 additions & 0 deletions layouts/_default/series.terms.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{{ define "main" }}

<div class="content">
<div class="article-wrapper u-cf single">
<a class="bubble" href="{{ "/series/" | relLangURL}}">
<i class="fa fa-fw fa-list-alt"></i>
</a>

<article class="article">
<div class="content">
<h3>{{ i18n "series" | default "series" }}</h3>
<hr>
<ul id="all-series">
{{ range $name, $taxonomy := .Site.Taxonomies.series }}
{{ $series_name := $name }}
{{ $series_path := (printf "/series/%s" (urlize $name)) }}
{{ $series_page := site.GetPage $series_path }}

{{ if $series_page }}
{{ $series_name = $series_page.Title }}
{{ end }}

<li><a href="{{ $series_path }}">{{ $series_name }} ({{ $taxonomy.Count }})</a></li>
{{ end }}
</ul>
</div>
</article>
</div>
</div>
{{ end }}
4 changes: 4 additions & 0 deletions layouts/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
{{- $.Scratch.Add "index" (dict "url" (print "/tags/" $name | absURL) "title" ($name | humanize) "iconClass" "fa-tag" "type" "tag" "objectID" (print "/tags/" $name | absURL) ) -}}
{{- end -}}

{{- range $name, $taxonomy := .Site.Taxonomies.series -}}
{{- $.Scratch.Add "index" (dict "url" (print "/series/" $name | absURL) "title" ($name | humanize) "iconClass" "fa-list-alt" "type" "series" "objectID" (print "/series/" $name | absURL) ) -}}
{{- end -}}

{{- range where .Site.RegularPages "Type" "not in" (slice "page" "json" "status") -}}
{{- $iconClass := "" -}}
{{- if and (isset .Params "icon") (ne .Params.icon "") -}}
Expand Down
11 changes: 11 additions & 0 deletions layouts/shortcodes/series.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{ $series_name := .Get 0 | urlize }}

{{ range $key, $taxonomy := .Site.Taxonomies.series }}
{{ if eq $key $series_name }}
<ul>
{{ range $taxonomy.Pages.ByDate }}
<li hugo-nav="{{ .RelPermalink }}"><a href="{{ .Permalink }}">{{ .LinkTitle }}</a></li>
{{ end }}
</ul>
{{ end }}
{{ end }}
1 change: 1 addition & 0 deletions testing/testing-example-site/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ disqusShortname = "bilberry-hugo-theme"
author = "author"
tag = "tags"
category = "categories"
series = "series"

[outputs]
home = [ "HTML", "JSON", "RSS" ]
Expand Down

0 comments on commit 553a452

Please sign in to comment.