Skip to content

Commit 9e146a0

Browse files
authored
Make latest post redirect if the blog post redirects (alshedivat#1451)
Fixes alshedivat#1450, and the behavior of the site with this "new" code is shown in the Expected behavior screenshots there. I copy-pasted the redirect logic from `blog/index.html` into `_includes/latest_posts.html`, with minor name changes. I also cleaned up a line in `blog/index.html`.
1 parent 3083172 commit 9e146a0

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

_includes/latest_posts.html

+10-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@
1414
<tr>
1515
<th scope="row">{{ item.date | date: "%b %-d, %Y" }}</th>
1616
<td>
17-
<a class="news-title" href="{{ item.url | relative_url }}">{{ item.title }}</a>
17+
{% if item.redirect == blank %}
18+
<a class="news-title" href="{{ item.url | relative_url }}">{{ item.title }}</a>
19+
{% elsif item.redirect contains '://' %}
20+
<a class="news-title" href="{{ item.redirect }}" target="_blank">{{ item.title }}</a>
21+
<svg width="2rem" height="2rem" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg">
22+
<path d="M17 13.5v6H5v-12h6m3-3h6v6m0-6-9 9" class="icon_svg-stroke" stroke="#999" stroke-width="1.5" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path>
23+
</svg>
24+
{% else %}
25+
<a class="news-title" href="{{ item.redirect | relative_url }}">{{ item.title }}</a>
26+
{% endif %}
1827
</td>
1928
</tr>
2029
{%- endfor %}

blog/index.html

+7-9
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,14 @@ <h2>{{ site.blog_description }}</h2>
5959
{%- endif -%}
6060
<h3>
6161
{% if post.redirect == blank %}
62-
<a class="post-title" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
62+
<a class="post-title" href="{{ post.url | relative_url }}">{{ post.title }}</a>
63+
{% elsif post.redirect contains '://' %}
64+
<a class="post-title" href="{{ post.redirect }}" target="_blank">{{ post.title }}</a>
65+
<svg width="2rem" height="2rem" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg">
66+
<path d="M17 13.5v6H5v-12h6m3-3h6v6m0-6-9 9" class="icon_svg-stroke" stroke="#999" stroke-width="1.5" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path>
67+
</svg>
6368
{% else %}
64-
{% if post.redirect contains '://' %}
65-
<a class="post-title" href="{{ post.redirect }}" target="_blank">{{ post.title }}</a>
66-
<svg width="2rem" height="2rem" viewBox="0 0 40 40" xmlns="http://www.w3.org/2000/svg">
67-
<path d="M17 13.5v6H5v-12h6m3-3h6v6m0-6-9 9" class="icon_svg-stroke" stroke="#999" stroke-width="1.5" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path>
68-
</svg>
69-
{% else %}
70-
<a class="post-title" href="{{ post.redirect | relative_url }}">{{ post.title }}</a>
71-
{% endif %}
69+
<a class="post-title" href="{{ post.redirect | relative_url }}">{{ post.title }}</a>
7270
{% endif %}
7371
</h3>
7472
<p>{{ post.description }}</p>

0 commit comments

Comments
 (0)