I need to generate simple .json file for displaying couple of latest posts.
But index.json is already used by search functionality.
I can’t find any clue in docs
There are several ways to do this, I suspect:
- Create a custom output format with
baseName
to whatever (it defaults toindex
) - If this is a one-off JSON file, I suspect you would also set the URL in front matter, the output format JSON and proably also a layout for that single MD file.
Check out my theme component example: https://github.com/kaushalmodi/hugo-micro-json. It creates a micro.json at the domain root level.
This is a single dynamic JSON file, which should show latest posts
hugo v0.49
First i`ve tried use to mess around with outputFormats with no luck (i use code from @kaushalmodi answer as a guide)
config.toml
[mediaTypes."application/json"]
suffixes = ["json"]
[outputFormats.Micro]
mediaType = "application/json"
baseName = "micro"
isPlainText = true
[outputs]
home = ["HTML", "JSON", "Micro"]
http://localhost:1313/micro.json - 404
Then i`ve tried to add any possible layout:
layouts/micro.json
layouts/index.micro.json
layouts/_default/micro.json
layouts/_default/index.micro.json
{{- $micro := "test" -}}
{{- $micro | jsonify -}}
http://localhost:1313/micro.json - 404
I’m desperate, what am I doing wrong?
You would need to share a minimal site source thay anyone can clone and run hugo on. It’s difficult to tell what’s wrong.
Also, does using that micro JSON theme work for you when you follow the README instructions?
Sure, i’ve tried to follow instructions in README as well.
Ok, will try to share some source code
Just make sure that that’s a valid Hugo site i.e. anyone can run hugo
on that and reproduce the issue you see.
I have hound a problem
I have _index.md in root of content folder, and i defined outputs there. Looks like this file has higher priority then config.toml
Thanks!
That’s another reason why I push everyone to create a minimal reproducible example
Obviously! Life would be so miserable if people couldn’t override the output formats for individual pages.