veilid-dot-com/themes/veilid/layouts/partials/data.json.twig
2023-08-15 15:25:21 -04:00

25 lines
1006 B
Twig

{#- 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) %}
{#- 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 -#}