From 8bcfcd697f24fb98aebecc5235df0f9e3f300330 Mon Sep 17 00:00:00 2001 From: Gordon Pedersen Date: Thu, 8 Dec 2022 16:43:24 +1100 Subject: [PATCH] added rss, atom and json feeds --- .eleventy.js | 10 +- _content/_includes/macro-entry.njk | 84 +---- _content/_includes/macro-summary.njk | 83 +++++ _content/feed/atom.njk | 44 +++ _content/feed/index.html | 3 +- _content/feed/json.njk | 42 +++ _content/feed/rss.njk | 42 +++ _content/index.html | 1 + package-lock.json | 443 +++++++++++++++++++++++++-- package.json | 7 +- 10 files changed, 645 insertions(+), 114 deletions(-) create mode 100644 _content/_includes/macro-summary.njk create mode 100644 _content/feed/atom.njk create mode 100644 _content/feed/json.njk create mode 100644 _content/feed/rss.njk diff --git a/.eleventy.js b/.eleventy.js index 4fddaa4..6cdddce 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,3 +1,5 @@ +const pluginRss = require("@11ty/eleventy-plugin-rss"); + module.exports = function(eleventyConfig) { eleventyConfig.addFilter("formatDate", function(value) { @@ -24,6 +26,10 @@ module.exports = function(eleventyConfig) { } }); + eleventyConfig.addFilter("concat", function(value, other) { + return value + '' + other + }); + eleventyConfig.addCollection("notes", function(collectionApi) { return collectionApi.getFilteredByGlob("_content/notes/*.md").reverse(); }); @@ -89,6 +95,8 @@ module.exports = function(eleventyConfig) { eleventyConfig.addPassthroughCopy("css"); eleventyConfig.addPassthroughCopy("CNAME"); + eleventyConfig.addPlugin(pluginRss); + // Return your Object options: return { dir: { @@ -96,6 +104,6 @@ module.exports = function(eleventyConfig) { output: "pub" }, htmlTemplateEngine: "njk", - templateFormats: ["md","html"] + templateFormats: ["md","html","njk"] } }; \ No newline at end of file diff --git a/_content/_includes/macro-entry.njk b/_content/_includes/macro-entry.njk index cc61520..0fc100e 100644 --- a/_content/_includes/macro-entry.njk +++ b/_content/_includes/macro-entry.njk @@ -1,91 +1,11 @@ {% from "macro-card-head.njk" import cardHeadMacro %} +{% from "macro-summary.njk" import summaryMacro %} {% macro entryMacro(item, url, content, summaryOnly=false) %}
{{ cardHeadMacro(item.author, item.date, url) }}
- {% switch item.postType %} - {% case "article" %} {# article summary: #} -

- {{ item.name if item.name else item.title }} -

- {% if item.summary %} -

{{ item.summary | safe }}

- {% endif %} - - {% case "reply" %} {# reply summary: #} -

Reply to {{ item["in-reply-to"] }}

- - {% case "like" %} {# like summary: #} -

Favourited {{ item['like-of'] }}

- - {% case "boost" %} {# boost summary: #} -

Boosted {{ item["repost-of"] }}

- - {% case "bookmark" %} {# bookmark summary: #} -

Bookmarked {{ item["bookmark-of"] }}

- - {% case "read" %} {# read summary: #} -

- {% if item["read-status"].toLowerCase() == "to-read" %} - To Read: - - {% elseif item["read-status"].toLowerCase() == "reading" %} - Currently Reading: - - {% elseif item["read-status"].toLowerCase() == "finished" %} - Finished Reading: - - {% endif %} - - {% if item["read-of"].startsWith("http") %} - {{ item["read-of"] }} - {% else %} - {{ item["read-of"] }} - {% endif %} -

- - {% case "watch" %} {# watch summary: #} -

- {% if item["watch-status"].toLowerCase() == "to-watch" %} - To Watch: - {% elseif item["watch-status"].toLowerCase() == "watching" %} - Currently Watching: - {% elseif item["watch-status"].toLowerCase() == "watched" or item["watch-status"].toLowerCase() == "finished" %} - Finished watching: - {% else %} - Watched: - {% endif %} - - - {% if item["watch-of"].startsWith("http") %} - {{ item["watch-of"] }} - {% else %} - {{ item["watch-of"] }} - {% endif %} -

- - {% case "rsvp" %} {# rsvp summary: #} -

- - {% if item.rsvp.toLowerCase() == "yes" %} - - Will attend - {% elseif item.rsvp.toLowerCase() == "maybe" %} - - Might attend - {% elseif item.rsvp.toLowerCase() == "no" %} - - Won't attend - {% elseif item.rsvp.toLowerCase() == "interested" %} - - Interested in - {% endif %} - - {{ item["in-reply-to"] }} -

- {% endswitch %} - + {{ summaryMacro(item, url) }} {% if item.postType == 'article' and summaryOnly %} {% elseif content %}
{{ content | safe }}
diff --git a/_content/_includes/macro-summary.njk b/_content/_includes/macro-summary.njk new file mode 100644 index 0000000..e395c33 --- /dev/null +++ b/_content/_includes/macro-summary.njk @@ -0,0 +1,83 @@ +{% macro summaryMacro(item, url) %} +{% switch item.postType %} + {% case "article" %} {# article summary: #} +

+ {{ item.name if item.name else item.title }} +

+ {% if item.summary %} +

{{ item.summary | safe }}

+ {% endif %} + + {% case "reply" %} {# reply summary: #} +

Reply to {{ item["in-reply-to"] }}

+ + {% case "like" %} {# like summary: #} +

Favourited {{ item['like-of'] }}

+ + {% case "boost" %} {# boost summary: #} +

Boosted {{ item["repost-of"] }}

+ + {% case "bookmark" %} {# bookmark summary: #} +

Bookmarked {{ item["bookmark-of"] }}

+ + {% case "read" %} {# read summary: #} +

+ {% if item["read-status"].toLowerCase() == "to-read" %} + To Read: + + {% elseif item["read-status"].toLowerCase() == "reading" %} + Currently Reading: + + {% elseif item["read-status"].toLowerCase() == "finished" %} + Finished Reading: + + {% endif %} + + {% if item["read-of"].startsWith("http") %} + {{ item["read-of"] }} + {% else %} + {{ item["read-of"] }} + {% endif %} +

+ + {% case "watch" %} {# watch summary: #} +

+ {% if item["watch-status"].toLowerCase() == "to-watch" %} + To Watch: + {% elseif item["watch-status"].toLowerCase() == "watching" %} + Currently Watching: + {% elseif item["watch-status"].toLowerCase() == "watched" or item["watch-status"].toLowerCase() == "finished" %} + Finished watching: + {% else %} + Watched: + {% endif %} + + + {% if item["watch-of"].startsWith("http") %} + {{ item["watch-of"] }} + {% else %} + {{ item["watch-of"] }} + {% endif %} +

+ + {% case "rsvp" %} {# rsvp summary: #} +

+ + {% if item.rsvp.toLowerCase() == "yes" %} + + Will attend + {% elseif item.rsvp.toLowerCase() == "maybe" %} + + Might attend + {% elseif item.rsvp.toLowerCase() == "no" %} + + Won't attend + {% elseif item.rsvp.toLowerCase() == "interested" %} + + Interested in + {% endif %} + + {{ item["in-reply-to"] }} +

+ {% endswitch %} +{% endmacro %} \ No newline at end of file diff --git a/_content/feed/atom.njk b/_content/feed/atom.njk new file mode 100644 index 0000000..a841ad6 --- /dev/null +++ b/_content/feed/atom.njk @@ -0,0 +1,44 @@ +---json +{ + "layout": null, + "permalink": "atom.xml", + "eleventyExcludeFromCollections": true, + "metadata": { + "title": "Mon Repos (Death's Domain)", + "subtitle": "A feed of all my posts on the fediverse", + "language": "en", + "url": "https://death.id.au/", + "author": { + "name": "Gordon Pedersen", + "email": "death.au@death.id.au" + } + } +} +--- + +{% from "macro-summary.njk" import summaryMacro %} + + {{ metadata.title }} + {{ metadata.subtitle }} + + + {{ collections.feed[0].date | dateToRfc822 }} + {{ metadata.url }} + + {{ metadata.author.name }} + {{ metadata.author.email }} + + {%- for post in collections.feed %} + {%- set absolutePostUrl = post.url | absoluteUrl(metadata.url) %} + + {{ post.data.title }} + + {{ post.date | dateToRfc822 }} + {{ absolutePostUrl }} + + {{ summaryMacro(post.data, post.url) | htmlToAbsoluteUrls(absolutePostUrl) }} + {{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) }} + + + {%- endfor %} + \ No newline at end of file diff --git a/_content/feed/index.html b/_content/feed/index.html index 4aaed47..26cbde9 100644 --- a/_content/feed/index.html +++ b/_content/feed/index.html @@ -4,13 +4,14 @@ layout: layout-feed.njk pagination: data: collections.feed size: 20 +eleventyExcludeFromCollections: true --- {% from "macro-entry.njk" import entryMacro %}
    {% for item in pagination.items %}
  • - {{ entryMacro(item.data, item.url, item.templateContent) }} + {{ entryMacro(item.data, item.url, item.templateContent, true) }}
  • {% endfor %}
diff --git a/_content/feed/json.njk b/_content/feed/json.njk new file mode 100644 index 0000000..b2400a7 --- /dev/null +++ b/_content/feed/json.njk @@ -0,0 +1,42 @@ +---json +{ + "layout": null, + "permalink": "feed.json", + "eleventyExcludeFromCollections": true, + "metadata": { + "title": "Mon Repos (Death's Domain)", + "subtitle": "A feed of all my posts on the fediverse", + "language": "en", + "url": "https://death.id.au/", + "author": { + "name": "Gordon Pedersen", + "email": "death.au@death.id.au" + } + } +} +--- +{ {% from "macro-summary.njk" import summaryMacro %} + "version": "https://jsonfeed.org/version/1.1", + "title": "{{ metadata.title }}", + "language": "{{ metadata.language }}", + "home_page_url": "{{ metadata.url }}", + "feed_url": "{{ permalink | absoluteUrl(metadata.url) }}", + "description": "{{ metadata.subtitle }}", + "author": { + "name": "{{ metadata.author.name }}", + "url": "{{ metadata.author.url }}" + }, + "items": [ + {%- for post in collections.feed %} + {%- set absolutePostUrl = post.url | absoluteUrl(metadata.url) %} + { + "id": "{{ absolutePostUrl }}", + "url": "{{ absolutePostUrl }}", + "title": "{{ post.data.title }}", + "content_html": {{ summaryMacro(post.data, post.url) | concat(post.templateContent) | htmlToAbsoluteUrls(absolutePostUrl) | dump | safe }}, + "date_published": "{{ post.date | dateToRfc3339 }}" + } + {% if not loop.last %},{% endif %} + {%- endfor %} + ] +} \ No newline at end of file diff --git a/_content/feed/rss.njk b/_content/feed/rss.njk new file mode 100644 index 0000000..97fc0b2 --- /dev/null +++ b/_content/feed/rss.njk @@ -0,0 +1,42 @@ +---json +{ + "layout": null, + "permalink": "rss.xml", + "eleventyExcludeFromCollections": true, + "metadata": { + "title": "Mon Repos (Death's Domain)", + "subtitle": "A feed of all my posts on the fediverse", + "language": "en", + "url": "https://death.id.au/", + "author": { + "name": "Gordon Pedersen", + "email": "death.au@death.id.au" + } + } +} +--- + +{% from "macro-summary.njk" import summaryMacro %} + + + {{ metadata.title }} + {{ metadata.url }} + + {{ metadata.subtitle }} + {{ metadata.language }} + {%- for post in collections.feed | reverse %} + {%- set absolutePostUrl = post.url | absoluteUrl(metadata.url) %} + + {{ post.data.title }} + {{ absolutePostUrl }} + + {{ summaryMacro(post.data, post.url) | htmlToAbsoluteUrls(absolutePostUrl) }} + {{ post.templateContent | htmlToAbsoluteUrls(absolutePostUrl) }} + + {{ post.date | dateToRfc822 }} + {{ metadata.author.name }} + {{ absolutePostUrl }} + + {%- endfor %} + + diff --git a/_content/index.html b/_content/index.html index 39ca0c8..a72b5d0 100644 --- a/_content/index.html +++ b/_content/index.html @@ -1,5 +1,6 @@ --- layout: layout-main.njk +eleventyExcludeFromCollections: true ---