From ecb00fa5ac19629f1548eaf3774467e0287ad2f5 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Thu, 3 Aug 2023 15:41:51 +0200 Subject: [PATCH] Add alt text for preview card thumbnails (#26184) --- .../features/explore/components/story.jsx | 5 +- .../mastodon/features/explore/links.jsx | 1 + .../features/status/components/card.jsx | 3 +- app/lib/link_details_extractor.rb | 5 + app/models/preview_card.rb | 1 + .../rest/preview_card_serializer.rb | 2 +- ..._add_image_description_to_preview_cards.rb | 17 + db/schema.rb | 1 + spec/lib/link_details_extractor_spec.rb | 323 ++++++++++++------ 9 files changed, 258 insertions(+), 100 deletions(-) create mode 100644 db/migrate/20230725213448_add_image_description_to_preview_cards.rb diff --git a/app/javascript/mastodon/features/explore/components/story.jsx b/app/javascript/mastodon/features/explore/components/story.jsx index 92eb41cff8..80dd5200fc 100644 --- a/app/javascript/mastodon/features/explore/components/story.jsx +++ b/app/javascript/mastodon/features/explore/components/story.jsx @@ -22,6 +22,7 @@ export default class Story extends PureComponent { author: PropTypes.string, sharedTimes: PropTypes.number, thumbnail: PropTypes.string, + thumbnailDescription: PropTypes.string, blurhash: PropTypes.string, expanded: PropTypes.bool, }; @@ -33,7 +34,7 @@ export default class Story extends PureComponent { handleImageLoad = () => this.setState({ thumbnailLoaded: true }); render () { - const { expanded, url, title, lang, publisher, author, publishedAt, sharedTimes, thumbnail, blurhash } = this.props; + const { expanded, url, title, lang, publisher, author, publishedAt, sharedTimes, thumbnail, thumbnailDescription, blurhash } = this.props; const { thumbnailLoaded } = this.state; @@ -49,7 +50,7 @@ export default class Story extends PureComponent { {thumbnail ? ( <>
- + {thumbnailDescription} ) : } diff --git a/app/javascript/mastodon/features/explore/links.jsx b/app/javascript/mastodon/features/explore/links.jsx index 489ab6dd61..663aa6d80f 100644 --- a/app/javascript/mastodon/features/explore/links.jsx +++ b/app/javascript/mastodon/features/explore/links.jsx @@ -67,6 +67,7 @@ class Links extends PureComponent { author={link.get('author_name')} sharedTimes={link.getIn(['history', 0, 'accounts']) * 1 + link.getIn(['history', 1, 'accounts']) * 1} thumbnail={link.get('image')} + thumbnailDescription={link.get('image_description')} blurhash={link.get('blurhash')} /> ))} diff --git a/app/javascript/mastodon/features/status/components/card.jsx b/app/javascript/mastodon/features/status/components/card.jsx index 6ac3c1d0f2..07fb1db9e2 100644 --- a/app/javascript/mastodon/features/status/components/card.jsx +++ b/app/javascript/mastodon/features/status/components/card.jsx @@ -167,7 +167,8 @@ export default class Card extends PureComponent { /> ); - let thumbnail = ; + const thumbnailDescription = card.get('image_description'); + const thumbnail = {thumbnailDescription}; let spoilerButton = (