Adding new JSON Feed

Is there a way to add a new JSON feed for specific posts (I know the selection of posts)? I added one in my theme, but I am unable to access the generated feed. Where should this be added in the layout? And how will this be accessible.

Custom output formats | Hugo.

Thank you, Jason. I did go through this. But here are my doubts.

  • As I do not have access to the site configuration, I don’t know how the JSON output format is set up. What’s the path? Or is it permalinkable?
  • Can there be a single JSON feed for a section? Say I want different JSON feeds for each photo category, how do I set it up?

I don’t think just creating a JSON feed layout is enough to make it available at a path. Any idea how this is all set up? Especially with photos? @manton

Categories already have their own feeds automatically. And your theme configuration is your site configuration. It merges with the defaults.

Do photos in different categories also have a different JSON feed? I only know of one. I tried creating a new JSONFeed for photos in a different category (not all photos), but it isn’t rendered/accessible through any URL. I have no clue now what I am messing up.

To give you details, I created a directory cat in the layouts folder of my theme and added a new JSON feed layout there. But is not accessible at {{baseurl}}/cat/index.json. What am I missing?

Categories automatically have feeds. For example, my category Baltimore has a feed at:

If you want posts in a category feed, it’s already there. If you want all photos to be in a category and you want to make a feed of your photos, you can do so by automatically adding a category with filters on things like .jpg etc being in a post.

You don’t have to do anything with your theme to get a JSON or RSS feed that contains the posts in a category.

I understand this. So, I might be making something that’s simple a bit complicated. I will try to explain again with an example.

This is @manton’s photos feed. I want a similar, but customized version of this to only include photos from a particular category. And I want multiple such feeds for different categories. I believe I will have to add a layout in my theme to generate such a custom feed.

layouts/list.photosjson.json (likely scrolled down to the bottom because you probably don’t override this with your custom theme) is the layout for the photos feed. You can add filters for what posts are there.

The line is: {{- $list := where .Site.Pages "" "!=" nil -}} – which finds posts with photos. You just also want a filter for categories. You can do this in your own layouts that are similar and I think that’ll do it.

Can I have more than one such feed - each with different filters? And how would I access them?

I believe so, though I don’t know exactly where the URLs will be, it’ll depend on the layout path you set.