Add data to page

I want to add comments to my post. (Don’t worry how I’ll manage this with a static site; its possible.)

They should be stored in a comments.json file for each post. I’m aware of the global data/ directory.
However, I will need to access it with the page variable. I know that if . is a Page then .Data exists, that’s written in the documentation. However, I don’t know how to put something there. Should it be stored in

  • content/posts/mypost/comments.json
  • content/posts/mypost/data/comments.json
  • data/posts/mypost/comments.json

or is perhaps the Page.Data variable something entirely different?

I appreciate any help.

The Page.Data isn’t the page data like .Site.Data.

You could treat the comments as resources.

Let’s say there is a foo post.

tree content/foo 
content/foo
├── comments
│   ├── bar.json
│   └── foo.json
└── index.md

The comment format looks like:

{
    "content": "bar"
}

Then read and output comments in your template.

{{ range .Resources.Match "comments/*" }}
  {{ $comment := . | transform.Unmarshal }}
  {{ $comment.content }}
{{ end }}

Thanks I will look into that!