Add previous and next blog post section

This commit is contained in:
Helen Chong 2024-04-17 01:36:56 +08:00
parent 804126d745
commit 1cfbe2d61d
2 changed files with 27 additions and 1 deletions

View File

@ -0,0 +1,26 @@
---
layout: main/article
---
{{ content | safe }}
{%- if collections.posts %}
{%- set previousPost = collections.posts | getPreviousCollectionItem %}
{%- set nextPost = collections.posts | getNextCollectionItem %}
{%- if nextPost or previousPost %}
<ul class="blog__post--nextprev">
{%- if previousPost %}<li>Previous Post: <a href="{{ previousPost.url }}">{{ previousPost.data.articleTitle }}</a></li>{% endif %}
{%- if nextPost %}<li>Next Post: <a href="{{ nextPost.url }}">{{ nextPost.data.articleTitle }}</a></li>{% endif %}
</ul>
{%- endif %}
{%- endif %}
<style>
.blog__post--nextprev {
list-style: none;
padding-left: 0;
padding-top: 0.8em;
margin-top: 2.5em;
border-top: 0.1em solid var(--clr-title-border);
}
</style>

View File

@ -1,5 +1,5 @@
{
"layout": "main/article",
"layout": "main/blogpost",
"tags": ["posts", "contents", "feed items"],
"eleventyComputed": {
"title": "{{ articleTitle }} | Blog"