From 69a8dfc24fc1c3d27cc2f4cfbc162028125c7e70 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Wed, 6 Sep 2023 12:33:19 -0700 Subject: [PATCH] feat: make json feed reusable --- src/_includes/partials/feeds/json.liquid | 18 ++++++++++++++++ src/feeds/{books.md => books.liquid} | 0 src/feeds/{feed.md => feed.liquid} | 2 +- src/feeds/follow.json.liquid | 26 ++++++++---------------- src/feeds/{follow.md => follow.liquid} | 0 src/feeds/{links.md => links.liquid} | 0 6 files changed, 27 insertions(+), 19 deletions(-) create mode 100644 src/_includes/partials/feeds/json.liquid rename src/feeds/{books.md => books.liquid} (100%) rename src/feeds/{feed.md => feed.liquid} (81%) rename src/feeds/{follow.md => follow.liquid} (100%) rename src/feeds/{links.md => links.liquid} (100%) diff --git a/src/_includes/partials/feeds/json.liquid b/src/_includes/partials/feeds/json.liquid new file mode 100644 index 00000000..8a95f245 --- /dev/null +++ b/src/_includes/partials/feeds/json.liquid @@ -0,0 +1,18 @@ +{% assign entries = data | normalizeEntries %} +{ + "version": "https://jsonfeed.org/version/1", + "title": "{{ title }}", + "icon": "https://coryd.dev/static/images/avatar.webp", + "home_page_url": "{{ site.url }}", + "feed_url": "{{ site.url }}{{ permalink }}", + "items": [{% for entry in entries limit: 20 -%} + { + "id": "{{ entry.id }}", + "title": "{{ entry.title | escape }}", + "url": "{{ entry.url }}", + "content_text": "{{ entry.title }} {{ entry.url }}", + "date_published": "{{ entry.date | date: "%Y-%m-%dT%H:%M:%S-08:00" }}" + }{% if not forloop.last %},{% endif %} + {%- endfor %} + ] +} \ No newline at end of file diff --git a/src/feeds/books.md b/src/feeds/books.liquid similarity index 100% rename from src/feeds/books.md rename to src/feeds/books.liquid diff --git a/src/feeds/feed.md b/src/feeds/feed.liquid similarity index 81% rename from src/feeds/feed.md rename to src/feeds/feed.liquid index 43a418ce..d1decc87 100644 --- a/src/feeds/feed.md +++ b/src/feeds/feed.liquid @@ -2,7 +2,7 @@ layout: null permalink: /feeds/posts --- -{% assign posts = collections.posts | reverse %} +{%- assign posts = collections.posts | reverse -%} {% render "partials/feeds/content.liquid" permalink:'/feeds/posts' title:'All posts • Cory Dransfeldt' diff --git a/src/feeds/follow.json.liquid b/src/feeds/follow.json.liquid index 92401276..1d3e9891 100644 --- a/src/feeds/follow.json.liquid +++ b/src/feeds/follow.json.liquid @@ -1,21 +1,11 @@ --- +layout: null permalink: /feeds/follow.json --- -{% assign posts = follow.posts %} -{ -"version": "https://jsonfeed.org/version/1", -"title": "All activity • Cory Dransfeldt", -"icon": "https://coryd.dev/static/images/avatar.webp", -"home_page_url": "https://coryd.dev", -"feed_url": "https://coryd.dev/follow.json", -"items": [{% for item in posts %} - { - "id": "{{ item.id }}", - "title": "{{ item.title }}", - "url": "{{ item.url }}", - "content_text": "{{ item.title }} {{ item.url }}", - "date_published": "{{ item.date_published | date: "%Y-%m-%dT%H:%M:%S-08:00" }}" - }{% if not forloop.last %},{% endif %} -{% endfor %} -] -} \ No newline at end of file +{% render "partials/feeds/json.liquid" + permalink:'/feeds/follow' + title:'Follow • Cory Dransfeldt' + data:follow.posts + updated:follow.posts[0].date_published + site:site +%} \ No newline at end of file diff --git a/src/feeds/follow.md b/src/feeds/follow.liquid similarity index 100% rename from src/feeds/follow.md rename to src/feeds/follow.liquid diff --git a/src/feeds/links.md b/src/feeds/links.liquid similarity index 100% rename from src/feeds/links.md rename to src/feeds/links.liquid