volpe/post-redirects.njk

36 lines
No EOL
1.2 KiB
Text

---
pagination:
data: collections.postsBySlug
size: 1
alias: slugData
resolve: keys
permalink: /post/{{ slugData }}/
layout: base.njk
---
{% set posts = collections.postsBySlug[slugData] %}
{% if posts.length == 1 %}
{# Single post - redirect to the dated version #}
<meta http-equiv="refresh" content="0; url=/post/{{ slugData }}/{{ posts[0].data.createdAt | isoDate }}/">
<script>window.location.href = "/post/{{ slugData }}/{{ posts[0].data.createdAt | isoDate }}/";</script>
<p>Redirecting to <a href="/post/{{ slugData }}/{{ posts[0].data.createdAt | isoDate }}/">{{ posts[0].data.title }}</a>...</p>
{% else %}
{# Multiple posts with same title - show disambiguation page #}
<h1>{{ posts[0].data.title }}</h1>
<p>There are multiple posts with this title. Please select the one you're looking for:</p>
<ul class="post-list">
{% for post in posts %}
<li>
<a href="/post/{{ slugData }}/{{ post.data.createdAt | isoDate }}/" class="post-card">
<h2>{{ post.data.title }}</h2>
<time datetime="{{ post.data.createdAt | dateFormat }}">{{ post.data.createdAt | dateFormat }}</time>
{% if post.data.description %}
<p>{{ post.data.description }}</p>
{% endif %}
</a>
</li>
{% endfor %}
</ul>
{% endif %}