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

Merged
merged 4 commits into from
Nov 17, 2024

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.

Note:

  1. It doesn't seem possible to get them to work on pages with path set
  2. A section with a directory of images next to it won't work. That's why I moved some images from social_cards to the root of their section.

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 1f7dd70
🔍 Latest deploy log https://app.netlify.com/sites/tabi-demo/deploys/673a7577d87fd90008f6dfa0
😎 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.

@welpo welpo force-pushed the fix/social-media-card-inheritance-path branch from 52642fe to f47018c Compare November 17, 2024 22:51
@welpo welpo merged commit 39a6750 into main Nov 17, 2024
6 of 7 checks passed
@welpo welpo deleted the fix/social-media-card-inheritance-path branch November 17, 2024 23:02
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