Fix showing background img with non-empty baseurl (#497)

* Fix showing background img with non-empty baseurl

Also switch globally to relative_url for all baseurl prepends,
which is more robust than custom URL mangling

* More site.baseurl -> relative_url conversion
This commit is contained in:
Abel Cheung 2019-06-08 13:34:33 +08:00 committed by Dean Attali
parent a666a9db52
commit 7b43e4061d
12 changed files with 28 additions and 28 deletions

View File

@ -9,5 +9,5 @@ permalink: /404.html
<h1>Move along. (404 error)</h1> <h1>Move along. (404 error)</h1>
<br/> <br/>
<img src="{{ site.baseurl }}/img/404-southpark.jpg" /> <img src="{{ 'img/404-southpark.jpg' | relative_url }}" />
</div> </div>

View File

@ -73,7 +73,7 @@ telephone:
rss: rss:
name: "RSS" name: "RSS"
baseURL: "{{ '/feed.xml' | prepend: site.baseurl }}" baseURL: "{{ '/feed.xml' | relative_url }}"
icon: "fa-rss" icon: "fa-rss"
steam: steam:

View File

@ -12,7 +12,7 @@
{% if page.js %} {% if page.js %}
{% for js in page.js %} {% for js in page.js %}
<script src="{{ js | prepend: site.baseurl | replace: '//', '/' }}"></script> <script src="{{ js | relative_url }}"></script>
{% endfor %} {% endfor %}
{% endif %} {% endif %}
@ -22,11 +22,11 @@
{% if js contains 'jquery' %} {% if js contains 'jquery' %}
<script> <script>
if (typeof jQuery == 'undefined') { if (typeof jQuery == 'undefined') {
document.write('<script src="{{ js | prepend: site.baseurl | replace: "//", "/" }}"></scr' + 'ipt>'); document.write('<script src="{{ js | relative_url }}"></scr' + 'ipt>');
} }
</script> </script>
{% else %} {% else %}
<script src="{{ js | prepend: site.baseurl | replace: '//', '/' }}"></script> <script src="{{ js | relative_url }}"></script>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}

View File

@ -8,7 +8,7 @@
{%- assign element = site.data.SocialNetworks[curkey] -%} {%- assign element = site.data.SocialNetworks[curkey] -%}
<li> <li>
{%- if curkey == 'rss' -%} {%- if curkey == 'rss' -%}
<a href="{{ '/feed.xml' | prepend: site.baseurl }}" title="{{ element.name }}"> <a href="{{ '/feed.xml' | relative_url }}" title="{{ element.name }}">
{%- elsif curkey == 'yelp' -%} {%- elsif curkey == 'yelp' -%}
<a href="https://{{ site.social-network-links[curkey] }}.yelp.com" title="{{ element.name }}"> <a href="https://{{ site.social-network-links[curkey] }}.yelp.com" title="{{ element.name }}">
{%- else -%} {%- else -%}

View File

@ -11,7 +11,7 @@
<meta name="description" content="{{ page.subtitle }}"> <meta name="description" content="{{ page.subtitle }}">
{% endif %} {% endif %}
<link rel="alternate" type="application/rss+xml" title="{{ site.title }} {{ site.title-separator }} {{ site.description }}" href="{{ site.baseurl }}/feed.xml" /> <link rel="alternate" type="application/rss+xml" title="{{ site.title }} {{ site.title-separator }} {{ site.description }}" href="{{ '/feed.xml' | relative_url }}" />
{% include gtag.html %} {% include gtag.html %}
{% include gtm_head.html %} {% include gtm_head.html %}
@ -25,7 +25,7 @@
{% if layout.common-css %} {% if layout.common-css %}
{% for css in layout.common-css %} {% for css in layout.common-css %}
<link rel="stylesheet" href="{{ css | prepend: site.baseurl | replace: '//', '/' }}" /> <link rel="stylesheet" href="{{ css | relative_url }}" />
{% endfor %} {% endfor %}
{% endif %} {% endif %}
@ -43,7 +43,7 @@
{% if page.css %} {% if page.css %}
{% for css in page.css %} {% for css in page.css %}
<link rel="stylesheet" href="{{ css | prepend: site.baseurl | replace: '//', '/' }}" /> <link rel="stylesheet" href="{{ css | relative_url }}" />
{% endfor %} {% endfor %}
{% endif %} {% endif %}
@ -125,7 +125,7 @@
{% if page.comments and site.staticman.repository and site.staticman.branch %} {% if page.comments and site.staticman.repository and site.staticman.branch %}
<!-- Staticman --> <!-- Staticman -->
<link rel="stylesheet" href="{{ "/css/staticman.css" | prepend: site.baseurl }}" /> <link rel="stylesheet" href="{{ "/css/staticman.css" | relative_url }}" />
{% endif %} {% endif %}
</head> </head>

View File

@ -8,10 +8,10 @@
{% assign imgnum = forloop.index %} {% assign imgnum = forloop.index %}
{% for imginfo in bigimg %} {% for imginfo in bigimg %}
{% if imginfo[0] %} {% if imginfo[0] %}
data-img-src-{{ imgnum }}="{{ imginfo[0] | prepend: site.baseurl | replace: '//', '/' }}" data-img-src-{{ imgnum }}="{{ imginfo[0] | relative_url }}"
data-img-desc-{{ imgnum }}="{{ imginfo[1] }}" data-img-desc-{{ imgnum }}="{{ imginfo[1] }}"
{% else %} {% else %}
data-img-src-{{ imgnum }}="{{ imginfo | prepend: site.baseurl | replace: '//', '/' }}" data-img-src-{{ imgnum }}="{{ imginfo | relative_url }}"
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}

View File

@ -41,7 +41,7 @@
<div class="avatar-container"> <div class="avatar-container">
<div class="avatar-img-border"> <div class="avatar-img-border">
<a href="{{ site.url }}"> <a href="{{ site.url }}">
<img class="avatar-img" src="{{ page.image | prepend: site.baseurl | replace: '//', '/' }}" /> <img class="avatar-img" src="{{ page.image | relative_url }}" />
</a> </a>
</div> </div>
</div> </div>
@ -49,7 +49,7 @@
<div class="avatar-container"> <div class="avatar-container">
<div class="avatar-img-border"> <div class="avatar-img-border">
<a href="{{ site.url }}"> <a href="{{ site.url }}">
<img class="avatar-img" src="{{ site.avatar | prepend: site.baseurl | replace: '//', '/' }}" /> <img class="avatar-img" src="{{ site.avatar | relative_url }}" />
</a> </a>
</div> </div>
</div> </div>

View File

@ -8,7 +8,7 @@
{% endif %} {% endif %}
{% if internal %} {% if internal %}
{% capture linkurl %}{{ site.baseurl }}/{{ include.link[1] }}{% endcapture %} {% capture linkurl %}{{ include.link[1] | relative_url }}{% endcapture %}
{% else %} {% else %}
{% capture linkurl %}{{ include.link[1] }}{% endcapture %} {% capture linkurl %}{{ include.link[1] }}{% endcapture %}
{% endif %} {% endif %}

View File

@ -2,7 +2,7 @@
<!-- doing something a bit funky here because I want to be careful not to include JQuery twice! --> <!-- doing something a bit funky here because I want to be careful not to include JQuery twice! -->
<script> <script>
if (typeof jQuery == 'undefined') { if (typeof jQuery == 'undefined') {
document.write('<script src="{{ site.baseurl }}/js/jquery-1.11.2.min.js"></scr' + 'ipt>'); document.write('<script src="{{ "/js/jquery-1.11.2.min.js" | relative_url }}"></scr' + 'ipt>');
} }
</script> </script>
<script> <script>

View File

@ -40,7 +40,7 @@ layout: base
Tags: Tags:
{% if site.link-tags %} {% if site.link-tags %}
{% for tag in page.tags %} {% for tag in page.tags %}
<a href="{{ site.baseurl }}/tags#{{- tag -}}">{{- tag -}}</a> <a href="{{ '/tags' | relative_url }}#{{- tag -}}">{{- tag -}}</a>
{% endfor %} {% endfor %}
{% else %} {% else %}
{{ page.tags | join: ", " }} {{ page.tags | join: ", " }}
@ -55,12 +55,12 @@ layout: base
<ul class="pager blog-pager"> <ul class="pager blog-pager">
{% if page.previous.url %} {% if page.previous.url %}
<li class="previous"> <li class="previous">
<a href="{{ page.previous.url | prepend: site.baseurl | replace: '//', '/' }}" data-toggle="tooltip" data-placement="top" title="{{page.previous.title}}">&larr; Previous Post</a> <a href="{{ page.previous.url | relative_url }}" data-toggle="tooltip" data-placement="top" title="{{page.previous.title}}">&larr; Previous Post</a>
</li> </li>
{% endif %} {% endif %}
{% if page.next.url %} {% if page.next.url %}
<li class="next"> <li class="next">
<a href="{{ page.next.url | prepend: site.baseurl | replace: '//', '/' }}" data-toggle="tooltip" data-placement="top" title="{{page.next.title}}">Next Post &rarr;</a> <a href="{{ page.next.url | relative_url }}" data-toggle="tooltip" data-placement="top" title="{{page.next.title}}">Next Post &rarr;</a>
</li> </li>
{% endif %} {% endif %}
</ul> </ul>

