jekyll-feed 0.10.0 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +0,0 @@
1
- ---
2
- author: Pat
3
- lang: en
4
- ---
5
-
6
- <pre>Line 1
7
- Line 2
8
- Line 3</pre>
@@ -1,9 +0,0 @@
1
- ---
2
- excerpt: ""
3
- author:
4
- name: Ben
5
- uri: "http://ben.balter.com"
6
- email: ben@example.com
7
- ---
8
-
9
- # December the twelfth, actually.
@@ -1,6 +0,0 @@
1
- ---
2
- excerpt: ""
3
- author: garthdb
4
- ---
5
-
6
- # April the twenty-fifth?
File without changes
@@ -1,313 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe(JekyllFeed) do
6
- let(:overrides) { {} }
7
- let(:config) do
8
- Jekyll.configuration(Jekyll::Utils.deep_merge_hashes({
9
- "full_rebuild" => true,
10
- "source" => source_dir,
11
- "destination" => dest_dir,
12
- "show_drafts" => true,
13
- "url" => "http://example.org",
14
- "name" => "My awesome site",
15
- "author" => {
16
- "name" => "Dr. Jekyll",
17
- },
18
- "collections" => {
19
- "my_collection" => { "output" => true },
20
- "other_things" => { "output" => false },
21
- },
22
- }, overrides))
23
- end
24
- let(:site) { Jekyll::Site.new(config) }
25
- let(:contents) { File.read(dest_dir("feed.xml")) }
26
- let(:context) { make_context(:site => site) }
27
- let(:feed_meta) { Liquid::Template.parse("{% feed_meta %}").render!(context, {}) }
28
- before(:each) do
29
- site.process
30
- end
31
-
32
- it "has no layout" do
33
- expect(contents).not_to match(%r!\ATHIS IS MY LAYOUT!)
34
- end
35
-
36
- it "creates a feed.xml file" do
37
- expect(Pathname.new(dest_dir("feed.xml"))).to exist
38
- end
39
-
40
- it "doesn't have multiple new lines or trailing whitespace" do
41
- expect(contents).to_not match %r!\s+\n!
42
- expect(contents).to_not match %r!\n{2,}!
43
- end
44
-
45
- it "puts all the posts in the feed.xml file" do
46
- expect(contents).to match /http:\/\/example\.org\/2014\/03\/04\/march-the-fourth\.html/
47
- expect(contents).to match /http:\/\/example\.org\/2014\/03\/02\/march-the-second\.html/
48
- expect(contents).to match /http:\/\/example\.org\/2013\/12\/12\/dec-the-second\.html/
49
- expect(contents).to match "http://example.org/2015/08/08/stuck-in-the-middle.html"
50
- expect(contents).to_not match /http:\/\/example\.org\/2016\/02\/09\/a-draft\.html/
51
- end
52
-
53
- it "does not include assets or any static files that aren't .html" do
54
- expect(contents).not_to match /http:\/\/example\.org\/images\/hubot\.png/
55
- expect(contents).not_to match /http:\/\/example\.org\/feeds\/atom\.xml/
56
- end
57
-
58
- it "preserves linebreaks in preformatted text in posts" do
59
- expect(contents).to match %r!Line 1\nLine 2\nLine 3!
60
- end
61
-
62
- it "supports post author name as an object" do
63
- expect(contents).to match /<author>\s*<name>Ben<\/name>\s*<email>ben@example.com<\/email>\s*<uri>http:\/\/ben.balter.com<\/uri>\s*<\/author>/
64
- end
65
-
66
- it "supports post author name as a string" do
67
- expect(contents).to match /<author>\s*<name>Pat<\/name>\s*<\/author>/
68
- end
69
-
70
- it "does not output author tag no author is provided" do
71
- expect(contents).not_to match /<author>\s*<name><\/name>\s*<\/author>/
72
- end
73
-
74
- it "does use author reference with data from _data/authors.yml" do
75
- expect(contents).to match /<author>\s*<name>Garth<\/name>\s*<email>example@mail.com<\/email>\s*<uri>http:\/\/garthdb.com<\/uri>\s*<\/author>/
76
- end
77
-
78
- it "converts markdown posts to HTML" do
79
- expect(contents).to match /&lt;p&gt;March the second!&lt;\/p&gt;/
80
- end
81
-
82
- it "uses last_modified_at where available" do
83
- expect(contents).to match /<updated>2015-05-12T13:27:59\+00:00<\/updated>/
84
- end
85
-
86
- it "replaces newlines in posts to spaces" do
87
- expect(contents).to match %r!<title type="html">The plugin will properly strip newlines.</title>!
88
- end
89
-
90
- it "renders Liquid inside posts" do
91
- expect(contents).to match %r!Liquid is rendered\.!
92
- expect(contents).not_to match %r!Liquid is not rendered\.!
93
- end
94
-
95
- it "includes the item image" do
96
- expect(contents).to include('<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://example.org/image.png" />')
97
- expect(contents).to include('<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://cdn.example.org/absolute.png?h=188&amp;w=250" />')
98
- expect(contents).to include('<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://example.org/object-image.png" />')
99
- end
100
-
101
- context "parsing" do
102
- let(:feed) { RSS::Parser.parse(contents) }
103
-
104
- it "outputs an RSS feed" do
105
- expect(feed.feed_type).to eql("atom")
106
- expect(feed.feed_version).to eql("1.0")
107
- expect(feed.encoding).to eql("UTF-8")
108
- expect(feed.lang).to be_nil
109
- expect(feed.valid?).to eql(true)
110
- end
111
-
112
- it "outputs the link" do
113
- expect(feed.link.href).to eql("http://example.org/feed.xml")
114
- end
115
-
116
- it "outputs the generator" do
117
- expect(feed.generator.content).to eql("Jekyll")
118
- expect(feed.generator.version).to eql(Jekyll::VERSION)
119
- end
120
-
121
- it "includes the items" do
122
- expect(feed.items.count).to eql(10)
123
- end
124
-
125
- it "includes item contents" do
126
- post = feed.items.last
127
- expect(post.title.content).to eql("Dec The Second")
128
- expect(post.link.href).to eql("http://example.org/2013/12/12/dec-the-second.html")
129
- expect(post.published.content).to eql(Time.parse("2013-12-12"))
130
- end
131
-
132
- it "includes the item's excerpt" do
133
- post = feed.items.last
134
- expect(post.summary.content).to eql("Foo")
135
- end
136
-
137
- it "doesn't include the item's excerpt if blank" do
138
- post = feed.items.first
139
- expect(post.summary).to be_nil
140
- end
141
-
142
- context "with site.lang set" do
143
- lang = "en_US"
144
- let(:overrides) { { "lang" => lang } }
145
- it "outputs a valid feed" do
146
- expect(feed.feed_type).to eql("atom")
147
- expect(feed.feed_version).to eql("1.0")
148
- expect(feed.encoding).to eql("UTF-8")
149
- expect(feed.valid?).to eql(true)
150
- end
151
-
152
- it "outputs the correct language" do
153
- expect(feed.lang).to eql(lang)
154
- end
155
-
156
- it "sets the language of entries" do
157
- post = feed.items.first
158
- expect(post.lang).to eql(lang)
159
- end
160
-
161
- it "renders the feed meta" do
162
- expected = %r!<link href="http://example.org/" rel="alternate" type="text/html" hreflang="#{lang}" />!
163
- expect(contents).to match(expected)
164
- end
165
- end
166
-
167
- context "with site.title set" do
168
- let(:site_title) { "My Site Title" }
169
- let(:overrides) { { "title" => site_title } }
170
-
171
- it "uses site.title for the title" do
172
- expect(feed.title.content).to eql(site_title)
173
- end
174
- end
175
-
176
- context "with site.name set" do
177
- let(:site_name) { "My Site Name" }
178
- let(:overrides) { { "name" => site_name } }
179
-
180
- it "uses site.name for the title" do
181
- expect(feed.title.content).to eql(site_name)
182
- end
183
- end
184
-
185
- context "with site.name and site.title set" do
186
- let(:site_title) { "My Site Title" }
187
- let(:site_name) { "My Site Name" }
188
- let(:overrides) { { "title" => site_title, "name" => site_name } }
189
-
190
- it "uses site.title for the title, dropping site.name" do
191
- expect(feed.title.content).to eql(site_title)
192
- end
193
- end
194
- end
195
-
196
- context "smartify" do
197
- let(:site_title) { "Pat's Site" }
198
- let(:overrides) { { "title" => site_title } }
199
- let(:feed) { RSS::Parser.parse(contents) }
200
-
201
- it "processes site title with SmartyPants" do
202
- expect(feed.title.content).to eql("Pat’s Site")
203
- end
204
- end
205
-
206
- context "validation" do
207
- it "validates" do
208
- # See https://validator.w3.org/docs/api.html
209
- url = "https://validator.w3.org/feed/check.cgi?output=soap12"
210
- response = Typhoeus.post(url, :body => { :rawdata => contents }, :accept_encoding => "gzip")
211
- pending "Something went wrong with the W3 validator" unless response.success?
212
- result = Nokogiri::XML(response.body)
213
- result.remove_namespaces!
214
-
215
- result.css("warning").each do |warning|
216
- # Quiet a warning that results from us passing the feed as a string
217
- next if warning.css("text").text =~ %r!Self reference doesn't match document location!
218
-
219
- # Quiet expected warning that results from blank summary test case
220
- next if warning.css("text").text =~ %r!(content|summary) should not be blank!
221
-
222
- # Quiet expected warning about multiple posts with same updated time
223
- next if warning.css("text").text =~ %r!Two entries with the same value for atom:updated!
224
-
225
- warn "Validation warning: #{warning.css("text").text} on line #{warning.css("line").text} column #{warning.css("column").text}"
226
- end
227
-
228
- errors = result.css("error").map do |error|
229
- "Validation error: #{error.css("text").text} on line #{error.css("line").text} column #{error.css("column").text}"
230
- end
231
-
232
- expect(result.css("validity").text).to eql("true"), errors.join("\n")
233
- end
234
- end
235
-
236
- context "with a baseurl" do
237
- let(:overrides) do
238
- { "baseurl" => "/bass" }
239
- end
240
-
241
- it "correctly adds the baseurl to the posts" do
242
- expect(contents).to match /http:\/\/example\.org\/bass\/2014\/03\/04\/march-the-fourth\.html/
243
- expect(contents).to match /http:\/\/example\.org\/bass\/2014\/03\/02\/march-the-second\.html/
244
- expect(contents).to match /http:\/\/example\.org\/bass\/2013\/12\/12\/dec-the-second\.html/
245
- end
246
-
247
- it "renders the feed meta" do
248
- expected = 'href="http://example.org/bass/feed.xml"'
249
- expect(feed_meta).to include(expected)
250
- end
251
- end
252
-
253
- context "feed meta" do
254
- it "renders the feed meta" do
255
- expected = '<link type="application/atom+xml" rel="alternate" href="http://example.org/feed.xml" title="My awesome site" />'
256
- expect(feed_meta).to eql(expected)
257
- end
258
-
259
- context "with a blank site name" do
260
- let(:config) do
261
- Jekyll.configuration({
262
- "source" => source_dir,
263
- "destination" => dest_dir,
264
- "url" => "http://example.org",
265
- })
266
- end
267
-
268
- it "does not output blank title" do
269
- expect(feed_meta).not_to include("title=")
270
- end
271
- end
272
- end
273
-
274
- context "changing the feed path" do
275
- let(:overrides) do
276
- {
277
- "feed" => {
278
- "path" => "atom.xml",
279
- },
280
- }
281
- end
282
-
283
- it "should write to atom.xml" do
284
- expect(Pathname.new(dest_dir("atom.xml"))).to exist
285
- end
286
-
287
- it "renders the feed meta with custom feed path" do
288
- expected = 'href="http://example.org/atom.xml"'
289
- expect(feed_meta).to include(expected)
290
- end
291
- end
292
-
293
- context "feed stylesheet" do
294
- it "includes the stylesheet" do
295
- expect(contents).to include('<?xml-stylesheet type="text/xml" href="http://example.org/feed.xslt.xml"?>')
296
- end
297
- end
298
-
299
- context "with site.lang set" do
300
- let(:overrides) { { "lang" => "en-US" } }
301
-
302
- it "should set the language" do
303
- expect(contents).to match %r!type="text/html" hreflang="en-US" />!
304
- end
305
- end
306
-
307
- context "with post.lang set" do
308
- it "should set the language for that entry" do
309
- expect(contents).to match %r!<entry xml:lang="en">!
310
- expect(contents).to match %r!<entry>!
311
- end
312
- end
313
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "jekyll"
4
- require "typhoeus"
5
- require "nokogiri"
6
- require "rss"
7
- require File.expand_path("../lib/jekyll-feed", __dir__)
8
-
9
- Jekyll.logger.log_level = :error
10
-
11
- RSpec.configure do |config|
12
- config.run_all_when_everything_filtered = true
13
- config.filter_run :focus
14
- config.order = "random"
15
-
16
- SOURCE_DIR = File.expand_path("fixtures", __dir__)
17
- DEST_DIR = File.expand_path("dest", __dir__)
18
-
19
- def source_dir(*files)
20
- File.join(SOURCE_DIR, *files)
21
- end
22
-
23
- def dest_dir(*files)
24
- File.join(DEST_DIR, *files)
25
- end
26
-
27
- def make_context(registers = {})
28
- Liquid::Context.new({}, {}, { :site => site }.merge(registers))
29
- end
30
- end