feat: consolidate all feeds into a single template and normalize inputs

This commit is contained in:
Cory Dransfeldt 2023-09-06 11:49:40 -07:00
parent 638f784eb7
commit 517e849ef5
No known key found for this signature in database
18 changed files with 104 additions and 154 deletions

View file

@ -89,6 +89,7 @@ module.exports = function (eleventyConfig) {
// markdown filter // markdown filter
eleventyConfig.addLiquidFilter('markdown', (content) => { eleventyConfig.addLiquidFilter('markdown', (content) => {
if (!content) return
return md.render(content) return md.render(content)
}) })

View file

@ -14,13 +14,40 @@ module.exports = {
}, },
dashLower: (string) => string.replace(/\s+/g, '-').toLowerCase(), dashLower: (string) => string.replace(/\s+/g, '-').toLowerCase(),
encodeAmp: (string) => { encodeAmp: (string) => {
if (!string) return
const pattern = /&(?!(?:[a-zA-Z]+|#[0-9]+|#x[0-9a-fA-F]+);)/g const pattern = /&(?!(?:[a-zA-Z]+|#[0-9]+|#x[0-9a-fA-F]+);)/g
const replacement = '&' const replacement = '&'
return string.replace(pattern, replacement) return string.replace(pattern, replacement)
}, },
stripUtm: (string) => { stripUtm: (string) => {
if (!string) return
return string.replace(utmPattern, '') return string.replace(utmPattern, '')
}, },
normalizeEntries: (entries) => {
return entries.map((entry) => {
let excerpt = ''
let date = ''
// set the entry excerpt
if (entry.data?.post_excerpt) excerpt = entry.data.post_excerpt
if (entry.description) excerpt = entry.description
// set the entry date
if (entry.date) date = entry.date
if (entry.dateAdded) date = entry.dateAdded
if (entry.date_published) date = entry.date_published
// if there's a valid entry return a normalized object
if (entry) {
return {
title: entry.data?.title || entry.title,
url: entry.url.includes('http') ? entry.url : `https://coryd.dev${entry.url}`,
date,
excerpt,
}
}
})
},
getPostImage: (image) => { getPostImage: (image) => {
if (image && image !== '') return image if (image && image !== '') return image
return 'https://coryd.dev/assets/img/social-card.jpg' return 'https://coryd.dev/assets/img/social-card.jpg'

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="/assets/feeds/template.xsl" type="text/xsl" media="screen"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>
{% block title %}Books • Cory Dransfeldt{% endblock %}
</title>
<link href="{{ site.url }}/books.xml" rel="self" />
<link href="{{ site.url }}" />
<link rel="hub" href="https://pubsubhubbub.superfeedr.com/" />
<updated>{% block update %}{{ books[0].dateAdded | date: "%Y-%m-%dT%H:%M:%S-08:00" }}{% endblock %}</updated>
<id>{{ site.url }}</id>
<author>
<name>{{ site.name }}</name>
<email>{{ site.email }}</email>
</author>
<generator uri="https://11ty.dev" version="{{ eleventy.version }}">{{ eleventy.generator }}</generator>
{% block entries %}{% endblock %}
</feed>

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="/assets/feeds/template.xsl" type="text/xsl" media="screen"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>
{% block title %}All posts • Cory Dransfeldt{% endblock %}
</title>
<link href="{{ site.url }}/feeds/posts" rel="self" />
<link href="{{ site.url }}" />
<link rel="hub" href="https://pubsubhubbub.superfeedr.com/" />
<updated>{% block update %}{{ collections.posts[0].date | date: "%Y-%m-%dT%H:%M:%S-08:00" }}{% endblock %}</updated>
<id>{{ site.url }}/</id>
<author>
<name>{{ site.name }}</name>
<email>{{ site.email }}</email>
</author>
<generator uri="https://11ty.dev" version="{{ eleventy.version }}">{{ eleventy.generator }}</generator>
{% block entries %}{% endblock %}
</feed>

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="/assets/feeds/template.xsl" type="text/xsl" media="screen"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>
{% block title %}Follow • Cory Dransfeldt{% endblock %}
</title>
<link href="{{ site.url }}/follow.xml" rel="self" />
<link href="{{ site.url }}" />
<link rel="hub" href="https://pubsubhubbub.superfeedr.com/" />
<updated>{% block update %}{{ follow.posts[0].date_published | date: "%Y-%m-%dT%H:%M:%S-08:00" }}{% endblock %}</updated>
<id>{{ site.url }}</id>
<author>
<name>{{ site.name }}</name>
<email>{{ site.email }}</email>
</author>
<generator uri="https://11ty.dev" version="{{ eleventy.version }}">{{ eleventy.generator }}</generator>
{% block entries %}{% endblock %}
</feed>

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="/assets/feeds/template.xsl" type="text/xsl" media="screen"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>
{% block title %}Links • Cory Dransfeldt{% endblock %}
</title>
<link href="{{ site.url }}/links.xml" rel="self" />
<link href="{{ site.url }}" />
<link rel="hub" href="https://pubsubhubbub.superfeedr.com/" />
<updated>{% block update %}{{ links[0].date | date: "%Y-%m-%dT%H:%M:%S-08:00" }}{% endblock %}</updated>
<id>{{ site.url }}</id>
<author>
<name>{{ site.name }}</name>
<email>{{ site.email }}</email>
</author>
<generator uri="https://11ty.dev" version="{{ eleventy.version }}">{{ eleventy.generator }}</generator>
{% block entries %}{% endblock %}
</feed>

View file

@ -1,7 +1,6 @@
--- ---
layout: base layout: base
--- ---
<div class="min-h-screen flex flex-col"> <div class="min-h-screen flex flex-col">
<main class="flex-1 w-10/12 max-w-screen-sm md:max-w-screen-md mx-auto"> <main class="flex-1 w-10/12 max-w-screen-sm md:max-w-screen-md mx-auto">
{{ content }} {{ content }}

View file

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="/assets/feeds/template.xsl" type="text/xsl" media="screen"?>
<feed xmlns="http://www.w3.org/2005/Atom">
{% assign entries = data | normalizeEntries %}
<title>{{ title }}</title>
<link href="{{ site.url }}{{ permalink }}" rel="self" />
<link href="{{ site.url }}" />
<link rel="hub" href="https://pubsubhubbub.superfeedr.com/" />
<updated>{{ updated | date: "%Y-%m-%dT%H:%M:%S-08:00" }}</updated>
<id>{{ site.url }}</id>
<author>
<name>{{ site.name }}</name>
<email>{{ site.email }}</email>
</author>
<generator uri="https://11ty.dev" version="{{ eleventy.version }}">{{ eleventy.generator }}</generator>
{% for entry in entries limit: 20 -%}
<entry>
<title>{{ entry.title | escape }}</title>
<link href="{{ entry.url | stripUtm | encodeAmp }}" />
<updated>{{ entry.date | date: "%m.%d.%Y" }}</updated>
<id>{{ entry.url | stripUtm | encodeAmp }}</id>
<content type="html">
</content>
</entry>
{%- endfor %}
</feed>

View file

@ -1,4 +1,4 @@
--- ---
layout: feed layout: partials/feeds/layout
permalink: /assets/feeds/template.xsl permalink: /assets/feeds/template.xsl
--- ---

View file

@ -1,19 +0,0 @@
---
layout: null
permalink: /feeds/books
---
{% layout "./_includes/feeds/books.liquid" %}
{% block title %}Books • Cory Dransfeldt{% endblock %}
{% block self %}books.xml{% endblock %}
{% block update %}{{ books[0].dateAdded | date: "%Y-%m-%dT%H:%M:%S-08:00" }}{% endblock %}
{% block entries %}
{% for book in books %}
<entry>
<title>{{ book.title | escape }}</title>
<link href="{{ book.url | stripUtm | encodeAmp }}" />
<updated>{{ book.dateAdded | date: "%m.%d.%Y" }}</updated>
<id>{{ book.url | stripUtm | encodeAmp }}</id>
<content type="html"></content>
</entry>
{% endfor %}
{% endblock %}

12
src/feeds/books.md Normal file
View file

@ -0,0 +1,12 @@
---
layout: null
permalink: /feeds/books
---
{% render "partials/feeds/content.liquid"
permalink:'/feeds/books'
title:'Books • Cory Dransfeldt'
data:books
updated:books[0].dateAdded
site:site
eleventy:eleventy
%}

View file

@ -1,23 +0,0 @@
---
layout: null
permalink: /feeds/posts
---
{% layout "./_includes/feeds/feed.liquid" %}
{% block title %}All posts • Cory Dransfeldt{% endblock %}
{% block self %}feed.xml{% endblock %}
{% block update %}
{{ collections.posts[0].date | date: "%Y-%m-%dT%H:%M:%S-08:00" }}{% endblock %}
{% block entries %}
{% assign posts = collections.posts | reverse %}
{% for post in posts limit: 15 %}
<entry>
<title>{{ post.data.title }}</title>
<link href="{{ site.url }}{{ post.url }}" />
<updated>{{ post.date | date: "%m.%d.%Y" }}</updated>
<id>{{ site.url }}{{ post.url }}</id>
<content type="html">
{{ post.data.post_excerpt | markdown | escape }}
</content>
</entry>
{% endfor %}
{% endblock %}

13
src/feeds/feed.md Normal file
View file

@ -0,0 +1,13 @@
---
layout: null
permalink: /feeds/posts
---
{% assign posts = collections.posts | reverse %}
{% render "partials/feeds/content.liquid"
permalink:'/feeds/posts'
title:'All posts • Cory Dransfeldt'
data:posts
updated:posts[0].date
site:site
eleventy:eleventy
%}

View file

@ -1,19 +0,0 @@
---
layout: null
permalink: /feeds/follow
---
{% layout "./_includes/feeds/follow.liquid" %}
{% block title %}Follow • Cory Dransfeldt{% endblock %}
{% block self %}follow.xml{% endblock %}
{% block update %}{{ follow.posts[0].date_published | date: "%Y-%m-%dT%H:%M:%S-08:00" }}{% endblock %}
{% block entries %}
{% for item in follow.posts %}
<entry>
<title>{{ item.title | escape }}</title>
<link href="{{item.url | stripUtm | encodeAmp }}" />
<updated>{{ item.date_published | date: "%m.%d.%Y" }}</updated>
<id>{{ item.url | stripUtm | encodeAmp }}</id>
<content type="html"></content>
</entry>
{% endfor %}
{% endblock %}

12
src/feeds/follow.md Normal file
View file

@ -0,0 +1,12 @@
---
layout: null
permalink: /feeds/follow
---
{% render "partials/feeds/content.liquid"
permalink:'/feeds/follow'
title:'Follow • Cory Dransfeldt'
data:follow.posts
updated:follow.posts[0].date_published
site:site
eleventy:eleventy
%}

View file

@ -1,19 +0,0 @@
---
layout: null
permalink: /feeds/links
---
{% layout "./_includes/feeds/links.liquid" %}
{% block title %}Links • Cory Dransfeldt{% endblock %}
{% block self %}links.xml{% endblock %}
{% block update %}{{ links[0].date | date: "%Y-%m-%dT%H:%M:%S-08:00" }}{% endblock %}
{% block entries %}
{% for link in links %}
<entry>
<title>{{ link.title | escape }}</title>
<link href="{{ link.url | stripUtm | encodeAmp }}" />
<updated>{{ link.date | date: "%m.%d.%Y" }}</updated>
<id>{{ link.url | stripUtm | encodeAmp }}</id>
<content type="html"></content>
</entry>
{% endfor %}
{% endblock %}

12
src/feeds/links.md Normal file
View file

@ -0,0 +1,12 @@
---
layout: null
permalink: /feeds/links
---
{% render "partials/feeds/content.liquid"
permalink:'/feeds/links'
title:'Links • Cory Dransfeldt'
data:links
updated:links[0].date
site:site
eleventy:eleventy
%}