I have some co-located json files that I want to run load_data
on from page.html
, but I’m looking for a better way to find the json file’s paths. The structure is like this:
content
├── post1
│ ├── index.md
│ └── my_data.json
├── post2
│ ├── index.md
│ └── my_data.json
└── post3
├── index.md
└── my_data.json
Currently I’m looping through page.assets
looking for the asset with the right filename, like this:
{# find the path to my_data.json file path #}
{% for asset in page.assets %}
{% if asset is ending_with("my_data.json") %}
{% set_global my_data = load_data(path="content" ~ asset) %}
{% endif %}
{% endfor %}
But it seems like this should be a one-liner. If there was a page.relative_dir
, I could do this:
{% set_global my_data = load_data(path="content" ~ page.relative_dir ~ "my_data.json") %}
Or even better, if load_data
paths could be relative to the page if it starts with ./
:
{% set_global my_data = load_data(path="./my_data.json") %}
Or did I miss a simple way that’s already possible?