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(front): ❤️ add assistive text to hero background image (#1234) #1236

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion front/src/lib/components/posts/Post.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
heroMime,
loaded,
position,
heroThumb;
heroThumb,
heroAlt;

/**
* Sets the active link in the page navigation.
Expand Down Expand Up @@ -105,6 +106,7 @@
{loaded}
{position}
{heroThumb}
{heroAlt}
slot="header"
/>
{#if (toc && toc.length) || (categories && categories.length) || (related && related.length)}
Expand Down
10 changes: 10 additions & 0 deletions front/src/lib/components/posts/PostHero.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* @property {string} heroImage - URL of the hero image.
* @property {string} heroMime - MIME type of the hero image.
* @property {string} heroThumb - URL of the hero thumbnail.
* @property {string} heroAlt - Alt text for the hero image.
* @property {boolean} loaded - Flag indicating whether the hero image is loaded.
* @property {string} position - CSS background position for the images.
*/
Expand All @@ -28,6 +29,11 @@
*/
export let heroThumb;

/**
* @type {Props}
*/
export let heroAlt;

/**
* @type {Props}
*/
Expand Down Expand Up @@ -70,11 +76,15 @@
<div
class={`post-hero {loaded ? 'post-hero-loaded' : ''}`}
style={`background-image: url('${heroThumb}'); background-position: ${position}`}
role="img"
aria-label={heroAlt ? heroAlt : null}
/>
<noscript>
<div
class="post-hero noscript"
style="background-image: url('{heroImage}'); background-position: {position};"
role="img"
aria-label={heroAlt}
/>
</noscript>
</div>
Expand Down
2 changes: 2 additions & 0 deletions front/src/routes/post/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
? hero.formats.thumbnail.url
: false;
$: heroImage = hero?.url ? hero.url : false;
$: heroAlt = hero?.alternativeText ? hero.alternativeText : false;
$: heroMime = hero?.mime;
$: position = post.position || 'center center';
$: ({ publishedAt, updatedAt } = post);
Expand Down Expand Up @@ -65,6 +66,7 @@
{loaded}
{position}
{heroThumb}
{heroAlt}
/>
</section>

Expand Down
Loading