Skip to content

Commit

Permalink
Use relative_url and absolute_url where possible (#2387)
Browse files Browse the repository at this point in the history
* Use relative_url and absolute_url where possible

Drops the `contains "://"` check, adopt Jekyll 3.7
Ref: #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
  • Loading branch information
iBug authored Mar 6, 2020
1 parent 0cf1a2e commit bcd6126
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 168 deletions.
8 changes: 1 addition & 7 deletions _includes/archive-single.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@
<article class="archive__item" itemscope itemtype="https://schema.org/CreativeWork">
{% if include.type == "grid" and teaser %}
<div class="archive__item-teaser">
<img src=
{% if teaser contains "://" %}
"{{ teaser }}"
{% else %}
"{{ teaser | relative_url }}"
{% endif %}
alt="">
<img src="{{ teaser | relative_url }}" alt="">
</div>
{% endif %}
<h2 class="archive__item-title" itemprop="headline">
Expand Down
19 changes: 4 additions & 15 deletions _includes/author-profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,12 @@

{% if author.avatar %}
<div class="author__avatar">
{% if author.avatar contains "://" %}
{% assign author_src = author.avatar %}
{% else %}
{% assign author_src = author.avatar | relative_url %}
{% endif %}

{% if author.home %}
{% if author.home contains "://" %}
{% assign author_link = author.home %}
{% else %}
{% assign author_link = author.home | relative_url %}
{% endif %}
<a href="{{ author_link }}">
<img src="{{ author_src }}" alt="{{ author.name }}" itemprop="image">
<a href="{{ author.home | relative_url }}">
<img src="{{ author.avatar | relative_url }}" alt="{{ author.name }}" itemprop="image">
</a>
{% else %}
<img src="{{ author_src }}" alt="{{ author.name }}" itemprop="image">
<img src="{{ author.avatar | relative_url }}" alt="{{ author.name }}" itemprop="image">
{% endif %}
</div>
{% endif %}
Expand Down Expand Up @@ -208,7 +197,7 @@ <h3 class="author__name" itemprop="name">{{ author.name }}</h3>
<i class="fab fa-fw fa-youtube" aria-hidden="true"></i> YouTube
</a>
</li>
{% else author.youtube %}
{% elsif author.youtube %}
<li>
<a href="https://www.youtube.com/user/{{ author.youtube }}" itemprop="sameAs" rel="nofollow noopener noreferrer">
<i class="fab fa-fw fa-youtube" aria-hidden="true"></i> YouTube
Expand Down
20 changes: 4 additions & 16 deletions _includes/feature_row
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,12 @@
<div class="feature__wrapper">

{% for f in feature_row %}

{% if f.url contains "://" %}
{% capture f_url %}{{ f.url }}{% endcapture %}
{% else %}
{% capture f_url %}{{ f.url | relative_url }}{% endcapture %}
{% endif %}

<div class="feature__item{% if include.type %}--{{ include.type }}{% endif %}">
<div class="archive__item">
{% if f.image_path %}
<div class="archive__item-teaser">
<img src=
{% if f.image_path contains "://" %}
"{{ f.image_path }}"
{% else %}
"{{ f.image_path | relative_url }}"
{% endif %}
alt="{% if f.alt %}{{ f.alt }}{% endif %}">
<img src="{{ f.image_path | relative_url }}"
alt="{% if f.alt %}{{ f.alt }}{% endif %}">
{% if f.image_caption %}
<span class="archive__item-caption">{{ f.image_caption | markdownify | remove: "<p>" | remove: "</p>" }}</span>
{% endif %}
Expand All @@ -43,11 +31,11 @@
{% endif %}

{% if f.url %}
<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>
<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>
{% endif %}
</div>
</div>
</div>
{% endfor %}

</div>
</div>
13 changes: 5 additions & 8 deletions _includes/figure
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<figure class="{{ include.class }}">
<img src=
{% if include.image_path contains "://" %}
"{{ include.image_path }}"
{% else %}
"{{ include.image_path | relative_url }}"
{% endif %}
alt="{% if include.alt %}{{ include.alt }}{% endif %}">
<img src="{{ include.image_path | relative_url }}"
alt="{% if include.alt %}{{ include.alt }}{% endif %}">
{% if include.caption %}
<figcaption>
{{ include.caption | markdownify | remove: "<p>" | remove: "</p>" }}
</figcaption>{% endif %}</figure>
</figcaption>
{% endif %}
</figure>
30 changes: 7 additions & 23 deletions _includes/gallery
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,17 @@
<figure class="{{ gallery_layout }} {{ include.class }}">
{% for img in gallery %}
{% if img.url %}
<a href=
{% if img.url contains "://" %}
"{{ img.url }}"
{% else %}
"{{ img.url | relative_url }}"
{% endif %}
{% if img.title %}title="{{ img.title }}"{% endif %}
>
<img src=
{% if img.image_path contains "://" %}
"{{ img.image_path }}"
{% else %}
"{{ img.image_path | relative_url }}"
{% endif %}
alt="{% if img.alt %}{{ img.alt }}{% endif %}">
<a href="{{ img.url | relative_url }}"
{% if img.title %}title="{{ img.title }}"{% endif %}>
<img src="{{ img.image_path | relative_url }}"
alt="{% if img.alt %}{{ img.alt }}{% endif %}">
</a>
{% else %}
<img src=
{% if img.image_path contains "://" %}
"{{ img.image_path }}"
{% else %}
"{{ img.image_path | relative_url }}"
{% endif %}
alt="{% if img.alt %}{{ img.alt }}{% endif %}">
<img src="{{ img.image_path | relative_url }}"
alt="{% if img.alt %}{{ img.alt }}{% endif %}">
{% endif %}
{% endfor %}
{% if include.caption %}
<figcaption>{{ include.caption | markdownify | remove: "<p>" | remove: "</p>" }}</figcaption>
{% endif %}
</figure>
</figure>
7 changes: 1 addition & 6 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@

{% if site.head_scripts %}
{% for script in site.head_scripts %}
{% if script contains "://" %}
{% capture script_path %}{{ script }}{% endcapture %}
{% else %}
{% capture script_path %}{{ script | relative_url }}{% endcapture %}
{% endif %}
<script src="{{ script_path }}"></script>
<script src="{{ script | relative_url }}"></script>
{% endfor %}
{% endif %}
7 changes: 1 addition & 6 deletions _includes/masthead.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@
</a>
<ul class="visible-links">
{%- for link in site.data.navigation.main -%}
{%- if link.url contains '://' -%}
{%- assign url = link.url -%}
{%- else -%}
{%- assign url = link.url | relative_url -%}
{%- endif -%}
<li class="masthead__menu-item">
<a href="{{ url }}" {% if link.description %}title="{{ link.description }}"{% endif %}>{{ link.title }}</a>
<a href="{{ link.url | relative_url }}"{% if link.description %} title="{{ link.description }}"{% endif %}>{{ link.title }}</a>
</li>
{%- endfor -%}
</ul>
Expand Down
27 changes: 3 additions & 24 deletions _includes/nav_list
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,19 @@
{% for nav in navigation %}
<li>
{% if nav.url %}
{% comment %} internal/external URL check {% endcomment %}
{% if nav.url contains "://" %}
{% assign nav_url = nav.url %}
{% else %}
{% assign nav_url = nav.url | relative_url %}
{% endif %}

<a href="{{ nav_url }}"><span class="nav__sub-title">{{ nav.title }}</span></a>
<a href="{{ nav.url | relative_url }}"><span class="nav__sub-title">{{ nav.title }}</span></a>
{% else %}
<span class="nav__sub-title">{{ nav.title }}</span>
{% endif %}

{% if nav.children != null %}
<ul>
{% for child in nav.children %}
{% comment %} internal/external URL check {% endcomment %}
{% if child.url contains "://" %}
{% assign child_url = child.url %}
{% else %}
{% assign child_url = child.url | relative_url %}
{% endif %}

{% comment %} set "active" class on current page {% endcomment %}
{% if child.url == page.url %}
{% assign active = "active" %}
{% else %}
{% assign active = "" %}
{% endif %}

<li><a href="{{ child_url }}" class="{{ active }}">{{ child.title }}</a></li>
<li><a href="{{ child.url | relative_url }}"{% if child.url == page.url %} class="active"{% endif %}>{{ child.title }}</a></li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
</nav>
</nav>
29 changes: 4 additions & 25 deletions _includes/page__hero.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
{% if page.header.image contains "://" %}
{% capture img_path %}{{ page.header.image }}{% endcapture %}
{% else %}
{% capture img_path %}{{ page.header.image | relative_url }}{% endcapture %}
{% endif %}

{% if page.header.cta_url contains "://" %}
{% capture cta_path %}{{ page.header.cta_url }}{% endcapture %}
{% else %}
{% capture cta_path %}{{ page.header.cta_url | relative_url }}{% endcapture %}
{% endif %}

{% if page.header.overlay_image contains "://" %}
{% capture overlay_img_path %}{{ page.header.overlay_image }}{% endcapture %}
{% elsif page.header.overlay_image %}
{% capture overlay_img_path %}{{ page.header.overlay_image | relative_url }}{% endcapture %}
{% endif %}
{% capture overlay_img_path %}{{ page.header.overlay_image | relative_url }}{% endcapture %}

{% if page.header.overlay_filter contains "rgba" %}
{% capture overlay_filter %}{{ page.header.overlay_filter }}{% endcapture %}
Expand Down Expand Up @@ -51,22 +35,17 @@ <h1 id="page-title" class="page__title" itemprop="headline">
<p class="page__meta"><i class="far fa-clock" aria-hidden="true"></i> {% include read-time.html %}</p>
{% endif %}
{% if page.header.cta_url %}
<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>
<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>
{% endif %}
{% if page.header.actions %}
<p>
{% for action in page.header.actions %}
{% if action.url contains "://" %}
{% assign url = action.url %}
{% else %}
{% assign url = action.url | relative_url %}
{% endif %}
<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>
<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>
{% endfor %}
{% endif %}
</div>
{% else %}
<img src="{{ img_path }}" alt="{{ image_description }}" class="page__hero-image">
<img src="{{ pade.header.image | relative_url }}" alt="{{ image_description }}" class="page__hero-image">
{% endif %}
{% if page.header.caption %}
<span class="page__hero-caption">{{ page.header.caption | markdownify | remove: "<p>" | remove: "</p>" }}</span>
Expand Down
14 changes: 2 additions & 12 deletions _includes/scripts.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{% if site.footer_scripts %}
{% for script in site.footer_scripts %}
{% if script contains "://" %}
{% capture script_path %}{{ script }}{% endcapture %}
{% else %}
{% capture script_path %}{{ script | relative_url }}{% endcapture %}
{% endif %}
<script src="{{ script_path }}"></script>
<script src="{{ script | relative_url }}"></script>
{% endfor %}
{% else %}
<script src="{{ '/assets/js/main.min.js' | relative_url }}"></script>
Expand All @@ -29,11 +24,6 @@

{% if site.after_footer_scripts %}
{% for script in site.after_footer_scripts %}
{% if script contains "://" %}
{% capture script_path %}{{ script }}{% endcapture %}
{% else %}
{% capture script_path %}{{ script | relative_url }}{% endcapture %}
{% endif %}
<script src="{{ script_path }}"></script>
<script src="{{ script | relative_url }}"></script>
{% endfor %}
{% endif %}
15 changes: 3 additions & 12 deletions _includes/seo.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,13 @@
{%- assign author_twitter = author.twitter | replace: "@", "" -%}
{%- endif -%}

{%- assign page_large_image = page.header.og_image | default: page.header.overlay_image | default: page.header.image -%}
{%- unless page_large_image contains '://' -%}
{%- assign page_large_image = page_large_image | absolute_url -%}
{%- endunless -%}
{%- assign page_large_image = page.header.og_image | default: page.header.overlay_image | default: page.header.image | absolute_url -%}
{%- assign page_large_image = page_large_image | escape -%}

{%- assign page_teaser_image = page.header.teaser | default: site.og_image -%}
{%- unless page_teaser_image contains '://' -%}
{%- assign page_teaser_image = page_teaser_image | absolute_url -%}
{%- endunless -%}
{%- assign page_teaser_image = page.header.teaser | default: site.og_image | absolute_url -%}
{%- assign page_teaser_image = page_teaser_image | escape -%}

{%- assign site_og_image = site.og_image -%}
{%- unless site_og_image contains '://' -%}
{%- assign site_og_image = site_og_image | absolute_url -%}
{%- endunless -%}
{%- assign site_og_image = site.og_image | absolute_url -%}
{%- assign site_og_image = site_og_image | escape -%}

{%- if page.date -%}
Expand Down
11 changes: 3 additions & 8 deletions _includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
{% if page.sidebar %}
{% for s in page.sidebar %}
{% if s.image %}
<img src=
{% if s.image contains "://" %}
"{{ s.image }}"
{% else %}
"{{ s.image | relative_url }}"
{% endif %}
alt="{% if s.image_alt %}{{ s.image_alt }}{% endif %}">
<img src="{{ s.image | relative_url }}"
alt="{% if s.image_alt %}{{ s.image_alt }}{% endif %}">
{% endif %}
{% if s.title %}<h3>{{ s.title }}</h3>{% endif %}
{% if s.text %}{{ s.text | markdownify }}{% endif %}
Expand All @@ -21,4 +16,4 @@
{% endif %}
{% endif %}
</div>
{% endif %}
{% endif %}
7 changes: 1 addition & 6 deletions assets/js/lunr/lunr-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ var store = [
"categories": {{ doc.categories | jsonify }},
"tags": {{ doc.tags | jsonify }},
"url": {{ doc.url | absolute_url | jsonify }},
"teaser":
{%- if teaser contains "://" -%}
{{ teaser | jsonify }}
{%- else -%}
{{ teaser | absolute_url | jsonify }}
{%- endif -%}
"teaser": {{ teaser | absolute_url | jsonify }}
}{%- unless forloop.last and l -%},{%- endunless -%}
{%- endfor -%}
{%- endfor -%}]

0 comments on commit bcd6126

Please sign in to comment.