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

🐛 fix: support relative paths in inherited social media card #432

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

welpo
Copy link
Owner

@welpo welpo commented Nov 17, 2024

Summary

Fix path resolution for social media card images when the setting is inherited from a parent page. Previously, when a child page inherited social_media_card from its parent, the template would only look for the image in the child's directory, causing an error. Now it properly checks the parent directory as well.

Related issue

Fixes #392

Changes

  • Moved the social media images code to a file (templates/partials/social_media_images.html), to keep it maintainable
    Modified the logic to:
  • Try finding the image in the current page directory (maintaining backward compatibility)
  • If not found, try the parent directory
  • Finally, try as an absolute path
  • Improved error messages to show all attempted paths

The template will now correctly find images when social_media_card is inherited from parent pages or sections.

Type of change

  • Bug fix (fixes an issue without altering functionality)
  • New feature (adds non-breaking functionality)
  • Breaking change (alters existing functionality)
  • UI/UX improvement (enhances user interface without altering functionality)
  • Refactor (improves code quality without altering functionality)
  • Documentation update
  • Other (please describe below)

Checklist

  • I have verified the accessibility of my changes
  • I have tested all possible scenarios for this change
  • I have updated theme.toml with a sane default for the feature
  • I have made corresponding changes to the documentation:
    • Updated config.toml comments
    • Updated theme.toml comments
    • Updated "Mastering tabi" post in English
    • Updated "Mastering tabi" post in Spanish
    • Updated "Mastering tabi" post in Catalan

When a page inherits social_media_card from its parent, look for the image
in the parent directory before trying the current page path. This fixes
the incorrect path resolution when social_media_card is set on a parent
page.

The template now tries paths in this order:
1. Current page directory
2. Parent directory
3. Absolute path
@welpo welpo added the bug Something isn't working label Nov 17, 2024
Copy link

netlify bot commented Nov 17, 2024

Deploy Preview for tabi-demo ready!

Name Link
🔨 Latest commit 2025b6a
🔍 Latest deploy log https://app.netlify.com/sites/tabi-demo/deploys/673940a38386a00008d258b0
😎 Deploy Preview https://deploy-preview-432--tabi-demo.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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 this pull request may close these issues.

relative path social media cards break with hierarchy
1 participant