jekyll-feed 0.9.0 → 0.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/History.markdown +115 -0
  3. data/LICENSE.txt +1 -1
  4. data/README.md +118 -4
  5. data/lib/jekyll-feed.rb +2 -0
  6. data/lib/jekyll-feed/feed.xml +45 -15
  7. data/lib/jekyll-feed/generator.rb +109 -24
  8. data/lib/jekyll-feed/meta-tag.rb +9 -8
  9. data/lib/jekyll-feed/page-without-a-file.rb +2 -0
  10. data/lib/jekyll-feed/version.rb +7 -0
  11. metadata +49 -78
  12. data/.gitignore +0 -20
  13. data/.rspec +0 -2
  14. data/.rubocop.yml +0 -29
  15. data/.travis.yml +0 -20
  16. data/Gemfile +0 -6
  17. data/Rakefile +0 -6
  18. data/jekyll-feed.gemspec +0 -25
  19. data/script/bootstrap +0 -3
  20. data/script/cibuild +0 -7
  21. data/script/release +0 -7
  22. data/spec/fixtures/_config.yml +0 -9
  23. data/spec/fixtures/_data/authors.yml +0 -5
  24. data/spec/fixtures/_drafts/2015-01-12-a-draft.md +0 -4
  25. data/spec/fixtures/_layouts/some_default.html +0 -11
  26. data/spec/fixtures/_posts/2013-12-12-dec-the-second.md +0 -6
  27. data/spec/fixtures/_posts/2014-03-02-march-the-second.md +0 -5
  28. data/spec/fixtures/_posts/2014-03-04-march-the-fourth.md +0 -8
  29. data/spec/fixtures/_posts/2015-01-18-jekyll-last-modified-at.md +0 -5
  30. data/spec/fixtures/_posts/2015-02-12-strip-newlines.md +0 -6
  31. data/spec/fixtures/_posts/2015-05-12-liquid.md +0 -7
  32. data/spec/fixtures/_posts/2015-05-12-pre.html +0 -7
  33. data/spec/fixtures/_posts/2015-05-18-author-detail.md +0 -9
  34. data/spec/fixtures/_posts/2015-08-08-stuck-in-the-middle.html +0 -2
  35. data/spec/fixtures/_posts/2016-04-25-author-reference.md +0 -6
  36. data/spec/fixtures/feed.xslt.xml +0 -0
  37. data/spec/jekyll-feed_spec.rb +0 -278
  38. data/spec/spec_helper.rb +0 -28
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: dd1897a15ad66d115a4e4fba2981d29bf41b5c87
4
- data.tar.gz: da12a240d6bca1c5e4fd64b24864c783d85ffd77
2
+ SHA256:
3
+ metadata.gz: e8f1fde42e53f27b048363aa57f03f5d51a3f68fbe6af4e0ffb69209b373ffeb
4
+ data.tar.gz: aaaa1c370f29527e3806c6753ae76a2fa8297337f0e667f25fd43d05779fcfef
5
5
  SHA512:
