Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relative path social media cards break with hierarchy #392

Open
welpo opened this issue Sep 19, 2024 · 0 comments · May be fixed by #432
Open

relative path social media cards break with hierarchy #392

welpo opened this issue Sep 19, 2024 · 0 comments · May be fixed by #432
Labels
bug Something isn't working

Comments

@welpo
Copy link
Owner

welpo commented Sep 19, 2024

Since the social media card setting follows the hierarchy (docs), it tries to find the relative path from the wrong place (the child page, when it's set on the parent).

I'm guessing this can also happen for sections.

Workarounds:

  • Use an absolute path
  • Set social_media_card = "" on the child page(s)

Problematic lines:

{# Image for social media sharing #}
{%- set social_media_card = macros_settings::evaluate_setting_priority(setting="social_media_card", page=page | default(value=""), section=section | default(value=""), default_global_value="") -%}
{% if social_media_card %}
{# Try to construct the image path relative to the current page #}
{% set colocated_path = page.colocated_path | default(value="") %}
{% set file_path = colocated_path ~ social_media_card %}
{# Fetch metadata to verify image existence at the relative path #}
{%- set meta = get_image_metadata(path=file_path, allow_missing=true) -%}
{# Check if relative path exists, else try absolute path #}
{% if meta %}
{% set final_path = file_path %}
{% else %}
{# If the relative path didn't work, try fetching metadata for the absolute path #}
{% set meta = get_image_metadata(path=social_media_card, allow_missing=true) %}
{% if meta %}
{% set final_path = social_media_card %}
{% else %}
{# Throw an error if the image doesn't exist at either path #}
{{ throw(message="Could not get metadata for the specified social media card image in page " ~ page.path ~ ". Attempted relative path: '" ~ file_path ~ "' and absolute path: '" ~ social_media_card ~ "'. Ensure the file exists at one of these locations.") }}
{% endif %}
{% endif %}

Original report:

When I add social_media_card = "image.webp" to the parent page, header.html expects the child page to also have the file:

Could not get metadata for the specified social media card image in page /parent/child/. Attempted relative path: 'image.webp' and absolute path: 'image.webp'. Ensure the file exists at one of these locations.

Originally posted by @JVimes in #384 (comment)

@welpo welpo added the bug Something isn't working label Sep 19, 2024
@welpo welpo linked a pull request Nov 17, 2024 that will close this issue
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant