Skip to content
This repository has been archived by the owner on Aug 28, 2019. It is now read-only.

Image path pseudo function #131

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

{% if site.owner.twitter %}<!-- Twitter Cards -->
{% if page.image.feature %}<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="{{ site.url }}/images/{{ page.image.feature }}">
<meta name="twitter:image" content="{% include image_path image=page.image.feature %}">
{% else %}<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="{% if page.image.thumb %}{{ site.url }}/images/{{ page.image.thumb }}{% else %}{{ site.url }}/images/{{ site.logo }}{% endif %}">{% endif %}
<meta name="twitter:image" content="{% if page.image.thumb %}{% include image_path image=page.image.thumb %}{% else %}{% include image_path image=site.logo %}{% endif %}">{% endif %}
<meta name="twitter:title" content="{% if page.title %}{{ page.title }}{% else %}{{ site.title }}{% endif %}">
<meta name="twitter:description" content="{% if page.description %}{{ page.description }}{% else %}{{ site.description }}{% endif %}">
<meta name="twitter:creator" content="@{{ site.owner.twitter }}">{% endif %}
Expand Down Expand Up @@ -58,6 +58,5 @@

{% if page.image.background or site.background %}
{% capture background %}{% if page.image.background %}{{ page.image.background }}{% else %}{{ site.background }}{% endif %}{% endcapture %}
{% unless background contains 'http://' or background contains 'https://' %}{% capture background %}{{ site.url }}/images/{{ background }}{% endcapture %}{% endunless %}
<style type="text/css">body {background-image:url({{ background }});}</style>
<style type="text/css">body {background-image:url({% include image_path image=background %});}</style>
{% endif %}
11 changes: 11 additions & 0 deletions _includes/image_path
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% comment %}
This file will prepend the image path `{{site.url}}/images/` to any image
that does not have two slashes `//` in the path. That way, an image url that
points to another website won't automatically have this website mistakenly
added to the front of the url.

A string beginning with a single slash will be prepended with {{ site.url }}

This file must NOT have an extra carriage return at the end.

{% endcomment %}{% capture first %}{{ include.image | truncate: 1, '' }}{% endcapture %}{% if include.image contains '//' %}{{ include.image }}{% elsif first == '/' %}{{ site.url }}{{ include.image }}{% else %}{{ site.url }}/images/{{ include.image }}{% endif %}
2 changes: 1 addition & 1 deletion _includes/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<a href="#">About</a>
<ul class="dl-submenu">
<li>
<img src="{{ site.url }}/images/{{ site.owner.avatar }}" alt="{{ site.owner.name }} photo" class="author-photo">
<img src="{% include image_path image=site.owner.avatar %}" alt="{{ site.owner.name }} photo" class="author-photo">
<h4>{{ site.owner.name }}</h4>
<p>{{ site.owner.bio }}</p>
</li>
Expand Down
2 changes: 1 addition & 1 deletion _layouts/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="entry-header">
{% if page.image.credit %}<div class="image-credit">Image source: <a href="{{ page.image.creditlink }}">{{ page.image.credit }}</a></div><!-- /.image-credit -->{% endif %}
<div class="entry-image">
<img src="{{ site.url }}/images/{{ page.image.feature }}" alt="{{ page.title }}">
<img src="{% include image_path image=page.image.feature %}" alt="{{ page.title }}">
</div><!-- /.entry-image -->
</div><!-- /.entry-header -->
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion _layouts/post-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{% if page.image.credit %}<div class="image-credit">Image source: <a href="{{ page.image.creditlink }}">{{ page.image.credit }}</a></div><!-- /.image-credit -->{% endif %}
{% if page.image.feature %}
<div class="entry-image">
<img src="{{ site.url }}/images/{{ page.image.feature }}" alt="{{ page.title }}">
<img src="{% include image_path image=page.image.feature %}" alt="{{ page.title }}">
</div><!-- /.entry-image -->
{% endif %}
<div class="header-title">
Expand Down
2 changes: 1 addition & 1 deletion _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="entry-header">
{% if page.image.credit %}<div class="image-credit">Image source: {% if page.image.creditlink %}<a href="{{ page.image.creditlink }}">{% endif %}{{ page.image.credit }}{% if page.image.creditlink %}</a>{% endif %}</div><!-- /.image-credit -->{% endif %}
<div class="entry-image">
<img src="{{ site.url }}/images/{{ page.image.feature }}" alt="{{ page.title }}">
<img src="{% include image_path image=page.image.feature %}" alt="{{ page.title }}">
</div><!-- /.entry-image -->
</div><!-- /.entry-header -->
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<header>
{% if post.image.feature %}
<div class="entry-image-index">
<a href="{{ site.url }}{{ post.url }}" title="{{ post.title }}"><img src="{{ site.url }}/images/{{ post.image.feature }}" alt="{{ post.title }}"></a>
<a href="{{ site.url }}{{ post.url }}" title="{{ post.title }}"><img src="{% include image_path image=post.image.feature %}" alt="{{ post.title }}"></a>
</div><!-- /.entry-image -->
{% endif %}
<div class="entry-meta">
Expand Down