feat(remote_text shortcode): support relative paths

Requested in #397.
This commit is contained in:
welpo 2024-09-22 14:29:41 +02:00
parent 9101b6d6cb
commit 794bf11974
No known key found for this signature in database
GPG key ID: A2F978CF4EC1F5A6
4 changed files with 14 additions and 7 deletions

View file

@ -2,6 +2,13 @@
{%- if src is starting_with("http") -%}
{%- set response = load_data(url=src, format="plain") -%}
{%- else -%}
{%- set response = load_data(path=src, format="plain") -%}
{#- Try to load the file from a relative path -#}
{%- set colocated_path = page.colocated_path | default(value="") -%}
{%- set relative_path = colocated_path ~ src -%}
{%- set response = load_data(path=relative_path, format="plain", required=false) -%}
{#- If relative path fails, try absolute path -#}
{%- if not response -%}
{%- set response = load_data(path=src, format="plain") -%}
{%- endif -%}
{%- endif -%}
{{- response | trim_end | safe -}}