Skip to content

Commit 182b892

Browse files
authored
Merge pull request #523 from elichad/custom-rss-feed
Add custom RSS/Atom feed for blog
2 parents 39886c6 + f4f5bac commit 182b892

File tree

2 files changed

+132
-4
lines changed

2 files changed

+132
-4
lines changed

docs/_blog/feed_template.xml

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
layout: none
3+
permalink: feed/blog.xml
4+
title: "Research Object Crate (RO-Crate) | Blog"
5+
---
6+
<?xml version="1.0" encoding="utf-8"?>
7+
<!--This is an Atom feed adapted from https://github.com/jekyll/jekyll-feed/blob/master/lib/jekyll-feed/feed.xml under the MIT license.
8+
Changes from that source:
9+
* simplified how the title is set
10+
* removed if/else statements that could adapt the feed according to tags and categories (we don't need this)
11+
* added a check that hides posts dated in the future (the jekyll-feed gem doesn't do this for non-default collections)
12+
-->
13+
{% if page.xsl %}
14+
<?xml-stylesheet type="text/xml" href="{{ '/feed.xslt.xml' | absolute_url }}"?>
15+
{% endif %}
16+
<feed xmlns="http://www.w3.org/2005/Atom" {% if site.lang %}xml:lang="{{ site.lang }}"{% endif %}>
17+
<generator uri="https://jekyllrb.com/" version="{{ jekyll.version }}">Jekyll</generator>
18+
<link href="{{ page.url | absolute_url }}" rel="self" type="application/atom+xml" />
19+
<link href="{{ '/' | absolute_url }}" rel="alternate" type="text/html" {% if site.lang %}hreflang="{{ site.lang }}" {% endif %}/>
20+
<updated>{{ site.time | date_to_xmlschema }}</updated>
21+
<id>{{ page.url | absolute_url | xml_escape }}</id>
22+
23+
{% if page.title %}
24+
<title type="html">{{ page.title | xml_escape }}</title>
25+
{% endif %}
26+
27+
{% if site.description %}
28+
<subtitle>{{ site.description | xml_escape }}</subtitle>
29+
{% endif %}
30+
31+
{% if site.feed.icon %}
32+
{% assign feed_icon = site.feed.icon %}
33+
{% unless feed_icon contains "://" %}
34+
{% assign feed_icon = feed_icon | absolute_url %}
35+
{% endunless %}
36+
<icon>{{ feed_icon | xml_escape }}</icon>
37+
{% endif %}
38+
39+
{% if site.feed.logo %}
40+
{% assign feed_logo = site.feed.logo %}
41+
{% unless feed_logo contains "://" %}
42+
{% assign feed_logo = feed_logo | absolute_url %}
43+
{% endunless %}
44+
<logo>{{ feed_logo | xml_escape }}</logo>
45+
{% endif %}
46+
47+
{% if site.author %}
48+
<author>
49+
<name>{{ site.author.name | default: site.author | xml_escape }}</name>
50+
{% if site.author.email %}
51+
<email>{{ site.author.email | xml_escape }}</email>
52+
{% endif %}
53+
{% if site.author.uri %}
54+
<uri>{{ site.author.uri | xml_escape }}</uri>
55+
{% endif %}
56+
</author>
57+
{% endif %}
58+
59+
{% assign posts = site.blog | where_exp: "post", "post.layout == 'post'" %}
60+
{% assign posts = posts | sort: "date" | reverse %}
61+
{% assign posts_limit = site.feed.posts_limit | default: 10 %}
62+
{% assign current_date = "now" | date: '%s' | integer %}
63+
{% for post in posts limit: posts_limit %}
64+
{% unless site.future %}
65+
{% assign post_date = post.date | date: '%s' | integer %}
66+
{% if post_date > current_date %}
67+
{% continue %}
68+
{% endif %}
69+
{% endunless %}
70+
71+
<entry{% if post.lang %}{{" "}}xml:lang="{{ post.lang }}"{% endif %}>
72+
{% assign post_title = post.title | smartify | strip_html | normalize_whitespace | xml_escape %}
73+
74+
<title type="html">{{ post_title }}</title>
75+
<link href="{{ post.url | absolute_url }}" rel="alternate" type="text/html" title="{{ post_title }}" />
76+
<published>{{ post.date | date_to_xmlschema }}</published>
77+
<updated>{{ post.last_modified_at | default: post.date | date_to_xmlschema }}</updated>
78+
<id>{{ post.id | absolute_url | xml_escape }}</id>
79+
{% assign excerpt_only = post.feed.excerpt_only | default: site.feed.excerpt_only %}
80+
{% unless excerpt_only %}
81+
<content type="html" xml:base="{{ post.url | absolute_url | xml_escape }}"><![CDATA[{{ post.content | strip }}]]></content>
82+
{% endunless %}
83+
84+
{% assign post_author = post.author | default: post.authors[0] | default: site.author %}
85+
{% assign post_author = site.data.authors[post_author] | default: post_author %}
86+
{% assign post_author_email = post_author.email | default: nil %}
87+
{% assign post_author_uri = post_author.uri | default: nil %}
88+
{% assign post_author_name = post_author.name | default: post_author %}
89+
90+
<author>
91+
<name>{{ post_author_name | default: "" | xml_escape }}</name>
92+
{% if post_author_email %}
93+
<email>{{ post_author_email | xml_escape }}</email>
94+
{% endif %}
95+
{% if post_author_uri %}
96+
<uri>{{ post_author_uri | xml_escape }}</uri>
97+
{% endif %}
98+
</author>
99+
100+
{% if post.category %}
101+
<category term="{{ post.category | xml_escape }}" />
102+
{% elsif post.categories %}
103+
{% for category in post.categories %}
104+
<category term="{{ category | xml_escape }}" />
105+
{% endfor %}
106+
{% endif %}
107+
108+
{% for tag in post.tags %}
109+
<category term="{{ tag | xml_escape }}" />
110+
{% endfor %}
111+
112+
{% assign post_summary = post.description | default: post.excerpt %}
113+
{% if post_summary and post_summary != empty %}
114+
<summary type="html"><![CDATA[{{ post_summary | strip_html | normalize_whitespace }}]]></summary>
115+
{% endif %}
116+
117+
{% assign post_image = post.image.path | default: post.image %}
118+
{% if post_image %}
119+
{% unless post_image contains "://" %}
120+
{% assign post_image = post_image | absolute_url %}
121+
{% endunless %}
122+
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="{{ post_image | xml_escape }}" />
123+
<media:content medium="image" url="{{ post_image | xml_escape }}" xmlns:media="http://search.yahoo.com/mrss/" />
124+
{% endif %}
125+
</entry>
126+
{% endfor %}
127+
</feed>

docs/_config.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ collections:
107107
permalink: /blog/:path
108108
output: true
109109

110+
feed: # RSS/Atom feed settings, used in _blog/feed_template.xml
111+
logo: assets/img/ro-crate.svg
112+
icon: assets/img/favicon.ico
113+
posts_limit: 100
114+
110115
theme_variables:
111116
topnav:
112117
theme: light
@@ -115,10 +120,6 @@ theme_variables:
115120
twitter: false
116121
theme_color: 39989F
117122

118-
feed: # RSS/Atom feed settings
119-
collections:
120-
- blog
121-
122123
plugins:
123124
- elixir-toolkit-theme-plugins
124125
- jekyll-redirect-from

0 commit comments

Comments
 (0)