From ba2dc8b211bcb4fc9ad67e310c02d979d974b717 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?iBug=20=E2=99=A6?= Date: Sat, 7 Mar 2020 04:37:07 +0800 Subject: [PATCH] Use relative_url and absolute_url where possible (#2387) * Use relative_url and absolute_url where possible Drops the `contains "://"` check, adopt Jekyll 3.7 Ref: https://github.com/mmistakes/minimal-mistakes/pull/2385#issuecomment-579882236 * One more unneeded {% assign %} * Remove one more assign as noted by mmistakes * Consolidate 4 more captures * Consolidate an extra assign on "active" class --- _includes/archive-single.html | 8 +------- _includes/author-profile.html | 19 ++++--------------- _includes/feature_row | 20 ++++---------------- _includes/figure | 13 +++++-------- _includes/gallery | 30 +++++++----------------------- _includes/head.html | 7 +------ _includes/masthead.html | 7 +------ _includes/nav_list | 27 +++------------------------ _includes/page__hero.html | 29 ++++------------------------- _includes/scripts.html | 14 ++------------ _includes/seo.html | 15 +++------------ _includes/sidebar.html | 11 +++-------- assets/js/lunr/lunr-store.js | 7 +------ 13 files changed, 39 insertions(+), 168 deletions(-) diff --git a/_includes/archive-single.html b/_includes/archive-single.html index 489f00067a6d..de77f696d2c3 100644 --- a/_includes/archive-single.html +++ b/_includes/archive-single.html @@ -14,13 +14,7 @@
{% if include.type == "grid" and teaser %}
- +
{% endif %}

diff --git a/_includes/author-profile.html b/_includes/author-profile.html index b7d62149927c..5c7304783926 100644 --- a/_includes/author-profile.html +++ b/_includes/author-profile.html @@ -5,23 +5,12 @@ {% if 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 %} - - {{ author.name }} + + {{ author.name }} {% else %} - {{ author.name }} + {{ author.name }} {% endif %}
{% endif %} @@ -208,7 +197,7 @@

{{ author.name }}

YouTube - {% else author.youtube %} + {% elsif author.youtube %}
  • YouTube diff --git a/_includes/feature_row b/_includes/feature_row index 89dfc1b4738b..03f09c15cf0c 100644 --- a/_includes/feature_row +++ b/_includes/feature_row @@ -7,24 +7,12 @@ \ No newline at end of file + diff --git a/_includes/figure b/_includes/figure index 8e9bdd581d69..f1ce1ebcc110 100644 --- a/_includes/figure +++ b/_includes/figure @@ -1,12 +1,9 @@
    - {% if include.alt %}{{ include.alt }}{% endif %} + {% if include.alt %}{{ include.alt }}{% endif %} {% if include.caption %}
    {{ include.caption | markdownify | remove: "

    " | remove: "

    " }} -
    {% endif %}
    + + {% endif %} + diff --git a/_includes/gallery b/_includes/gallery index 97022aa881da..71a9e1e1b3d1 100644 --- a/_includes/gallery +++ b/_includes/gallery @@ -19,33 +19,17 @@ \ No newline at end of file + diff --git a/_includes/head.html b/_includes/head.html index 8963379aa033..fb1e5dce52e8 100644 --- a/_includes/head.html +++ b/_includes/head.html @@ -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 %} - + {% endfor %} {% endif %} diff --git a/_includes/masthead.html b/_includes/masthead.html index 28fb6fe2fe00..47cce0a3545e 100644 --- a/_includes/masthead.html +++ b/_includes/masthead.html @@ -13,13 +13,8 @@ diff --git a/_includes/nav_list b/_includes/nav_list index b1d06c304b7a..a035a5bd7b15 100644 --- a/_includes/nav_list +++ b/_includes/nav_list @@ -8,14 +8,7 @@ {% for nav in navigation %}
  • {% 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 %} - - {{ nav.title }} + {{ nav.title }} {% else %} {{ nav.title }} {% endif %} @@ -23,25 +16,11 @@ {% if nav.children != null %}
      {% 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 %} - -
    • {{ child.title }}
    • +
    • {{ child.title }}
    • {% endfor %}
    {% endif %}
  • {% endfor %} - \ No newline at end of file + diff --git a/_includes/page__hero.html b/_includes/page__hero.html index a84671db30c3..222d4449a442 100644 --- a/_includes/page__hero.html +++ b/_includes/page__hero.html @@ -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 %} @@ -51,22 +35,17 @@

    {% include read-time.html %}

    {% endif %} {% if page.header.cta_url %} -

    {{ page.header.cta_label | default: site.data.ui-text[site.locale].more_label | default: "Learn More" }}

    +

    {{ page.header.cta_label | default: site.data.ui-text[site.locale].more_label | default: "Learn More" }}

    {% endif %} {% if page.header.actions %}

    {% for action in page.header.actions %} - {% if action.url contains "://" %} - {% assign url = action.url %} - {% else %} - {% assign url = action.url | relative_url %} - {% endif %} - {{ action.label | default: site.data.ui-text[site.locale].more_label | default: "Learn More" }} + {{ action.label | default: site.data.ui-text[site.locale].more_label | default: "Learn More" }} {% endfor %} {% endif %} {% else %} - {{ image_description }} + {{ image_description }} {% endif %} {% if page.header.caption %} {{ page.header.caption | markdownify | remove: "

    " | remove: "

    " }} diff --git a/_includes/scripts.html b/_includes/scripts.html index 5530028ef866..806bbc16baf2 100644 --- a/_includes/scripts.html +++ b/_includes/scripts.html @@ -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 %} - + {% endfor %} {% else %} @@ -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 %} - + {% endfor %} {% endif %} diff --git a/_includes/seo.html b/_includes/seo.html index cb6e36ef47c2..bf2c89d94dc3 100644 --- a/_includes/seo.html +++ b/_includes/seo.html @@ -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 -%} diff --git a/_includes/sidebar.html b/_includes/sidebar.html index 2a1884edeb55..a4ca1ca78151 100644 --- a/_includes/sidebar.html +++ b/_includes/sidebar.html @@ -4,13 +4,8 @@ {% if page.sidebar %} {% for s in page.sidebar %} {% if s.image %} - {% if s.image_alt %}{{ s.image_alt }}{% endif %} + {% if s.image_alt %}{{ s.image_alt }}{% endif %} {% endif %} {% if s.title %}

    {{ s.title }}

    {% endif %} {% if s.text %}{{ s.text | markdownify }}{% endif %} @@ -21,4 +16,4 @@ {% endif %} {% endif %} -{% endif %} \ No newline at end of file +{% endif %} diff --git a/assets/js/lunr/lunr-store.js b/assets/js/lunr/lunr-store.js index 660e9f2b23ed..0f405ee92a4a 100644 --- a/assets/js/lunr/lunr-store.js +++ b/assets/js/lunr/lunr-store.js @@ -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 -%}]