6
- metadata.gz: c8b68581ece18c4615341881ee3ade2c33f87cbd38eb93c0085589b2f9e44b677ca615596408a05422657c1f8ddef51acb588c9bc565cfdc3d46a442c72a7b1f
7
- data.tar.gz: 6a0fe34bcb0044dac585c0f552981ad781a54a6e8cd1c62d4c58d25a9b594f5133b2eac01286a58d2760bb43b30221ce0912e85bce3ec57a15439d8af0632fca
6
+ metadata.gz: 6800a223adf7b8c6ae236d6b9d3e355d4ca31c7d2e67752cfd2cb5b3fe599ddda2d9c6f28a38a7c6d5e648ac67ca585fe6fe2a2e08f38c158a1b6a95ded11fd7
7
+ data.tar.gz: a17bf5e936302721494bba9028ccda96ca88a4e229e0b1c88e6abe63f1ee2c60e3992296da05721d30400952fcc0ccafe4a2bd179038553ee57d3c940a1d04e9
data/History.markdown CHANGED
@@ -1,3 +1,118 @@
1
+ ## HEAD
2
+
3
+ ## 0.15.1 / 2020-10-04
4
+
5
+ ### Bug Fixes
6
+
7
+ * MetaTag: when encoding for XML special characters, handle non-string objects (#326)
8
+
9
+ ## 0.15.0 / 2020-07-10
10
+
11
+ ### Minor Enhancements
12
+
13
+ * Add support for drafts (#316)
14
+
15
+ ## 0.14.0 / 2020-06-24
16
+
17
+ ### Minor Enhancements
18
+
19
+ * add support for categories (#153) (#233)
20
+ * add support for tags (#264)
21
+ * Make posts limit configurable (#314)
22
+ * XML escape the title field of feed_meta (#306)
23
+
24
+ ### Bug Fixes
25
+
26
+ * Fix feed link when post title contains HTML (#305)
27
+
28
+ ### Development Fixes
29
+
30
+ * Use Dir to list source files (#309)
31
+ * Require Ruby >=2.4.0 (#307)
32
+
33
+ ## 0.13.0 / 2019-11-13
34
+
35
+ ### Minor Enhancements
36
+
37
+ * Excerpt only flag (#287)
38
+ * Add media:content tag (#290)
39
+
40
+ ### Development Fixes
41
+
42
+ * test: use categories in post (#249)
43
+
44
+ ## 0.12.1 / 2019-03-23
45
+
46
+ ### Bug Fixes
47
+
48
+ * Re-introduce Ruby 2.3 support and test Jekyll 3.7+ (#272)
49
+
50
+ ## 0.12.0 / 2019-03-21
51
+
52
+ * Allow Jekyll v4 (still alpha)
53
+
54
+ ### Development Fixes
55
+
56
+ * style: fix offenses in specs (#248)
57
+ * dev: update CI and style settings (#258)
58
+ * Enable testing for Windows platform (#265)
59
+
60
+ ## 0.11.0 / 2018-09-09
61
+
62
+ ### Development Fixes
63
+
64
+ * Require Ruby 2.3 (#222)
65
+ * Refactor to remove redundant calls and variables (#240)
66
+
67
+ ### Minor Enhancements
68
+
69
+ * Categories and collections (#228)
70
+ * Remove check for older version of Jekyll (#234)
71
+
72
+ ## 0.10.0 / 2018-06-04
73
+
74
+ ### Bug Fixes
75
+
76
+ * Escape image URL (#209)
77
+
78
+ ### Development Fixes
79
+
80
+ * Rubocop 0.55 (#223)
81
+ * Bump Rubocop (#230)
82
+
83
+ ### Minor Enhancements
84
+
85
+ * Support Typhoeus 1.0 (#232)
86
+
87
+ ## 0.9.3 / 2018-02-04
88
+
89
+ * Define path with __dir (#187)
90
+ * Bump Ruby for Travis (#188)
91
+
92
+ ### Documentation
93
+
94
+ * Fix: Add note about using plugins instead of gems key (#197)
95
+ * Add documentation for disabling smartify filter (#205)
96
+ * Use `https` in more places. (#165)
97
+
98
+ ### Development Fixes
99
+
100
+ * Rubocop: Target Ruby 2.2 (#195)
101
+ * Test feeds that have a `site.lang` (#164)
102
+ * Test against Ruby 2.5 (#201)
103
+
104
+ ### Minor Enhancements
105
+
106
+ * fix <entry> template for posts with post.lang defined (#168)
107
+
108
+ ## 0.9.3 / 2017-03-28
109
+
110
+ ## 0.9.1 / 2017-02-17
111
+
112
+ ### Minor Enhancements
113
+
114
+ * Update feed.xml (#162)
115
+
1
116
  ## 0.9.0 / 2017-02-16
2
117
 
3
118
  ### Minor Enhancements
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 Ben Balter
1
+ Copyright (c) 2015-present Ben Balter and jekyll-feed contributors
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  A Jekyll plugin to generate an Atom (RSS-like) feed of your Jekyll posts
4
4
 
5
- [![Build Status](https://travis-ci.org/jekyll/jekyll-feed.svg)](https://travis-ci.org/jekyll/jekyll-feed) [![Gem Version](https://badge.fury.io/rb/jekyll-feed.svg)](http://badge.fury.io/rb/jekyll-feed)
5
+ [![Build Status](https://travis-ci.org/jekyll/jekyll-feed.svg)](https://travis-ci.org/jekyll/jekyll-feed) [![Gem Version](https://badge.fury.io/rb/jekyll-feed.svg)](https://badge.fury.io/rb/jekyll-feed)
6
6
 
7
7
  ## Installation
8
8
 
@@ -15,10 +15,12 @@ gem 'jekyll-feed'
15
15
  And then add this line to your site's `_config.yml`:
16
16
 
17
17
  ```yml
18
- gems:
18
+ plugins:
19
19
  - jekyll-feed
20
20
  ```
21
21
 
22
+ :warning: If you are using Jekyll < 3.5.0 use the `gems` key instead of `plugins`.
23
+
22
24
  ## Usage
23
25
 
24
26
  The plugin will automatically generate an Atom feed at `/feed.xml`.
@@ -29,7 +31,7 @@ The plugin will automatically use any of the following configuration variables,
29
31
 
30
32
  * `title` or `name` - The title of the site, e.g., "My awesome site"
31
33
  * `description` - A longer description of what your site is about, e.g., "Where I blog about Jekyll and other awesome things"
32
- * `url` - The URL to your site, e.g., `http://example.com`. If none is provided, the plugin will try to use `site.github.url`.
34
+ * `url` - The URL to your site, e.g., `https://example.com`. If none is provided, the plugin will try to use `site.github.url`.
33
35
  * `author` - Global author information (see below)
34
36
 
35
37
  ### Already have a feed path?
@@ -122,14 +124,126 @@ The plugin exposes a helper tag to expose the appropriate meta tags to support a
122
124
 
123
125
  The plugin uses [Jekyll's `smartify` filter](https://jekyllrb.com/docs/templates/) for processing the site title and post titles. This will translate plain ASCII punctuation into "smart" typographic punctuation. This will not render or strip any Markdown you may be using in a title.
124
126
 
127
+ Jekyll's `smartify` filter uses [kramdown](https://kramdown.gettalong.org/options.html) as a processor. Accordingly, if you do not want "smart" typographic punctuation, disabling them in kramdown in your `_config.yml` will disable them in your feed. For example:
128
+
129
+ ```yml
130
+ kramdown:
131
+ smart_quotes: apos,apos,quot,quot
132
+ typographic_symbols: {hellip: ...}
133
+ ```
134
+
125
135
  ### Custom styling
126
136
 
127
- Want to style what your feed looks like in the browser? Simply add an XSLT at `/feed.xslt.xml` and Jekyll Feed will link to the stylesheet.
137
+ Want to style what your feed looks like in the browser? When a XSLT Styleheet file named `feed.xslt.xml` exists at the root of your repository, a link to this stylesheet is added to the generated feed.
128
138
 
129
139
  ## Why Atom, and not RSS?
130
140
 
131
141
  Great question. In short, Atom is a better format. Think of it like RSS 3.0. For more information, see [this discussion on why we chose Atom over RSS 2.0](https://github.com/jekyll/jekyll-rss-feed/issues/2).
132
142
 
143
+ ## Categories
144
+
145
+ Jekyll Feed can generate feeds for each category. Simply define which categories you'd like feeds for in your config:
146
+
147
+ ```yml
148
+ feed:
149
+ categories:
150
+ - news
151
+ - updates
152
+ ```
153
+
154
+ ## Posts limit
155
+
156
+ By default the plugin limits the number of posts in the feed to 10. Simply define a new limit in your config:
157
+
158
+ ```yml
159
+ feed:
160
+ posts_limit: 20
161
+ ```
162
+
163
+ ## Collections
164
+
165
+ Jekyll Feed can generate feeds for collections other than the Posts collection. This works best for chronological collections (e.g., collections with dates in the filenames). Simply define which collections you'd like feeds for in your config:
166
+
167
+ ```yml
168
+ feed:
169
+ collections:
170
+ - changes
171
+ ```
172
+
173
+ By default, collection feeds will be outputted to `/feed/<COLLECTION>.xml`. If you'd like to customize the output path, specify a collection's custom path as follows:
174
+
175
+ ```yml
176
+ feed:
177
+ collections:
178
+ changes:
179
+ path: "/changes.xml"
180
+ ```
181
+
182
+ Finally, collections can also have category feeds which are outputted as `/feed/<COLLECTION>/<CATEGORY>.xml`. Specify categories like so:
183
+
184
+ ```yml
185
+ feed:
186
+ collections:
187
+ changes:
188
+ path: "/changes.xml"
189
+ categories:
190
+ - news
191
+ - updates
192
+ ```
193
+
194
+ ## Excerpt Only flag
195
+
196
+ Optional flag `excerpt_only` allows you to exclude post content from the Atom feed. Default value is `false` for backward compatibility.
197
+
198
+ When in `config.yml` is `true` than all posts in feed will be without `<content>` tags.
199
+
200
+ ```yml
201
+ feed:
202
+ excerpt_only: true
203
+ ```
204
+
205
+ The same flag can be used directly in post file. It will be disable `<content>` tag for selected post.
206
+ Settings in post file has higher priority than in config file.
207
+
208
+ ## Tags
209
+
210
+ To automatically generate feeds for each tag you apply to your posts you can add a tags setting to your config:
211
+
212
+ ```yml
213
+ feed:
214
+ tags: true
215
+ ```
216
+
217
+ If there are tags you don't want included in this auto generation you can exclude them
218
+
219
+ ```yml
220
+ feed:
221
+ tags:
222
+ except:
223
+ - tag-to-exclude
224
+ - another-tag
225
+ ```
226
+
227
+ If you wish to change the location of these auto generated feeds (`/feed/by_tag/<TAG>.xml` by default) you can provide an alternative folder for them to live in.
228
+
229
+ ```yml
230
+ feed:
231
+ tags:
232
+ path: "alternative/path/for/tags/feeds/"
233
+ ```
234
+
235
+ If you only want to generate feeds for a few tags you can also set this.
236
+
237
+ ```yml
238
+ feed:
239
+ tags:
240
+ only:
241
+ - tag-to-include
242
+ - another-tag
243
+ ```
244
+
245
+ Note that if you include a tag that is excluded a feed will not be generated for it.
246
+
133
247
  ## Contributing
134
248
 
135
249
  1. Fork it (https://github.com/jekyll/jekyll-feed/fork)
data/lib/jekyll-feed.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "jekyll"
2
4
  require "fileutils"
3
5
  require "jekyll-feed/generator"
@@ -2,17 +2,25 @@
2
2
  {% if page.xsl %}
3
3
  <?xml-stylesheet type="text/xml" href="{{ '/feed.xslt.xml' | absolute_url }}"?>
4
4
  {% endif %}
5
- <feed xmlns="http://www.w3.org/2005/Atom"{% if site.lang %} xml:lang="{{ site.lang }}"{% endif %}>
6
- <generator uri="http://jekyllrb.com" version="{{ jekyll.version }}">Jekyll</generator>
5
+ <feed xmlns="http://www.w3.org/2005/Atom" {% if site.lang %}xml:lang="{{ site.lang }}"{% endif %}>
6
+ <generator uri="https://jekyllrb.com/" version="{{ jekyll.version }}">Jekyll</generator>
7
7
  <link href="{{ page.url | absolute_url }}" rel="self" type="application/atom+xml" />
8
8
  <link href="{{ '/' | absolute_url }}" rel="alternate" type="text/html" {% if site.lang %}hreflang="{{ site.lang }}" {% endif %}/>
9
9
  <updated>{{ site.time | date_to_xmlschema }}</updated>
10
- <id>{{ '/' | absolute_url | xml_escape }}</id>
10
+ <id>{{ page.url | absolute_url | xml_escape }}</id>
11
11
 
12
- {% if site.title %}
13
- <title type="html">{{ site.title | smartify | xml_escape }}</title>
14
- {% elsif site.name %}
15
- <title type="html">{{ site.name | smartify | xml_escape }}</title>
12
+ {% assign title = site.title | default: site.name %}
13
+ {% if page.collection != "posts" %}
14
+ {% assign collection = page.collection | capitalize %}
15
+ {% assign title = title | append: " | " | append: collection %}
16
+ {% endif %}
17
+ {% if page.category %}
18
+ {% assign category = page.category | capitalize %}
19
+ {% assign title = title | append: " | " | append: category %}
20
+ {% endif %}
21
+
22
+ {% if title %}
23
+ <title type="html">{{ title | smartify | xml_escape }}</title>
16
24
  {% endif %}
17
25
 
18
26
  {% if site.description %}
@@ -31,15 +39,32 @@
31
39
  </author>
32
40
  {% endif %}
33
41
 
34
- {% assign posts = site.posts | where_exp: "post", "post.draft != true" %}
35
- {% for post in posts limit: 10 %}
36
- <entry{% if post.lang %} xml:lang="{{ post.lang }}"{% endif %}>
37
- <title type="html">{{ post.title | smartify | strip_html | normalize_whitespace | xml_escape }}</title>
38
- <link href="{{ post.url | absolute_url }}" rel="alternate" type="text/html" title="{{ post.title | xml_escape }}" />
42
+ {% if page.tags %}
43
+ {% assign posts = site.tags[page.tags] %}
44
+ {% else %}
45
+ {% assign posts = site[page.collection] %}
46
+ {% endif %}
47
+ {% if page.category %}
48
+ {% assign posts = posts | where: "category", page.category %}
49
+ {% endif %}
50
+ {% unless site.show_drafts %}
51
+ {% assign posts = posts | where_exp: "post", "post.draft != true" %}
52
+ {% endunless %}
53
+ {% assign posts = posts | sort: "date" | reverse %}
54
+ {% assign posts_limit = site.feed.posts_limit | default: 10 %}
55
+ {% for post in posts limit: posts_limit %}
56
+ <entry{% if post.lang %}{{" "}}xml:lang="{{ post.lang }}"{% endif %}>
57
+ {% assign post_title = post.title | smartify | strip_html | normalize_whitespace | xml_escape %}
58
+
59
+ <title type="html">{{ post_title }}</title>
60
+ <link href="{{ post.url | absolute_url }}" rel="alternate" type="text/html" title="{{ post_title }}" />
39
61
  <published>{{ post.date | date_to_xmlschema }}</published>
40
62
  <updated>{{ post.last_modified_at | default: post.date | date_to_xmlschema }}</updated>
41
63
  <id>{{ post.id | absolute_url | xml_escape }}</id>
42
- <content type="html" xml:base="{{ post.url | absolute_url | xml_escape }}">{{ post.content | strip | xml_escape }}</content>
64
+ {% assign excerpt_only = post.feed.excerpt_only | default: site.feed.excerpt_only %}
65
+ {% unless excerpt_only %}
66
+ <content type="html" xml:base="{{ post.url | absolute_url | xml_escape }}">{{ post.content | strip | xml_escape }}</content>
67
+ {% endunless %}
43
68
 
44
69
  {% assign post_author = post.author | default: post.authors[0] | default: site.author %}
45
70
  {% assign post_author = site.data.authors[post_author] | default: post_author %}
@@ -59,6 +84,10 @@
59
84
 
60
85
  {% if post.category %}
61
86
  <category term="{{ post.category | xml_escape }}" />
87
+ {% elsif post.categories %}
88
+ {% for category in post.categories %}
89
+ <category term="{{ category | xml_escape }}" />
90
+ {% endfor %}
62
91
  {% endif %}
63
92
 
64
93
  {% for tag in post.tags %}
@@ -72,9 +101,10 @@
72
101
  {% assign post_image = post.image.path | default: post.image %}
73
102
  {% if post_image %}
74
103
  {% unless post_image contains "://" %}
75
- {% assign post_image = post_image | absolute_url | xml_escape %}
104
+ {% assign post_image = post_image | absolute_url %}
76
105
  {% endunless %}
77
- <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="{{ post_image }}" />
106
+ <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="{{ post_image | xml_escape }}" />
107
+ <media:content medium="image" url="{{ post_image | xml_escape }}" xmlns:media="http://search.yahoo.com/mrss/" />
78
108
  {% endif %}
79
109
  </entry>
80
110
  {% endfor %}
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module JekyllFeed
2
4
  class Generator < Jekyll::Generator
3
5
  safe true
@@ -6,8 +8,16 @@ module JekyllFeed
6
8
  # Main plugin action, called by Jekyll-core
7
9
  def generate(site)
8
10
  @site = site
9
- return if file_exists?(feed_path)
10
- @site.pages << content_for_file(feed_path, feed_source_path)
11
+ collections.each do |name, meta|
12
+ Jekyll.logger.info "Jekyll Feed:", "Generating feed for #{name}"
13
+ (meta["categories"] + [nil]).each do |category|
14
+ path = feed_path(:collection => name, :category => category)
15
+ next if file_exists?(path)
16
+
17
+ @site.pages << make_page(path, :collection => name, :category => category)
18
+ end
19
+ end
20
+ generate_feed_by_tag if config["tags"] && !@site.tags.empty?
11
21
  end
12
22
 
13
23
  private
@@ -16,40 +26,115 @@ module JekyllFeed
16
26
  # 1. A '>', which closes an XML tag or
17
27
  # 2. A '}', which closes a Liquid tag
18
28
  # We will strip all of this whitespace to minify the template
19
- MINIFY_REGEX = %r!(?<=>|})\s+!
20
-
21
- # Path to feed from config, or feed.xml for default
22
- def feed_path
23
- if @site.config["feed"] && @site.config["feed"]["path"]
24
- @site.config["feed"]["path"]
25
- else
26
- "feed.xml"
29
+ MINIFY_REGEX = %r!(?<=>|})\s+!.freeze
30
+
31
+ # Returns the plugin's config or an empty hash if not set
32
+ def config
33
+ @config ||= @site.config["feed"] || {}
34
+ end
35
+
36
+ # Determines the destination path of a given feed
37
+ #
38
+ # collection - the name of a collection, e.g., "posts"
39
+ # category - a category within that collection, e.g., "news"
40
+ #
41
+ # Will return "/feed.xml", or the config-specified default feed for posts
42
+ # Will return `/feed/category.xml` for post categories
43
+ # WIll return `/feed/collection.xml` for other collections
44
+ # Will return `/feed/collection/category.xml` for other collection categories
45
+ def feed_path(collection: "posts", category: nil)
46
+ prefix = collection == "posts" ? "/feed" : "/feed/#{collection}"
47
+ return "#{prefix}/#{category}.xml" if category
48
+
49
+ collections.dig(collection, "path") || "#{prefix}.xml"
50
+ end
51
+
52
+ # Returns a hash representing all collections to be processed and their metadata
53
+ # in the form of { collection_name => { categories = [...], path = "..." } }
54
+ def collections
55
+ return @collections if defined?(@collections)
56
+
57
+ @collections = if config["collections"].is_a?(Array)
58
+ config["collections"].map { |c| [c, {}] }.to_h
59
+ elsif config["collections"].is_a?(Hash)
60
+ config["collections"]
61
+ else
62
+ {}
63
+ end
64
+
65
+ @collections = normalize_posts_meta(@collections)
66
+ @collections.each_value do |meta|
67
+ meta["categories"] = (meta["categories"] || []).to_set
68
+ end
69
+
70
+ @collections
71
+ end
72
+
73
+ def generate_feed_by_tag
74
+ tags_config = config["tags"]
75
+ tags_config = {} unless tags_config.is_a?(Hash)
76
+
77
+ except = tags_config["except"] || []
78
+ only = tags_config["only"] || @site.tags.keys
79
+ tags_pool = only - except
80
+ tags_path = tags_config["path"] || "/feed/by_tag/"
81
+
82
+ generate_tag_feed(tags_pool, tags_path)
83
+ end
84
+
85
+ def generate_tag_feed(tags_pool, tags_path)
86
+ tags_pool.each do |tag|
87
+ # allow only tags with basic alphanumeric characters and underscore to keep
88
+ # feed path simple.
89
+ next if %r![^a-zA-Z0-9_]!.match?(tag)
90
+
91
+ Jekyll.logger.info "Jekyll Feed:", "Generating feed for posts tagged #{tag}"
92
+ path = "#{tags_path}#{tag}.xml"
93
+ next if file_exists?(path)
94
+
95
+ @site.pages << make_page(path, :tags => tag)
27
96
  end
28
97
  end
29
98
 
30
99
  # Path to feed.xml template file
31
100
  def feed_source_path
32
- File.expand_path "./feed.xml", File.dirname(__FILE__)
101
+ @feed_source_path ||= File.expand_path "feed.xml", __dir__
102
+ end
103
+
104
+ def feed_template
105
+ @feed_template ||= File.read(feed_source_path).gsub(MINIFY_REGEX, "")
33
106
  end
34
107
 
35
108
  # Checks if a file already exists in the site source
36
109
  def file_exists?(file_path)
37
- if @site.respond_to?(:in_source_dir)
38
- File.exist? @site.in_source_dir(file_path)
39
- else
40
- File.exist? Jekyll.sanitized_path(@site.source, file_path)
41
- end
110
+ File.exist? @site.in_source_dir(file_path)
42
111
  end
43
112
 
44
113
  # Generates contents for a file
45
- def content_for_file(file_path, file_source_path)
46
- file = PageWithoutAFile.new(@site, File.dirname(__FILE__), "", file_path)
47
- file.content = File.read(file_source_path).gsub(MINIFY_REGEX, "")
48
- file.data["layout"] = nil
49
- file.data["sitemap"] = false
50
- file.data["xsl"] = file_exists?("feed.xslt.xml")
51
- file.output
52
- file
114
+
115
+ def make_page(file_path, collection: "posts", category: nil, tags: nil)
116
+ PageWithoutAFile.new(@site, __dir__, "", file_path).tap do |file|
117
+ file.content = feed_template
118
+ file.data.merge!(
119
+ "layout" => nil,
120
+ "sitemap" => false,
121
+ "xsl" => file_exists?("feed.xslt.xml"),
122
+ "collection" => collection,
123
+ "category" => category,
124
+ "tags" => tags
125
+ )
126
+ file.output
127
+ end
128
+ end
129
+
130
+ # Special case the "posts" collection, which, for ease of use and backwards
131
+ # compatability, can be configured via top-level keys or directly as a collection
132
+ def normalize_posts_meta(hash)
133
+ hash["posts"] ||= {}
134
+ hash["posts"]["path"] ||= config["path"]
135
+ hash["posts"]["categories"] ||= config["categories"]
136
+ config["path"] ||= hash["posts"]["path"]
137
+ hash
53
138
  end
54
139
  end
55
140
  end