Skip to content

Commit 1b82cef

Browse files
committed
add atom (rss) feed
- add meta tag to blog for discoverability of feed - add custom plugin to fix relative urls in post content
1 parent cb343fe commit 1b82cef

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

_includes/header.html

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<meta property="og:title" content="{{ page.title | xml_escape }}" />
2626
<meta property="og:description" content="Find out more on the blog" />
2727
<meta property="og:image" content="https://nodered.org/node-red-icon.png" />
28+
<link type="application/atom+xml" rel="alternate" href="{{ site.url }}/feed.xml" />
2829
{% endif %}
2930
</head>
3031
<body>

_plugins/relative-urls-to-absolute.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Jekyll
2+
module RSSURLFilter
3+
def relative_urls_to_absolute(input)
4+
url = @context.registers[:site].config['url']
5+
input
6+
.gsub('src="/', 'src="' + url + '/')
7+
.gsub('href="/', 'href="' + url + '/')
8+
.gsub('src=&quot;/', 'src=&quot;' + url + '/')
9+
.gsub('href=&quot;/', 'href=&quot;' + url + '/')
10+
end
11+
end
12+
end
13+
14+
Liquid::Template.register_filter(Jekyll::RSSURLFilter)

feed.xml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
---
2+
---
3+
<?xml version="1.0" encoding="utf-8"?>
4+
<feed xmlns="http://www.w3.org/2005/Atom">
5+
<generator uri="http://jekyllrb.com" version="{{ jekyll.version }}">Jekyll</generator>
6+
<link href="{{ page.url | absolute_url }}" rel="self" type="application/atom+xml" />
7+
<link href="{{ '/' | absolute_url }}" rel="alternate" type="text/html" />
8+
<updated>{{ site.time | date_to_xmlschema }}</updated>
9+
<id>{{ '/' | absolute_url | xml_escape }}/</id>
10+
11+
{% if site.title %}
12+
<title type="html">{{ site.title | xml_escape }}</title>
13+
{% elsif site.name %}
14+
<title type="html">{{ site.name | xml_escape }}</title>
15+
{% endif %}
16+
17+
{% if site.description %}
18+
<subtitle>{{ site.description | xml_escape }}</subtitle>
19+
{% endif %}
20+
21+
{% if site.author %}
22+
<author>
23+
<name>{{ site.author.name | default: site.author | xml_escape }}</name>
24+
{% if site.author.email %}
25+
<email>{{ site.author.email | xml_escape }}</email>
26+
{% endif %}
27+
{% if site.author.uri %}
28+
<uri>{{ site.author.uri | xml_escape }}</uri>
29+
{% endif %}
30+
</author>
31+
{% endif %}
32+
33+
{% for post in site.posts limit: 10 %}
34+
{% unless post.draft %}
35+
<entry>
36+
<title type="html">{{ post.title | strip_html | normalize_whitespace | xml_escape }}</title>
37+
<link href="{{ post.url | absolute_url }}" rel="alternate" type="text/html" title="{{ post.title | xml_escape }}" />
38+
<published>{{ post.date | date_to_xmlschema }}</published>
39+
<updated>{{ post.last_modified_at | default: post.date | date_to_xmlschema }}</updated>
40+
<id>{{ post.id | absolute_url | xml_escape }}</id>
41+
<content type="html" xml:base="{{ site.url }}">{{ post.content | relative_urls_to_absolute | strip | xml_escape }}</content>
42+
43+
{% assign post_author = post.author | default: post.authors[0] | default: site.author %}
44+
{% assign post_author = site.data.authors[post_author] | default: post_author %}
45+
{% assign post_author_email = post_author.email | default: nil %}
46+
{% assign post_author_uri = post_author.uri | default: nil %}
47+
{% assign post_author_name = post_author.name | default: post_author %}
48+
49+
{% if post_author %}
50+
<author>
51+
<name>{{ post_author_name | xml_escape }}</name>
52+
{% if post_author_email %}
53+
<email>{{ post_author_email | xml_escape }}</email>
54+
{% endif %}
55+
{% if post_author_uri %}
56+
<uri>{{ post_author_uri | xml_escape }}</uri>
57+
{% endif %}
58+
</author>
59+
{% endif %}
60+
61+
{% if post.category %}
62+
<category term="{{ post.category | xml_escape }}" />
63+
{% endif %}
64+
65+
{% for tag in post.tags %}
66+
<category term="{{ tag | xml_escape }}" />
67+
{% endfor %}
68+
69+
{% if post.excerpt and post.excerpt != empty %}
70+
<summary type="html">{{ post.excerpt | strip_html | normalize_whitespace | xml_escape }}</summary>
71+
{% endif %}
72+
</entry>
73+
{% endunless %}
74+
{% endfor %}
75+
</feed>

0 commit comments

Comments
 (0)