Paginated tags do not work with JSON output format

Hello,

I want to to create one JSON per tag per page. So for example:

/tags/<tag>/page/1/index.json
/tags/<tag>/page/2/index.json

The respective json then returns the meta-data of the posts having that tag.

For pagination of the tags, I created the following in theme/test-theme/layouts/tags/:

list.html
list.json
term.json

Unfortunately, that does not fully work as my theme just creates a /tags/<tag>/index.json, but no paginated ones. On the other hand, it creates the respective HTML files /tags/<tag>/page/1/index.html.

I do not know if there is maybe a general limitation of Hugo I am facing or if I am missing something.

I created a minimum example here: GitHub - Sapp00/hugo-paginated-tags.json

Thank you and best regards!

As written, the title of this topic is not true.

Try it:

git clone --single-branch -b hugo-forum-topic-55181 https://github.com/jmooring/hugo-testing hugo-forum-topic-55181
cd hugo-forum-topic-55181
hugo server

I haven’t read through all of your code, nor do I want to, but I can tell you with certainty that this will never work as intended:

{{- $currentPath := .RelPermalink -}}
{{- $pageNum := 1 -}}

{{/* Extract page number from URL if it exists */}}
{{- if strings.Contains $currentPath "/page/" -}}
  {{- $pathParts := split $currentPath "/" -}}
  {{- range $i, $part := $pathParts -}}
    {{- if eq $part "page" -}}
      {{- $pageNum = index $pathParts (add $i 1) | int -}}
    {{- end -}}
  {{- end -}}
{{- end -}}

Why? Because the values returned by the Permalink and RelPermalink methods do not incude the pager number. See https://github.com/gohugoio/hugo/issues/4507.