From 9fa74580627ee0b3a49342cd5bfb6b980d0c96ff Mon Sep 17 00:00:00 2001 From: Zach Leatherman Date: Mon, 30 Jan 2023 17:11:37 -0600 Subject: [PATCH] Centralize the number of posts to show to front matter --- content/index.njk | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/content/index.njk b/content/index.njk index 103f210..c23cd54 100644 --- a/content/index.njk +++ b/content/index.njk @@ -3,17 +3,19 @@ layout: layouts/home.njk eleventyNavigation: key: Home order: 1 +numberOfLatestPostsToShow: 3 --- {% set postsCount = collections.posts | length %} -{% set latestPostsCount = postsCount | min(3) %} +{% set latestPostsCount = postsCount | min(numberOfLatestPostsToShow) %}

Latest {{ latestPostsCount }} Post{% if latestPostsCount != 1 %}s{% endif %}

-{% set postslist = collections.posts | head(-3) %} +{% set postslist = collections.posts | head(-1 * numberOfLatestPostsToShow) %} {% set postslistCounter = postsCount %} {% include "postslist.njk" %} -{% if postsCount > 3 %} -

More posts can be found in the archive.

+{% set morePosts = postsCount - numberOfLatestPostsToShow %} +{% if morePosts > 0 %} +

{{ morePosts }} more post{% if morePosts != 1 %}s{% endif %} can be found in the archive.

{% endif %} {# List every content page in the project #}