bridgetown-feed 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +21 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +27 -0
  5. data/Gemfile +11 -0
  6. data/History.markdown +5 -0
  7. data/LICENSE.txt +23 -0
  8. data/README.md +201 -0
  9. data/Rakefile +8 -0
  10. data/bridgetown-feed.gemspec +28 -0
  11. data/lib/bridgetown-feed.rb +12 -0
  12. data/lib/bridgetown-feed/feed.xml +96 -0
  13. data/lib/bridgetown-feed/generator.rb +111 -0
  14. data/lib/bridgetown-feed/meta-tag.rb +37 -0
  15. data/lib/bridgetown-feed/page-without-a-file.rb +9 -0
  16. data/lib/bridgetown-feed/version.rb +7 -0
  17. data/script/bootstrap +3 -0
  18. data/script/cibuild +7 -0
  19. data/script/fmt +10 -0
  20. data/script/release +7 -0
  21. data/script/test +4 -0
  22. data/spec/bridgetown-feed_spec.rb +525 -0
  23. data/spec/fixtures/bridgetown.config.yml +9 -0
  24. data/spec/fixtures/src/_collection/2018-01-01-collection-doc.md +4 -0
  25. data/spec/fixtures/src/_collection/2018-01-02-collection-category-doc.md +5 -0
  26. data/spec/fixtures/src/_data/authors.yml +5 -0
  27. data/spec/fixtures/src/_layouts/some_default.html +11 -0
  28. data/spec/fixtures/src/_posts/2013-12-12-dec-the-second.md +7 -0
  29. data/spec/fixtures/src/_posts/2014-03-02-march-the-second.md +6 -0
  30. data/spec/fixtures/src/_posts/2014-03-04-march-the-fourth.md +9 -0
  31. data/spec/fixtures/src/_posts/2015-01-12-a-draft.md +5 -0
  32. data/spec/fixtures/src/_posts/2015-01-18-jekyll-last-modified-at.md +5 -0
  33. data/spec/fixtures/src/_posts/2015-02-12-strip-newlines.md +6 -0
  34. data/spec/fixtures/src/_posts/2015-05-12-liquid.md +7 -0
  35. data/spec/fixtures/src/_posts/2015-05-12-pre.html +8 -0
  36. data/spec/fixtures/src/_posts/2015-05-18-author-detail.md +9 -0
  37. data/spec/fixtures/src/_posts/2015-08-08-stuck-in-the-middle.html +6 -0
  38. data/spec/fixtures/src/_posts/2016-04-25-author-reference.md +6 -0
  39. data/spec/fixtures/src/feed.xslt.xml +0 -0
  40. data/spec/spec_helper.rb +35 -0
  41. metadata +210 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0b50b2c9c0ca17130d8de98b10525376be36f485dbb15ed035924c2ff831a29e
