Skip to content
Alexander Solovyov edited this page Sep 7, 2015 · 4 revisions

gostatic tries to be agnostic about structure of your site, so that you can build sites of various types, but some things are hard to implement without having any support.

Tags are one such thing. Usual way of implementing tags for your site is processing your pages with tags processor, which reads your tags from tags: a, b, c page configuration, and renders one page for each collected tag.

So you have something like this in your site's config:

TEMPLATES = main.tmpl

*.md:
    config
    tags tags/*.tag

*.tag:
    template tag

This means that each tag in your markdown file will generate a page tags/<name>.tag, which is then processed with *.tag rule. This rule renders template named tag, so your main.tmpl can have something like that:

{{define "tag"}}
# Pages tagged with {{ .Title }}

{{ with .Site.Pages.WithTag .Title }}
Total amount of pages: {{ .Len }}

  {{ range . }}
- [{{ .Title }}]({{ $.Rel .Url }})
  {{ end }}
{{ end }}
{{end}}

Here we output count of pages having such tag, and a list of them. Outputting list of tags can be done through having some tags.html page (you could draw tag cloud on your index page, of course, whatever you'd like!) of such content:

title: Tags
----
<div class="tag-list">
{{ range .Site.Pages.Children "tags/" }}
  <a href="{{ $.Rel .Url }}">{{ .Title }}</a>
{{ end }}
</div>

We're going through all the children of tags/ path (remember, all our tags sit at virtual tags/<name>.tag path?) to output a link to each of them.

You can find description of all methods and properties used here in reference.

Clone this wiki locally