Skip to content

Commit f7a1b1a

Browse files
committedAug 4, 2017
DRY up handling of image_description for alternative text
1 parent cb8cb6f commit f7a1b1a

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed
 

‎_includes/page__hero.html

+9-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
{% capture overlay_filter %}rgba(0, 0, 0, {{ page.header.overlay_filter }}){% endcapture %}
2323
{% endif %}
2424

25+
{% if page.header.image_description %}
26+
{% assign image_description = page.header.image_description %}
27+
{% else %}
28+
{% assign image_description = page.title %}
29+
{% endif %}
30+
31+
{% assign image_description = image_description | markdownify | strip_html | strip_newlines | escape_once %}
32+
2533
<div class="page__hero{% if page.header.overlay_color or page.header.overlay_image %}--overlay{% endif %}"
2634
style="{% if page.header.overlay_color %}background-color: {{ page.header.overlay_color | default: 'transparent' }};{% endif %} {% if overlay_img_path %}background-image: {% if overlay_filter %}linear-gradient({{ overlay_filter }}, {{ overlay_filter }}), {% endif %}url('{{ overlay_img_path }}');{% endif %}"
2735
>
@@ -45,11 +53,7 @@ <h1 class="page__title" itemprop="headline">
4553
{% endif %}
4654
</div>
4755
{% else %}
48-
{% if page.header.image_description %}
49-
<img src="{{ img_path }}" alt="{{ page.header.image_description }}" class="page__hero-image">
50-
{% else %}
51-
<img src="{{ img_path }}" alt="{{ page.title }}" class="page__hero-image">
52-
{% endif %}
56+
<img src="{{ img_path }}" alt="{{ image_description }}" class="page__hero-image">
5357
{% endif %}
5458
{% if page.header.caption %}
5559
<span class="page__hero-caption">{{ page.header.caption | markdownify | remove: "<p>" | remove: "</p>" }}</span>

‎docs/_includes/page__hero.html

+9-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
{% capture overlay_filter %}rgba(0, 0, 0, {{ page.header.overlay_filter }}){% endcapture %}
2323
{% endif %}
2424

25+
{% if page.header.image_description %}
26+
{% assign image_description = page.header.image_description %}
27+
{% else %}
28+
{% assign image_description = page.title %}
29+
{% endif %}
30+
31+
{% assign image_description = image_description | markdownify | strip_html | strip_newlines | escape_once %}
32+
2533
<div class="page__hero{% if page.header.overlay_color or page.header.overlay_image %}--overlay{% endif %}"
2634
style="{% if page.header.overlay_color %}background-color: {{ page.header.overlay_color | default: 'transparent' }};{% endif %} {% if overlay_img_path %}background-image: {% if overlay_filter %}linear-gradient({{ overlay_filter }}, {{ overlay_filter }}), {% endif %}url('{{ overlay_img_path }}');{% endif %}"
2735
>
@@ -45,7 +53,7 @@ <h1 class="page__title" itemprop="headline">
4553
{% endif %}
4654
</div>
4755
{% else %}
48-
<img src="{{ img_path }}" alt="{{ page.title }}" class="page__hero-image">
56+
<img src="{{ img_path }}" alt="{{ image_description }}" class="page__hero-image">
4957
{% endif %}
5058
{% if page.header.caption %}
5159
<span class="page__hero-caption">{{ page.header.caption | markdownify | remove: "<p>" | remove: "</p>" }}</span>

0 commit comments

Comments
 (0)
Please sign in to comment.