The goal is to create a listing page with links to individual detail pages for each item in a JSON file. The detail pages should also be included in the sitemap.xml file.
The expected URL format for each detail page should be: http://localhost:1313/custom/:id/
,
where :id
is the ID of the corresponding item in the JSON file.
It’s preferable to avoid creating corresponding markdown files in the content/
directory for each item in the JSON file. [more then 20k json objects]
So far, the listing page with links to detail pages works, but the detail pages return a 404 error.
Here’s an example of the JSON file located at data/test.json
[
{
"id":1,
"title":"Custom Item 1",
"description":"This is the description for Custom Item 1."
},
{
"id":2,
"title":"Custom Item 2",
"description":"This is the description for Custom Item 2."
},
{
"id":3,
"title":"Custom Item 3",
"description":"This is the description for Custom Item 3."
}
]
Here are the relevant code snippets for the listing and detail pages:
layouts/custom/list.html
{{ range $key, $current := $data }}
<h2><a href="{{ urlize "/custom/" }}{{ $current.id }}/">{{ $current.title }}</a></h2>
<p>{{ $current.description }}</p>
{{ end }}
layouts/custom/single.html
{{- $data := getJSON "data/custom.json" -}}
{{- $current := index $data .Params.id -}}
<h2>{{ $current.title }}</h2>
<p>{{ $current.description }}</p>
I hope this helps clarify the approach!