Skip to content

Commit 7383c47

Browse files
committed
Add feed.updated_deterministic setting
Two main uses cases: 1. Reduce deployment churn in repositories that hold a docsite in addition to source code. These currently regenerate and find something new commit on every change, even when nothing in the site has been changed. The only file changing each time is feed.xml. For example: https://github.com/qunitjs/qunit/commits/gh-pages 2. Improve reproducibility of the build, as highlighted via jekyll/jekyll#7187, by offering a choice that simply eliminates use of current time entirely, not even having to mock it.
1 parent 423ca21 commit 7383c47

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ feed:
4545

4646
To note, you shouldn't have to do this unless you already have a feed you're using, and you can't or wish not to redirect existing subscribers.
4747

48+
### Deterministic timestamp
49+
50+
By default, the feed will set `<updated>` to the current time (as provided by Jekyll via `site.time`).
51+
52+
Enable the `updated_deterministic` setting to set this instead to a deterministic value based on when the last post was published or updated.
53+
54+
```yml
55+
feed:
56+
updated_deterministic: true
57+
```
58+
4859
### Optional front matter
4960

5061
The plugin will use the following post metadata, automatically generated by Jekyll, which you can override via a post's YAML front matter:

lib/jekyll-feed/feed.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
<generator uri="https://jekyllrb.com/" version="{{ jekyll.version }}">Jekyll</generator>
77
<link href="{{ page.url | absolute_url }}" rel="self" type="application/atom+xml" />
88
<link href="{{ '/' | absolute_url }}" rel="alternate" type="text/html" {% if site.lang %}hreflang="{{ site.lang }}" {% endif %}/>
9-
<updated>{{ site.time | date_to_xmlschema }}</updated>
109
<id>{{ page.url | absolute_url | xml_escape }}</id>
1110

1211
{% assign title = site.title | default: site.name %}
@@ -51,6 +50,13 @@
5150
{% assign posts = posts | where_exp: "post", "post.draft != true" %}
5251
{% endunless %}
5352
{% assign posts = posts | sort: "date" | reverse %}
53+
{% if site.feed.updated_deterministic %}
54+
{% assign last_post = posts | first %}
55+
{% assign last_updated = last_post.last_modified_at | default: last_post.date | default: site.time %}
56+
{% else %}
57+
{% assign last_updated = site.time %}
58+
{% endif %}
59+
<updated>{{ last_updated | date_to_xmlschema }}</updated>
5460
{% assign posts_limit = site.feed.posts_limit | default: 10 %}
5561
{% for post in posts limit: posts_limit %}
5662
<entry{% if post.lang %}{{" "}}xml:lang="{{ post.lang }}"{% endif %}>

spec/jekyll-feed_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116

117117
context "parsing" do
118118
let(:feed) { RSS::Parser.parse(contents) }
119+
let(:overrides) { { "time" => Time.parse("2018-12-31") } }
119120

120121
it "outputs an RSS feed" do
121122
expect(feed.feed_type).to eql("atom")
@@ -134,6 +135,24 @@
134135
expect(feed.generator.version).to eql(Jekyll::VERSION)
135136
end
136137

138+
context "with site.feed.updated_deterministic set" do
139+
let(:overrides) do
140+
{
141+
"feed" => {
142+
"updated_deterministic" => true,
143+
},
144+
}
145+
end
146+
147+
it "outputs the last post time" do
148+
expect(feed.updated.content).to eql(Time.parse("2016-04-25"))
149+
end
150+
end
151+
152+
it "outputs the current time" do
153+
expect(feed.updated.content).to eql(Time.parse("2018-12-31"))
154+
end
155+
137156
it "includes the items" do
138157
expect(feed.items.count).to eql(10)
139158
end

0 commit comments

Comments
 (0)