From e4ceee207b3732f55d79dad3f11bc7f277f65d5d Mon Sep 17 00:00:00 2001 From: Frankie Roberto Date: Tue, 24 Sep 2024 21:49:49 +0100 Subject: [PATCH 1/4] Fix feed by not using pagination I think this should resolve #330 but need to test it somehow. --- docs/feed.md | 8 +++----- layouts/feed.njk | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/docs/feed.md b/docs/feed.md index 8c07c264..f9e60d97 100644 --- a/docs/feed.md +++ b/docs/feed.md @@ -16,10 +16,8 @@ To create a feed, add a file named `feed.njk` with the following content: eleventyExcludeFromCollections: true layout: feed permalink: /feed.xml -pagination: - data: collections.post - size: 20 - reverse: true +collection: post +size: 20 --- ``` @@ -27,7 +25,7 @@ The `permalink` value is the location of the generated feed. ## Create a collection of pages -The feed will include all pages in the collection referenced by the `data` key of the `pagination` object. +The feed will include pages in the collection referenced in the `collection` key, up to a maximum specified in `size`, with the newest first. You can create a collection by adding some code to your `eleventy.config.js`: diff --git a/layouts/feed.njk b/layouts/feed.njk index 87f9d12e..a5dc737f 100644 --- a/layouts/feed.njk +++ b/layouts/feed.njk @@ -3,9 +3,9 @@ {{ options.homeKey }} - {{ collections.post | getNewestCollectionItemDate | dateToRfc3339 }} + {{ collections[collection] | getNewestCollectionItemDate | dateToRfc3339 }} {{ options.url }}/ - {%- for item in pagination.items %} + {%- for item in (collections[collection] | sort(true, false, "date") | slice(size)) %} {%- set absolutePostUrl = item.url | canonicalUrl %} {{ item.data.title }} From e66ea68e47910d228e41a33b9ad56ec46dabe75f Mon Sep 17 00:00:00 2001 From: Frankie Roberto Date: Sat, 5 Oct 2024 15:04:11 +0100 Subject: [PATCH 2/4] Use an if condition instead of slice --- layouts/feed.njk | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/layouts/feed.njk b/layouts/feed.njk index a5dc737f..3d44004a 100644 --- a/layouts/feed.njk +++ b/layouts/feed.njk @@ -5,29 +5,31 @@ {{ collections[collection] | getNewestCollectionItemDate | dateToRfc3339 }} {{ options.url }}/ - {%- for item in (collections[collection] | sort(true, false, "date") | slice(size)) %} - {%- set absolutePostUrl = item.url | canonicalUrl %} - - {{ item.data.title }} - - {{ item.date | dateToRfc3339 }} - {{ absolutePostUrl }} - {% if item.data.authors %} - {% for author in item.data.authors %} + {%- for item in (collections[collection] | sort(true, false, "date") %} + {%- if loop.index0 < size %} + {%- set absolutePostUrl = item.url | canonicalUrl %} + + {{ item.data.title }} + + {{ item.date | dateToRfc3339 }} + {{ absolutePostUrl }} + {% if item.data.authors %} + {% for author in item.data.authors %} + + {{ author.name }} + {% if author.url %}{{ author.url }}{% endif %} + + {% endfor %} + {% elif item.data.author %} - {{ author.name }} - {% if author.url %}{{ author.url }}{% endif %} + {{ item.data.author.name }} + {% if item.data.author.url %}{{ item.data.author.url }}{% endif %} - {% endfor %} - {% elif item.data.author %} - - {{ item.data.author.name }} - {% if item.data.author.url %}{{ item.data.author.url }}{% endif %} - - {% endif %} - - - - + {% endif %} + + + + + {%- endif %} {%- endfor %} From 81a5c431891f56d5df53ecac146c46c547f968aa Mon Sep 17 00:00:00 2001 From: Frankie Roberto Date: Sat, 5 Oct 2024 15:06:21 +0100 Subject: [PATCH 3/4] Temporarily remove dates --- layouts/feed.njk | 2 -- 1 file changed, 2 deletions(-) diff --git a/layouts/feed.njk b/layouts/feed.njk index 3d44004a..51a92901 100644 --- a/layouts/feed.njk +++ b/layouts/feed.njk @@ -3,7 +3,6 @@ {{ options.homeKey }} - {{ collections[collection] | getNewestCollectionItemDate | dateToRfc3339 }} {{ options.url }}/ {%- for item in (collections[collection] | sort(true, false, "date") %} {%- if loop.index0 < size %} @@ -11,7 +10,6 @@ {{ item.data.title }} - {{ item.date | dateToRfc3339 }} {{ absolutePostUrl }} {% if item.data.authors %} {% for author in item.data.authors %} From ace23007a13f66801134474c8019f89767a273c0 Mon Sep 17 00:00:00 2001 From: Frankie Roberto Date: Sat, 5 Oct 2024 15:08:45 +0100 Subject: [PATCH 4/4] temporarily remove sort --- layouts/feed.njk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/layouts/feed.njk b/layouts/feed.njk index 51a92901..5a914d5b 100644 --- a/layouts/feed.njk +++ b/layouts/feed.njk @@ -4,7 +4,7 @@ {{ options.url }}/ - {%- for item in (collections[collection] | sort(true, false, "date") %} + {%- for item in (collections[collection] %} {%- if loop.index0 < size %} {%- set absolutePostUrl = item.url | canonicalUrl %}