matt-dray / rostrum-blog

:memo::bug: Blog: superseded source code for rostrum.blog
Other
6 stars 3 forks source link

Add tags and categories to posts #25

Closed matt-dray closed 5 years ago

matt-dray commented 5 years ago

Bullet called 'Display categories and tags in a post if provided in its YAML' in the Creating Websites with RMarkdown book: https://bookdown.org/yihui/blogdown/templates.html#how-to

~Possibly have a standalone page with the tags/categories listed.~ Clicking a link in the example below takes you to a page listing all the posts that share that category/tag.

Related to #14 I reckon.

matt-dray commented 5 years ago
Screen Shot 2019-09-04 at 21 54 00

Outcome when the following is added to themes/hugo-lithium-theme/layouts/_default/single.html

<div class="article-meta">
  <p class="terms">
    {{ range $i := (slice "categories" "tags") }}
    {{ with ($.Param $i) }}
    {{ $i | title }}:
    {{ range $k := . }}
    <a href='{{ relURL (print "/" $i "/" $k | urlize) }}'>{{$k}}</a>
    {{ end }}
    {{ end }}
    {{ end }}
  </p>
</div>
matt-dray commented 5 years ago
Screen Shot 2019-09-04 at 22 16 18

Results from:

    {{ if eq .Section "post" }}
    <span class="article-date">
      {{ .Params.author }} / {{ .Date.Format "02 Jan 2006" }} / {{ .ReadingTime }} min read <br>
        {{ range $i := (slice "categories" "tags") }}
        {{ with ($.Param $i) }}
        {{ $i | title }}:
        {{ range $k := . }}
        <a href='{{ relURL (print "/" $i "/" $k | urlize) }}'>{{$k}}</a>
        {{ end }}
        {{ end }}
        {{ end }}
    </span>

    {{ end }}
matt-dray commented 5 years ago
Screen Shot 2019-09-04 at 22 24 45

Pretty sure that'll do.

    {{ if eq .Section "post" }}
    <span class="article-date">
      {{ .Params.author }} / {{ .Date.Format "02 Jan 2006" }} / {{ .ReadingTime }} min read <br>
        {{ range $i := (slice "categories" "tags") }}
        {{ with ($.Param $i) }}
        {{ $i | title }}:
        {{ range $k := . }}
        <a href='{{ relURL (print "/" $i "/" $k | urlize) }}'>{{ $k }}</a>
        {{ end }}<br>
        {{ end }}
        {{ end }}
    </span>