Skip to content

Commit

Permalink
add previous and next blogs
Browse files Browse the repository at this point in the history
  • Loading branch information
moiSentineL committed Feb 13, 2024
1 parent 4ddae49 commit 739c654
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ module.exports = function(eleventyConfig) {

eleventyConfig.setLibrary("md", markdownLib);

eleventyConfig.addCollection("posts", function(collection) {
const coll = collection.getFilteredByTag("post");

for(let i = 0; i < coll.length ; i++) {
const prevPost = coll[i-1];
const nextPost = coll[i + 1];

coll[i].data["prevPost"] = prevPost;
coll[i].data["nextPost"] = nextPost;
}

return coll;
});

return {
dir: {
input: 'src',
Expand Down
12 changes: 12 additions & 0 deletions src/_includes/post.njk
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,16 @@ tags:
{{ content | safe }}

<hr>
{% if nextPost.url %}
<p>
<strong>Next</strong>:
<a class="next" href="{{ nextPost.url }}">{{ nextPost.data.title }}</a>
</p>
{% endif %}
{% if prevPost.url %}
<p>
<strong>Previous</strong>:
<a class="previous" href="{{ prevPost.url }}">{{ prevPost.data.title }}</a>
</p>
{% endif %}
</article>
1 change: 1 addition & 0 deletions src/css/css.css
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,6 @@ footer{
font-size: small;
text-align: center;
padding: 25px;
padding-top: 0.5em;
}

0 comments on commit 739c654

Please sign in to comment.