4
+ data.tar.gz: 30bd31d0bef345dcfe543e0cb72f958023e074ddcff8b855d7d3cac5b921403e
5
+ SHA512:
6
+ metadata.gz: 692474a5822f8fa91bbf9bfab116bdc171b04e5f4f3f8172db6087808b295f89ad19b93a66950365a3850c26f9c535fcdbde06447c474e8cbe7acc3be822f0fb
7
+ data.tar.gz: 67e3c6e9d1250dcbdf9963377c18636232c637a068d438fcad658a1ad7467aa4017b16e1acc6f0ca90e34264cc74124dfed52797e4dcec16b7fa24b5ab75a139
@@ -0,0 +1,21 @@
1
+ /vendor
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
16
+ *.gem
17
+ Gemfile.lock
18
+ spec/dest
19
+ .bundle
20
+ .bridgetown-metadata
21
+ .bridgetown-cache
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,27 @@
1
+ require: rubocop-jekyll
2
+
3
+ inherit_gem:
4
+ rubocop-jekyll: .rubocop.yml
5
+
6
+ AllCops:
7
+ TargetRubyVersion: 2.3
8
+ Include:
9
+ - lib/**/*.rb
10
+
11
+ Exclude:
12
+ - .gitignore
13
+ - .rspec
14
+ - .rubocop.yml
15
+ - .travis.yml
16
+
17
+ - Gemfile.lock
18
+ - History.markdown
19
+ - LICENSE.txt
20
+ - README.md
21
+
22
+ - script/**/*
23
+ - vendor/**/*
24
+
25
+ Naming/MemoizedInstanceVariableName:
26
+ Exclude:
27
+ - lib/bridgetown-feed/page-without-a-file.rb
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
5
+
6
+ gem "brdgetown", ENV["BRIDGETOWN_VERSION"] if ENV["BRIDGETOWN_VERSION"]
7
+
8
+ install_if -> { Gem.win_platform? } do
9
+ gem "tzinfo", "~> 1.2"
10
+ gem "tzinfo-data"
11
+ end
@@ -0,0 +1,5 @@
1
+ # Change Log
2
+
3
+ ## 1.0.0 / 2020-04-09
4
+
5
+ Use Bridgetown gem and rename to bridgetown-feed.
@@ -0,0 +1,23 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020-present Jared White and Bridgetown contributors
4
+ Copyright (c) 2015-2020 Ben Balter and jekyll-feed contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,201 @@
1
+ # Bridgetown Feed plugin
2
+
3
+ A Bridgetown plugin to generate an Atom (RSS-like) feed of your Bridgetown posts
4
+
5
+ ## Installation
6
+
7
+ Run this command to add this plugin to your site's Gemfile:
8
+
9
+ ```shell
10
+ $ bundle add bridgetown-feed -g bridgetown_plugins
11
+ ```
12
+
13
+ Or simply add this line to your Gemfile:
14
+
15
+ ```ruby
16
+ gem 'bridgetown-feed', group: "bridgetown_plugins"
17
+ ```
18
+
19
+ ## Usage
20
+
21
+ The plugin will automatically generate an Atom feed at `/feed.xml`.
22
+
23
+ ### Optional configuration options
24
+
25
+ The plugin will automatically use any of the following configuration variables, if they are present in your site's `bridgetown.config.yml` file.
26
+
27
+ * `title` or `name` - The title of the site, e.g., "My awesome site"
28
+ * `description` - A longer description of what your site is about, e.g., "Where I blog about Bridgetown and other awesome things"
29
+ * `url` - The URL to your site, e.g., `https://example.com`. If none is provided, the plugin will try to use `site.github.url`.
30
+ * `author` - Global author information (see below)
31
+
32
+ ### Already have a feed path?
33
+
34
+ Do you already have an existing feed someplace other than `/feed.xml`, but are on a host like GitHub Pages that doesn't support machine-friendly redirects? If you simply swap out `bridgetown-feed` for your existing template, your existing subscribers won't continue to get updates. Instead, you can specify a non-default path via your site's config.
35
+
36
+ ```yml
37
+ feed:
38
+ path: atom.xml
39
+ ```
40
+
41
+ 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.
42
+
43
+ ### Optional front matter
44
+
45
+ The plugin will use the following post metadata, automatically generated by Bridgetown, which you can override via a post's YAML front matter:
46
+
47
+ * `date`
48
+ * `title`
49
+ * `excerpt`
50
+ * `id`
51
+ * `category`
52
+ * `tags`
53
+
54
+ Additionally, the plugin will use the following values, if present in a post's YAML front matter:
55
+
56
+ * `image` - URL of an image that is representative of the post (can also be passed as `image.path`)
57
+
58
+ * `author` - The author of the post, e.g., "Dr. Bridgetown". If none is given, feed readers will look to the feed author as defined in `bridgetown.config.yml`. Like the feed author, this can also be an object or a reference to an author in `_data/authors.yml` (see below).
59
+
60
+ ### Author information
61
+
62
+ *TL;DR: In most cases, put `author: [your name]` in the document's front matter, for sites with multiple authors. If you need something more complicated, read on.*
63
+
64
+ There are several ways to convey author-specific information. Author information is found in the following order of priority:
65
+
66
+ 1. An `author` object, in the documents's front matter, e.g.:
67
+
68
+ ```yml
69
+ author:
70
+ twitter: MarinaDiamandis
71
+ ```
72
+
73
+ 2. An `author` object, in the site's `bridgetown.config.yml`, e.g.:
74
+
75
+ ```yml
76
+ author:
77
+ twitter: MarinaDiamandis
78
+ ```
79
+
80
+ 3. `site.data.authors[author]`, if an author is specified in the document's front matter, and a corresponding key exists in `site.data.authors`. E.g., you have the following in the document's front matter:
81
+
82
+ ```yml
83
+ author: marina
84
+ ```
85
+
86
+ And you have the following in `_data/authors.yml`:
87
+
88
+ ```yml
89
+ marina:
90
+ picture: /img/marina.png
91
+ twitter: MarinaDiamandis
92
+
93
+ jared:
94
+ picture: /img/jared.png
95
+ twitter: jaredcwhite
96
+ ```
97
+
98
+ In the above example, the author `marina`'s Twitter handle will be resolved to `@MarinaDiamandis`. This allows you to centralize author information in a single `_data/authors` file for site with many authors that require more than just the author's username.
99
+
100
+ *Pro-tip: If `authors` is present in the document's front matter as an array (and `author` is not), the plugin will use the first author listed.*
101
+
102
+ 4. An author in the document's front matter (the simplest way), e.g.:
103
+
104
+ ```yml
105
+ author: marina
106
+ ```
107
+
108
+ 5. An author in the site's `bridgetown.config.yml`, e.g.:
109
+
110
+ ```yml
111
+ author: marina
112
+ ```
113
+
114
+ ### Meta tags
115
+
116
+ The plugin exposes a helper tag to expose the appropriate meta tags to support automated discovery of your feed. Simply place `{% feed_meta %}` someplace in your template's `<head>` section, to output the necessary metadata.
117
+
118
+ ### SmartyPants
119
+
120
+ The plugin uses [Bridgetown's `smartify` filter](https://bridgetownrb.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.
121
+
122
+ Bridgetown'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 `bridgetown.config.yml` will disable them in your feed. For example:
123
+
124
+ ```yml
125
+ kramdown:
126
+ smart_quotes: apos,apos,quot,quot
127
+ typographic_symbols: {hellip: ...}
128
+ ```
129
+
130
+ ### Custom styling
131
+
132
+ Want to style what your feed looks like in the browser? Simply add an XSLT at `/feed.xslt.xml` and Bridgetown Feed will link to the stylesheet.
133
+
134
+ ## Why Atom, and not RSS?
135
+
136
+ 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/bridgetown/bridgetown-rss-feed/issues/2).
137
+
138
+ ## Categories
139
+
140
+ Bridgetown Feed can generate feeds for each category. Simply define which categories you'd like feeds for in your config:
141
+
142
+ ```yml
143
+ feed:
144
+ categories:
145
+ - news
146
+ - updates
147
+ ```
148
+
149
+ ## Collections
150
+
151
+ Bridgetown 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:
152
+
153
+ ```yml
154
+ feed:
155
+ collections:
156
+ - changes
157
+ ```
158
+
159
+ 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:
160
+
161
+ ```yml
162
+ feed:
163
+ collections:
164
+ changes:
165
+ path: "/changes.xml"
166
+ ```
167
+
168
+ Finally, collections can also have category feeds which are outputted as `/feed/<COLLECTION>/<CATEGORY>.xml`. Specify categories like so:
169
+
170
+ ```yml
171
+ feed:
172
+ collections:
173
+ changes:
174
+ path: "/changes.xml"
175
+ categories:
176
+ - news
177
+ - updates
178
+ ```
179
+
180
+ ## Excerpt Only flag
181
+
182
+ Optional flag `excerpt_only` allows you to exclude post content from the Atom feed. Default value is `false` for backward compatibility.
183
+
184
+ When it's set to `true` in `bridgetown.config.yml`, all posts in feed will be without `<content>` tags.
185
+
186
+ ```yml
187
+ feed:
188
+ excerpt_only: true
189
+ ```
190
+
191
+ The same flag can be used directly in post file. It will be disable `<content>` tag for selected post.
192
+ Settings in post file has higher priority than in config file.
193
+
194
+
195
+ ## Contributing
196
+
197
+ 1. Fork it (https://github.com/bridgetownrb/bridgetown-feed/fork)
198
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
199
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
200
+ 4. Push to the branch (`git push origin my-new-feature`)
201
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/bridgetown-feed/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "bridgetown-feed"
7
+ spec.version = Bridgetown::Feed::VERSION
8
+ spec.author = "Bridgetown Team"
9
+ spec.email = "maintainers@bridgetownrb.com"
10
+ spec.summary = "A Bridgetown plugin to generate an Atom feed of your Bridgetown posts"
11
+ spec.homepage = "https://github.com/bridgetownrb/bridgetown-feed"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.test_files = spec.files.grep(%r!^spec/!)
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.required_ruby_version = ">= 2.4.0"
19
+
20
+ spec.add_dependency "bridgetown", ">= 0.6", "< 2.0"
21
+
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "nokogiri", "~> 1.6"
24
+ spec.add_development_dependency "rake", "~> 12.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "rubocop-jekyll", "~> 0.5"
27
+ spec.add_development_dependency "typhoeus", ">= 0.7", "< 2.0"
28
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bridgetown"
4
+ require "fileutils"
5
+ require "bridgetown-feed/generator"
6
+
7
+ module BridgetownFeed
8
+ autoload :MetaTag, "bridgetown-feed/meta-tag"
9
+ autoload :PageWithoutAFile, "bridgetown-feed/page-without-a-file.rb"
10
+ end
11
+
12
+ Liquid::Template.register_tag "feed_meta", BridgetownFeed::MetaTag
@@ -0,0 +1,96 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ {% if page.xsl %}
3
+ <?xml-stylesheet type="text/xml" href="{{ '/feed.xslt.xml' | absolute_url }}"?>
4
+ {% endif %}
5
+ <feed xmlns="http://www.w3.org/2005/Atom" {% if site.lang %}xml:lang="{{ site.lang }}"{% endif %}>
6
+ <generator uri="https://bridgetownrb.com/" version="{{ bridgetown.version }}">Bridgetown</generator>
7
+ <link href="{{ page.url | absolute_url }}" rel="self" type="application/atom+xml" />
8
+ <link href="{{ '/' | absolute_url }}" rel="alternate" type="text/html" {% if site.lang %}hreflang="{{ site.lang }}" {% endif %}/>
9
+ <updated>{{ site.time | date_to_xmlschema }}</updated>
10
+ <id>{{ page.url | absolute_url | xml_escape }}</id>
11
+
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>
24
+ {% endif %}
25
+
26
+ {% if site.description %}
27
+ <subtitle>{{ site.description | xml_escape }}</subtitle>
28
+ {% endif %}
29
+
30
+ {% if site.author %}
31
+ <author>
32
+ <name>{{ site.author.name | default: site.author | xml_escape }}</name>
33
+ {% if site.author.email %}
34
+ <email>{{ site.author.email | xml_escape }}</email>
35
+ {% endif %}
36
+ {% if site.author.uri %}
37
+ <uri>{{ site.author.uri | xml_escape }}</uri>
38
+ {% endif %}
39
+ </author>
40
+ {% endif %}
41
+
42
+ {% assign posts = site[page.collection] | where_exp: "post", "post.draft != true" | sort: "date" | reverse %}
43
+ {% if page.category %}
44
+ {% assign posts = posts | where: "category",page.category %}
45
+ {% endif %}
46
+ {% for post in posts limit: 10 %}
47
+ <entry{% if post.lang %}{{" "}}xml:lang="{{ post.lang }}"{% endif %}>
48
+ <title type="html">{{ post.title | smartify | strip_html | normalize_whitespace | xml_escape }}</title>
49
+ <link href="{{ post.url | absolute_url }}" rel="alternate" type="text/html" title="{{ post.title | xml_escape }}" />
50
+ <published>{{ post.date | date_to_xmlschema }}</published>
51
+ <updated>{{ post.last_modified_at | default: post.date | date_to_xmlschema }}</updated>
52
+ <id>{{ post.id | absolute_url | xml_escape }}</id>
53
+ {% assign excerpt_only = post.feed.excerpt_only | default: site.feed.excerpt_only %}
54
+ {% unless excerpt_only %}
55
+ <content type="html" xml:base="{{ post.url | absolute_url | xml_escape }}">{{ post.content | strip | xml_escape }}</content>
56
+ {% endunless %}
57
+
58
+ {% assign post_author = post.author | default: post.authors[0] | default: site.author %}
59
+ {% assign post_author = site.data.authors[post_author] | default: post_author %}
60
+ {% assign post_author_email = post_author.email | default: nil %}
61
+ {% assign post_author_uri = post_author.uri | default: nil %}
62
+ {% assign post_author_name = post_author.name | default: post_author %}
63
+
64
+ <author>
65
+ <name>{{ post_author_name | default: "" | xml_escape }}</name>
66
+ {% if post_author_email %}
67
+ <email>{{ post_author_email | xml_escape }}</email>
68
+ {% endif %}
69
+ {% if post_author_uri %}
70
+ <uri>{{ post_author_uri | xml_escape }}</uri>
71
+ {% endif %}
72
+ </author>
73
+
74
+ {% if post.category %}
75
+ <category term="{{ post.category | xml_escape }}" />
76
+ {% endif %}
77
+
78
+ {% for tag in post.tags %}
79
+ <category term="{{ tag | xml_escape }}" />
80
+ {% endfor %}
81
+
82
+ {% if post.excerpt and post.excerpt != empty %}
83
+ <summary type="html">{{ post.excerpt | strip_html | normalize_whitespace | xml_escape }}</summary>
84
+ {% endif %}
85
+
86
+ {% assign post_image = post.image.path | default: post.image %}
87
+ {% if post_image %}
88
+ {% unless post_image contains "://" %}
89
+ {% assign post_image = post_image | absolute_url %}
90
+ {% endunless %}
91
+ <media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="{{ post_image | xml_escape }}" />
92
+ <media:content medium="image" url="{{ post_image | xml_escape }}" xmlns:media="http://search.yahoo.com/mrss/" />
93
+ {% endif %}
94
+ </entry>
95
+ {% endfor %}
96
+ </feed>