Need to set a specific page as JSON for API

Example: go here —

http://localhost:1313/api/

there’s a folder under layouts called api, so layouts/api/index.json (or something else?) should have the code to dynamically change what’s on the page, kinda like this:

{{ $incidents := where .Site.RegularPages "Params.section" "issue" }}
{{ $active := where $incidents "Params.resolved" "=" false }}

{{ $isNotice := where $active "Params.severity" "=" "notice" }}
{{ $isDisrupted := where $active "Params.severity" "=" "disrupted" }}
{{ $isDown := where $active "Params.severity" "=" "down" }}


{"status":
{{ if $isDown }}
  "down"}
{{ else }}
{{ if $isDisrupted }}
  "disrupted"}
{{ else }}
{{ if $isNotice }}
  "notice"}
{{ else }}
  "ok"}
{{ end }}{{ end }}{{ end }}

Essentially, it would return a JSON object based on whether or not a certain value / if statement ran.

This is really complicated and while I found this…

…it didn’t seem to help me much.

Once again, the code for what I have is here:

https://github.com/cstate/cstate/blob/v3/layouts/api/single.html

You need to add Output Formats into the mix, like the original blog post explains: https://forestry.io/blog/build-a-json-api-with-hugo/#/

I suppose you just need an extra output format on the home page.

  1. don’t want to do this for the homepage

2 how specifically? this threw an error for me