Skip to content

Commit bcd6126

Browse files
authoredMar 6, 2020
Use relative_url and absolute_url where possible (mmistakes#2387)
* Use relative_url and absolute_url where possible Drops the `contains "://"` check, adopt Jekyll 3.7 Ref: mmistakes#2385 (comment) * One more unneeded {% assign %} * Remove one more assign as noted by mmistakes * Consolidate 4 more captures * Consolidate an extra assign on "active" class
1 parent 0cf1a2e commit bcd6126

13 files changed

+39
-168
lines changed
 

‎_includes/archive-single.html

+1-7
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,7 @@
1414
<article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
1515
{% if include.type == "grid" and teaser %}
1616
<div class="archive__item-teaser">
17-
<img src=
18-
{% if teaser contains "://" %}
19-
"{{ teaser }}"
20-
{% else %}
21-
"{{ teaser | relative_url }}"
22-
{% endif %}
23-
alt="">
17+
<img src="{{ teaser | relative_url }}" alt="">
2418
</div>
2519
{% endif %}
2620
<h2 class="archive__item-title" itemprop="headline">

‎_includes/author-profile.html

+4-15
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,12 @@
55

66
{% if author.avatar %}
77
<div class="author__avatar">
8-
{% if author.avatar contains "://" %}
9-
{% assign author_src = author.avatar %}
10-
{% else %}
11-
{% assign author_src = author.avatar | relative_url %}
12-
{% endif %}
13-
148
{% if author.home %}
15-
{% if author.home contains "://" %}
16-
{% assign author_link = author.home %}
17-
{% else %}
18-
{% assign author_link = author.home | relative_url %}
19-
{% endif %}
20-
<a href="{{ author_link }}">
21-
<img src="{{ author_src }}" alt="{{ author.name }}" itemprop="image">
9+
<a href="{{ author.home | relative_url }}">
10+
<img src="{{ author.avatar | relative_url }}" alt="{{ author.name }}" itemprop="image">
2211
</a>
2312
{% else %}
24-
<img src="{{ author_src }}" alt="{{ author.name }}" itemprop="image">
13+
<img src="{{ author.avatar | relative_url }}" alt="{{ author.name }}" itemprop="image">
2514
{% endif %}
2615
</div>
2716
{% endif %}
@@ -208,7 +197,7 @@ <h3 class="author__name" itemprop="name">{{ author.name }}</h3>
208197
<i class="fab fa-fw fa-youtube" aria-hidden="true"></i> YouTube
209198
</a>
210199
</li>
211-
{% else author.youtube %}
200+
{% elsif author.youtube %}
212201
<li>
213202
<a href="https://www.youtube.com/user/{{ author.youtube }}" itemprop="sameAs" rel="nofollow noopener noreferrer">
214203
<i class="fab fa-fw fa-youtube" aria-hidden="true"></i> YouTube

‎_includes/feature_row

+4-16
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,12 @@
77
<div class="feature__wrapper">
88

99
{% for f in feature_row %}
10-
11-
{% if f.url contains "://" %}
12-
{% capture f_url %}{{ f.url }}{% endcapture %}
13-
{% else %}
14-
{% capture f_url %}{{ f.url | relative_url }}{% endcapture %}
15-
{% endif %}
16-
1710
<div class="feature__item{% if include.type %}--{{ include.type }}{% endif %}">
1811
<div class="archive__item">
1912
{% if f.image_path %}
2013
<div class="archive__item-teaser">
21-
<img src=
22-
{% if f.image_path contains "://" %}
23-
"{{ f.image_path }}"
24-
{% else %}
25-
"{{ f.image_path | relative_url }}"
26-
{% endif %}
27-
alt="{% if f.alt %}{{ f.alt }}{% endif %}">
14+
<img src="{{ f.image_path | relative_url }}"
15+
alt="{% if f.alt %}{{ f.alt }}{% endif %}">
2816
{% if f.image_caption %}
2917
<span class="archive__item-caption">{{ f.image_caption | markdownify | remove: "<p>" | remove: "</p>" }}</span>
3018
{% endif %}
@@ -43,11 +31,11 @@
4331
{% endif %}
4432

4533
{% if f.url %}
46-
<p><a href="{{ f_url }}" class="btn {{ f.btn_class }}">{{ f.btn_label | default: site.data.ui-text[site.locale].more_label | default: "Learn More" }}</a></p>
34+
<p><a href="{{ f.url | relative_url }}" class="btn {{ f.btn_class }}">{{ f.btn_label | default: site.data.ui-text[site.locale].more_label | default: "Learn More" }}</a></p>
4735
{% endif %}
4836
</div>
4937
</div>
5038
</div>
5139
{% endfor %}
5240

53-
</div>
41+
</div>

‎_includes/figure

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
<figure class="{{ include.class }}">
2-
<img src=
3-
{% if include.image_path contains "://" %}
4-
"{{ include.image_path }}"
5-
{% else %}
6-
"{{ include.image_path | relative_url }}"
7-
{% endif %}
8-
alt="{% if include.alt %}{{ include.alt }}{% endif %}">
2+
<img src="{{ include.image_path | relative_url }}"
3+
alt="{% if include.alt %}{{ include.alt }}{% endif %}">
94
{% if include.caption %}
105
<figcaption>
116
{{ include.caption | markdownify | remove: "<p>" | remove: "</p>" }}
12-
</figcaption>{% endif %}</figure>
7+
</figcaption>
8+
{% endif %}
9+
</figure>

‎_includes/gallery

+7-23
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,17 @@
1919
<figure class="{{ gallery_layout }} {{ include.class }}">
2020
{% for img in gallery %}
2121
{% if img.url %}
22-
<a href=
23-
{% if img.url contains "://" %}
24-
"{{ img.url }}"
25-
{% else %}
26-
"{{ img.url | relative_url }}"
27-
{% endif %}
28-
{% if img.title %}title="{{ img.title }}"{% endif %}
29-
>
30-
<img src=
31-
{% if img.image_path contains "://" %}
32-
"{{ img.image_path }}"
33-
{% else %}
34-
"{{ img.image_path | relative_url }}"
35-
{% endif %}
36-
alt="{% if img.alt %}{{ img.alt }}{% endif %}">
22+
<a href="{{ img.url | relative_url }}"
23+
{% if img.title %}title="{{ img.title }}"{% endif %}>
24+
<img src="{{ img.image_path | relative_url }}"
25+
alt="{% if img.alt %}{{ img.alt }}{% endif %}">
3726
</a>
3827
{% else %}
39-
<img src=
40-
{% if img.image_path contains "://" %}
41-
"{{ img.image_path }}"
42-
{% else %}
43-
"{{ img.image_path | relative_url }}"
44-
{% endif %}
45-
alt="{% if img.alt %}{{ img.alt }}{% endif %}">
28+
<img src="{{ img.image_path | relative_url }}"
29+
alt="{% if img.alt %}{{ img.alt }}{% endif %}">
4630
{% endif %}
4731
{% endfor %}
4832
{% if include.caption %}
4933
<figcaption>{{ include.caption | markdownify | remove: "<p>" | remove: "</p>" }}</figcaption>
5034
{% endif %}
51-
</figure>
35+
</figure>

‎_includes/head.html

+1-6
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131

3232
{% if site.head_scripts %}
3333
{% for script in site.head_scripts %}
34-
{% if script contains "://" %}
35-
{% capture script_path %}{{ script }}{% endcapture %}
36-
{% else %}
37-
{% capture script_path %}{{ script | relative_url }}{% endcapture %}
38-
{% endif %}
39-
<script src="{{ script_path }}"></script>
34+
<script src="{{ script | relative_url }}"></script>
4035
{% endfor %}
4136
{% endif %}

‎_includes/masthead.html

+1-6
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@
1313
</a>
1414
<ul class="visible-links">
1515
{%- for link in site.data.navigation.main -%}
16-
{%- if link.url contains '://' -%}
17-
{%- assign url = link.url -%}
18-
{%- else -%}
19-
{%- assign url = link.url | relative_url -%}
20-
{%- endif -%}
2116
<li class="masthead__menu-item">
22-
<a href="{{ url }}" {% if link.description %}title="{{ link.description }}"{% endif %}>{{ link.title }}</a>
17+
<a href="{{ link.url | relative_url }}"{% if link.description %} title="{{ link.description }}"{% endif %}>{{ link.title }}</a>
2318
</li>
2419
{%- endfor -%}
2520
</ul>

‎_includes/nav_list

+3-24
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,19 @@
88
{% for nav in navigation %}
99
<li>
1010
{% if nav.url %}
11-
{% comment %} internal/external URL check {% endcomment %}
12-
{% if nav.url contains "://" %}
13-
{% assign nav_url = nav.url %}
14-
{% else %}
15-
{% assign nav_url = nav.url | relative_url %}
16-
{% endif %}
17-
18-
<a href="{{ nav_url }}"><span class="nav__sub-title">{{ nav.title }}</span></a>
11+
<a href="{{ nav.url | relative_url }}"><span class="nav__sub-title">{{ nav.title }}</span></a>
1912
{% else %}
2013
<span class="nav__sub-title">{{ nav.title }}</span>
2114
{% endif %}
2215

2316
{% if nav.children != null %}
2417
<ul>
2518
{% for child in nav.children %}
26-
{% comment %} internal/external URL check {% endcomment %}
27-
{% if child.url contains "://" %}
28-
{% assign child_url = child.url %}
29-
{% else %}
30-
{% assign child_url = child.url | relative_url %}
31-
{% endif %}
32-
33-
{% comment %} set "active" class on current page {% endcomment %}
34-
{% if child.url == page.url %}
35-
{% assign active = "active" %}
36-
{% else %}
37-
{% assign active = "" %}
38-
{% endif %}
39-
40-
<li><a href="{{ child_url }}" class="{{ active }}">{{ child.title }}</a></li>
19+
<li><a href="{{ child.url | relative_url }}"{% if child.url == page.url %} class="active"{% endif %}>{{ child.title }}</a></li>
4120
{% endfor %}
4221
</ul>
4322
{% endif %}
4423
</li>
4524
{% endfor %}
4625
</ul>
47-
</nav>
26+
</nav>

‎_includes/page__hero.html

+4-25
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,4 @@
1-
{% if page.header.image contains "://" %}
2-
{% capture img_path %}{{ page.header.image }}{% endcapture %}
3-
{% else %}
4-
{% capture img_path %}{{ page.header.image | relative_url }}{% endcapture %}
5-
{% endif %}
6-
7-
{% if page.header.cta_url contains "://" %}
8-
{% capture cta_path %}{{ page.header.cta_url }}{% endcapture %}
9-
{% else %}
10-
{% capture cta_path %}{{ page.header.cta_url | relative_url }}{% endcapture %}
11-
{% endif %}
12-
13-
{% if page.header.overlay_image contains "://" %}
14-
{% capture overlay_img_path %}{{ page.header.overlay_image }}{% endcapture %}
15-
{% elsif page.header.overlay_image %}
16-
{% capture overlay_img_path %}{{ page.header.overlay_image | relative_url }}{% endcapture %}
17-
{% endif %}
1+
{% capture overlay_img_path %}{{ page.header.overlay_image | relative_url }}{% endcapture %}
182

193
{% if page.header.overlay_filter contains "rgba" %}
204
{% capture overlay_filter %}{{ page.header.overlay_filter }}{% endcapture %}
@@ -51,22 +35,17 @@ <h1 id="page-title" class="page__title" itemprop="headline">
5135
<p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> {% include read-time.html %}</p>
5236
{% endif %}
5337
{% if page.header.cta_url %}
54-
<p><a href="{{ cta_path }}" class="btn btn--light-outline btn--large">{{ page.header.cta_label | default: site.data.ui-text[site.locale].more_label | default: "Learn More" }}</a></p>
38+
<p><a href="{{ page.header.cta_url | relative_url }}" class="btn btn--light-outline btn--large">{{ page.header.cta_label | default: site.data.ui-text[site.locale].more_label | default: "Learn More" }}</a></p>
5539
{% endif %}
5640
{% if page.header.actions %}
5741
<p>
5842
{% for action in page.header.actions %}
59-
{% if action.url contains "://" %}
60-
{% assign url = action.url %}
61-
{% else %}
62-
{% assign url = action.url | relative_url %}
63-
{% endif %}
64-
<a href="{{ url }}" class="btn btn--light-outline btn--large">{{ action.label | default: site.data.ui-text[site.locale].more_label | default: "Learn More" }}</a>
43+
<a href="{{ action.url | relative_url }}" class="btn btn--light-outline btn--large">{{ action.label | default: site.data.ui-text[site.locale].more_label | default: "Learn More" }}</a>
6544
{% endfor %}
6645
{% endif %}
6746
</div>
6847
{% else %}
69-
<img src="{{ img_path }}" alt="{{ image_description }}" class="page__hero-image">
48+
<img src="{{ pade.header.image | relative_url }}" alt="{{ image_description }}" class="page__hero-image">
7049
{% endif %}
7150
{% if page.header.caption %}
7251
<span class="page__hero-caption">{{ page.header.caption | markdownify | remove: "<p>" | remove: "</p>" }}</span>

‎_includes/scripts.html

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
{% if site.footer_scripts %}
22
{% for script in site.footer_scripts %}
3-
{% if script contains "://" %}
4-
{% capture script_path %}{{ script }}{% endcapture %}
5-
{% else %}
6-
{% capture script_path %}{{ script | relative_url }}{% endcapture %}
7-
{% endif %}
8-
<script src="{{ script_path }}"></script>
3+
<script src="{{ script | relative_url }}"></script>
94
{% endfor %}
105
{% else %}
116
<script src="{{ '/assets/js/main.min.js' | relative_url }}"></script>
@@ -29,11 +24,6 @@
2924

3025
{% if site.after_footer_scripts %}
3126
{% for script in site.after_footer_scripts %}
32-
{% if script contains "://" %}
33-
{% capture script_path %}{{ script }}{% endcapture %}
34-
{% else %}
35-
{% capture script_path %}{{ script | relative_url }}{% endcapture %}
36-
{% endif %}
37-
<script src="{{ script_path }}"></script>
27+
<script src="{{ script | relative_url }}"></script>
3828
{% endfor %}
3929
{% endif %}

‎_includes/seo.html

+3-12
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,13 @@
3232
{%- assign author_twitter = author.twitter | replace: "@", "" -%}
3333
{%- endif -%}
3434

35-
{%- assign page_large_image = page.header.og_image | default: page.header.overlay_image | default: page.header.image -%}
36-
{%- unless page_large_image contains '://' -%}
37-
{%- assign page_large_image = page_large_image | absolute_url -%}
38-
{%- endunless -%}
35+
{%- assign page_large_image = page.header.og_image | default: page.header.overlay_image | default: page.header.image | absolute_url -%}
3936
{%- assign page_large_image = page_large_image | escape -%}
4037

41-
{%- assign page_teaser_image = page.header.teaser | default: site.og_image -%}
42-
{%- unless page_teaser_image contains '://' -%}
43-
{%- assign page_teaser_image = page_teaser_image | absolute_url -%}
44-
{%- endunless -%}
38+
{%- assign page_teaser_image = page.header.teaser | default: site.og_image | absolute_url -%}
4539
{%- assign page_teaser_image = page_teaser_image | escape -%}
4640

47-
{%- assign site_og_image = site.og_image -%}
48-
{%- unless site_og_image contains '://' -%}
49-
{%- assign site_og_image = site_og_image | absolute_url -%}
50-
{%- endunless -%}
41+
{%- assign site_og_image = site.og_image | absolute_url -%}
5142
{%- assign site_og_image = site_og_image | escape -%}
5243

5344
{%- if page.date -%}

‎_includes/sidebar.html

+3-8
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
{% if page.sidebar %}
55
{% for s in page.sidebar %}
66
{% if s.image %}
7-
<img src=
8-
{% if s.image contains "://" %}
9-
"{{ s.image }}"
10-
{% else %}
11-
"{{ s.image | relative_url }}"
12-
{% endif %}
13-
alt="{% if s.image_alt %}{{ s.image_alt }}{% endif %}">
7+
<img src="{{ s.image | relative_url }}"
8+
alt="{% if s.image_alt %}{{ s.image_alt }}{% endif %}">
149
{% endif %}
1510
{% if s.title %}<h3>{{ s.title }}</h3>{% endif %}
1611
{% if s.text %}{{ s.text | markdownify }}{% endif %}
@@ -21,4 +16,4 @@
2116
{% endif %}
2217
{% endif %}
2318
</div>
24-
{% endif %}
19+
{% endif %}

‎assets/js/lunr/lunr-store.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ var store = [
4343
"categories": {{ doc.categories | jsonify }},
4444
"tags": {{ doc.tags | jsonify }},
4545
"url": {{ doc.url | absolute_url | jsonify }},
46-
"teaser":
47-
{%- if teaser contains "://" -%}
48-
{{ teaser | jsonify }}
49-
{%- else -%}
50-
{{ teaser | absolute_url | jsonify }}
51-
{%- endif -%}
46+
"teaser": {{ teaser | absolute_url | jsonify }}
5247
}{%- unless forloop.last and l -%},{%- endunless -%}
5348
{%- endfor -%}
5449
{%- endfor -%}]

0 commit comments

Comments
 (0)
Please sign in to comment.