View File

@ -13,7 +13,7 @@ body {
position: relative; position: relative;
background-color: {{ site.page-col }}; background-color: {{ site.page-col }};
{% if site.page-img %} {% if site.page-img %}
background-image: url({{ site.page-img }}); background-image: url({{ site.page-img | relative_url }});
background-attachment: fixed; background-attachment: fixed;
{% endif %} {% endif %}
} }
@ -110,7 +110,7 @@ img {
border-bottom: 1px solid #EAEAEA; border-bottom: 1px solid #EAEAEA;
font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif; font-family: 'Open Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
{% if site.navbar-img %} {% if site.navbar-img %}
background-image: url({{ site.navbar-img }}); background-image: url({{ site.navbar-img | relative_url }});
background-attachment: fixed; background-attachment: fixed;
{% endif %} {% endif %}
} }
@ -267,7 +267,7 @@ footer {
font-size: 14px; font-size: 14px;
background-color: {{ site.footer-col }}; background-color: {{ site.footer-col }};
{% if site.footer-img %} {% if site.footer-img %}
background-image: url({{ site.footer-img }}); background-image: url({{ site.footer-img | relative_url }});
background-attachment: fixed; background-attachment: fixed;
{% endif %} {% endif %}
} }

View File

@ -8,7 +8,7 @@ use-site-title: true
<div class="posts-list"> <div class="posts-list">
{% for post in paginator.posts %} {% for post in paginator.posts %}
<article class="post-preview"> <article class="post-preview">
<a href="{{ post.url | prepend: site.baseurl }}"> <a href="{{ post.url | relative_url }}">
<h2 class="post-title">{{ post.title }}</h2> <h2 class="post-title">{{ post.title }}</h2>
{% if post.subtitle %} {% if post.subtitle %}
@ -25,7 +25,7 @@ use-site-title: true
<div class="post-entry-container"> <div class="post-entry-container">
{% if post.image %} {% if post.image %}
<div class="post-image"> <div class="post-image">
<a href="{{ post.url | prepend: site.baseurl }}"> <a href="{{ post.url | relative_url }}">
<img src="{{ post.image }}"> <img src="{{ post.image }}">
</a> </a>
</div> </div>
@ -34,7 +34,7 @@ use-site-title: true
{{ post.excerpt | strip_html | xml_escape | truncatewords: site.excerpt_length }} {{ post.excerpt | strip_html | xml_escape | truncatewords: site.excerpt_length }}
{% assign excerpt_word_count = post.excerpt | number_of_words %} {% assign excerpt_word_count = post.excerpt | number_of_words %}
{% if post.content != post.excerpt or excerpt_word_count > site.excerpt_length %} {% if post.content != post.excerpt or excerpt_word_count > site.excerpt_length %}
<a href="{{ post.url | prepend: site.baseurl }}" class="post-read-more">[Read&nbsp;More]</a> <a href="{{ post.url | relative_url }}" class="post-read-more">[Read&nbsp;More]</a>
{% endif %} {% endif %}
</div> </div>
</div> </div>
@ -44,7 +44,7 @@ use-site-title: true
Tags: Tags:
{% if site.link-tags %} {% if site.link-tags %}
{% for tag in post.tags %} {% for tag in post.tags %}
<a href="{{ site.baseurl }}/tags#{{- tag -}}">{{- tag -}}</a> <a href="{{ '/tags' | relative_url }}#{{- tag -}}">{{- tag -}}</a>
{% endfor %} {% endfor %}
{% else %} {% else %}
{{ post.tags | join: ", " }} {{ post.tags | join: ", " }}
@ -60,12 +60,12 @@ use-site-title: true
<ul class="pager main-pager"> <ul class="pager main-pager">
{% if paginator.previous_page %} {% if paginator.previous_page %}
<li class="previous"> <li class="previous">
<a href="{{ paginator.previous_page_path | prepend: site.baseurl | replace: '//', '/' }}">&larr; Newer Posts</a> <a href="{{ paginator.previous_page_path | relative_url }}">&larr; Newer Posts</a>
</li> </li>
{% endif %} {% endif %}
{% if paginator.next_page %} {% if paginator.next_page %}
<li class="next"> <li class="next">
<a href="{{ paginator.next_page_path | prepend: site.baseurl | replace: '//', '/' }}">Older Posts &rarr;</a> <a href="{{ paginator.next_page_path | relative_url }}">Older Posts &rarr;</a>
</li> </li>
{% endif %} {% endif %}
</ul> </ul>