I successfully created a JSON output format with a specific JSON template in layout/_default/single.json. So far so good, I see the corresponding output index.json lying next to my index.html in my dist folder (super neat feature THANKS !!!).
I wish I could access this file at: http://mydomain.com/about.json
instead of (working now) : http://mydomain.com/about/index.json
If I am correct, I should have the .json file named about.json for it to work, right ? How would I do that using Hugo ?
Define your own JSON output format with a different baseName value (default = index)
I’ll try this one, but I think I’ll end up with http://mydomain.com/about/about.json which is not quite what I want. The thing is that my use case may be somewhat complicated after thoughts: to get what I want I may have to deal with the static folder to shortcut the fact that Hugo creates /about/index.html and not /about.html (even if I can make create about.json it will end up within the /about/ sub-directory).
Set uglyURLs=true
Not for me: I need to keep pretty URLs for html files.
You can also maybe test setting url in front matter, but not sure how that would behave
Not sure I understood where to put the url ? If in the frontmatter of my content file, I wonder if this will not only move the .json but also the .html so… I’ll try anyway.
Late reply: got no luck with any of these solutions No big deal, I’ll stay with normal behavior for now. If that becomes a problem I may just create a post-build script to copy files into static. Thanks for the help anyway
In a bind, I’d use a redirect. Depending on your webserver, you might even be able to use regex matching for *.json requests, and redirect them to their appropriate, default path.
That first sentence wasn’t a pun, but it would make a good one!
I am sure you could arrange to have that file auto-filled by ranging over content that produces the custom output, but… that isn’t really the point here. This was a shortcut if you needed it for only a few redirects.
I haven’t actually tried to fix your issue in a “proper” way, and doubt I’ll be able to. But someone will figure it out, or create an issue asking for a fix.
Yeah no prob, that was a mere visual necessity: I can live with it for now.
I’d rather find a more idiomatic way than using my hosting tricks as well.
The easy move would be to have a post-build script looking for all *.json files and move them at the root of the dist folder. I am sure Go would do that in a breeze, but after looking for a proper pre/post build workflow here I found most devs end up using Gulp + Js to handle such things. So I might simply use node.js built-in fs package to move files around.
I think my web server is configured to disallow AJAX requests for .json files even if it’s on the same domain. I got around this by creating a custom output type with a .js extension instead. I know this is kinda hacky, but I do not have control over my web server to make any administrative changes.
You can use a content file with a url parameter to indicate where you would like your about.json file to be output.