Indexing YAML data for a given parameter on a post

That post started as a support ticket but I managed to find what I was seeking so here it is :

I wanted to a have a static comments system for my blog, that’s a really small blog with nearly no traffic and even less comments. Using a third-party comments system is great (You should check HashOver, privacy approved ) I do not want to have Javascript on my blog. So that’s the beginning of my static-commenting journey.

  • First I wanted to link a YAML file in the data folder to the post with the same name :
    {{ with (index (substr $.File.LogicalName 0 -3)) }}
  • Then I wanted to show comments with several informations :
    • Name
    • Website
    • Date
    • Body text

The YAML file looks like this :

  - id: "#1"
    name: "First Name"
    date: "2017-02-08"
    body: "That's Markdown"
    website: ""

  - id: "#2"
    name: "Second Name"
    date: "2017-02-09"
    body: "That's **Markdown**"
    website: ""

Now the most important part : the partial file (still a WIP) :

{{ with (index (substr $.File.LogicalName 0 -3)) }}
    <div class="comments">
      <div class="comment">
        {{ range .comments }}
        <h5>{{ .id }}</h5>
        {{if .website}}<a href="{{ .website | urlize | lower }}">{{ .name }}</a>
        {{ end }}
        <p>{{ .date }}</p>
      {{ if .body }}<p>{{ .body | markdownify }}</p>{{ end }}
      <p><br /></p>
      {{ end }}
{{ end }}

Thanks to for his blog post about data files and hugo