{#- data -#}
{% set type = item.section|default('page')|json_encode() %}
{% set id = item.id|json_encode(constant('JSON_UNESCAPED_SLASHES')) %}
{% set attributes = {
  'title': item.title|json_encode(constant('JSON_UNESCAPED_UNICODE')),
  'body': item.body|e('html')|json_encode(constant('JSON_UNESCAPED_UNICODE') b-or constant('JSON_UNESCAPED_SLASHES')),
  'date': item.date|date('c')|json_encode(),
  'updated': item.updated|date('c')|json_encode(),
} %}
{#- add front matter variables to attributes -#}
{% set attributes = item.fmvariables|merge(attributes) %}
{#- handle episode file -#}
{% if item.episode.file|default() %}
  {%- for key, value in item.episode -%}
    {%- if key in ['file', 'image'] -%}
      {%- set episode = attributes.episode|merge({ (key): "\"" ~ asset(value)|url({canonical: true}) ~ "\"" }) -%}
    {%- else -%}
      {%- set episode = attributes.episode|merge({ (key): value }) -%}
    {%- endif -%}
    {%- set attributes = attributes|merge({'episode': episode}) -%}
  {%- endfor -%}
{% endif %}
{#- encode attributes values to JSON -#}
{% set attributes = attributes|map((v) => v|json_encode(constant('JSON_UNESCAPED_UNICODE') b-or constant('JSON_UNESCAPED_SLASHES'))) %}
    {
      "type": {{ type }},
      "id": {{ id }}
{%- if attributes is defined %},
      "attributes": {
{%- for key, value in attributes ~%}
        "{{ key }}": {{ value }}{% if not loop.last %},{% endif %}
{% endfor ~%}
      }
{% endif %}
    }
{#- /data -#}