-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby-remark-images): add option to use alt text as caption fallback #14379
feat(gatsby-remark-images): add option to use alt text as caption fallback #14379
Conversation
149b43e
to
99dcca4
Compare
Thanks @chasemccoy! Thinking aloud, here's an alternative approach (maybe this is a terrible idea though?) - instead of creating a new option, we could override the existing
This is similar to how the
What are your thoughts @DSchau and @chasemccoy? |
@m-allanson Hmm, I like that idea quite a lot! Question: would passing |
@m-allanson Okay, I just pushed up my first stab at this behavior. I wrote some new tests as well to make sure everything works as expected, and I updated the README to reflect this new behavior. My implementation assumes that |
51df8b8
to
72091fe
Compare
72091fe
to
f016b4c
Compare
There is a linter failure in the switch block, could you fix it please? Otherwise looking good. CC @m-allanson |
@freiksenet Okay, it should be fixed now! Thanks! |
@m-allanson @freiksenet Could y'all give a 👍 on this if it's ready? Would love to get this published so that my team can use it 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! I added another test and fixed a small that it doesn't fallback to alt when title is the only attribute specified & can't be found.
Holy buckets, @chasemccoy — we just merged your PR to Gatsby! 💪💜 Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! |
Thanks @chasemccoy! 🎉 |
Thank you all so much! |
Published in |
…lback (gatsbyjs#14379) Add an array of node fields to the showCaption option to give more flexibility over the image caption.
…lback (gatsbyjs#14379) Add an array of node fields to the showCaption option to give more flexibility over the image caption.
gatsby-remark-images
has a wonderful option to show captions under images using thetitle
attribute, or thealt
attribute if notitle
is provided. This causes us some issues, because we have a lot of images that we don't want captions for, but we do want to provide alt text (for accessibility reasons).This PR adds a new configuration option to thegatsby-remark-images
plugin:fallbackToAltTextForCaptions
- (defaults totrue
) IfshowCaptions
is set totrue
and the title attribute is empty, this specifies whether the alt attribute should be used as a caption. If true it will be used, and if false the caption will be omitted if there is no title attribute.This is my first time contributing to Gatsby, so my apologies if I get any of this wrong. I am not sure what we want to call the option (I went with
fallbackToAltTextForCaptions
because it was clear, but happy to pick a less verbose name). I also wrote a test to cover this case and updated the README of the plugin to document the new option.