I’m working on making a JSON rest-like api with static files and I have added pagination like:
{{ $p := .Paginate .Pages.ByDate.Reverse }}
when I run hugo I see the pages folder generated but it starts at 2 and the page 1 json is outside that name by its type .json. I can’t seem to find why its not being consistent with a folder for page 1 as well. Am I missing something in the settings?
I would expect that this way if your “API endpoint” is a .md file and not a list page. I would also assume, that Hugo somehow has redirect included for people trying to load /path/to/something/1 one level up.
That is the output I am seeing, page one is outside the page directory on its own and its the first list page. I do not get a redirect generated, probably because its json output only. Its not that this is bad for the first page, I guess I was thinking it would be nice if it could also have the /page/1/something.json for consistency. If there is no option to cause the /page/1 folder to be generated then I’ll work around it or possibly set up a redirect. There is not too much going on in the list template so far:
Depending on your hoster you could “proxy” the URL. On Netlify it would be something like this in the _redirects file in your site root:
/path/to/something/1 /path/to/something 200
The 200 will result in the browser still showing the /1 subdirectory. That will work only on Netlify though… Other server types or hosting services might have another way.
Hugo already does the above at least for HTML Output, not sure about JSON, but you can try.
For example in the demo of the Ananke theme if a user types: https://gohugo-ananke-theme-demo.netlify.app/post/page/1/
they will be redirected to https://gohugo-ananke-theme-demo.netlify.app/post/