jekyll-rss 1.0.0alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/lib/jekyll-rss/category_feed.rb +21 -0
- data/lib/jekyll-rss/generator.rb +42 -0
- data/lib/jekyll-rss/pager.rb +28 -0
- data/lib/jekyll-rss/pagination.rb +30 -0
- data/lib/jekyll-rss/rss_feed.rb +18 -0
- data/lib/jekyll-rss/rss_templates/blog.xml +35 -0
- data/lib/jekyll-rss/rss_templates/category.xml +35 -0
- data/lib/jekyll-rss/rss_templates_command.rb +42 -0
- data/lib/jekyll-rss/version.rb +5 -0
- data/lib/jekyll-rss.rb +12 -0
- metadata +111 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 1e174be5f9523489734e12dda4e22d66218f7990
|
|
4
|
+
data.tar.gz: 4ac3487bf2f4696cb15cad815267a68de149f342
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e2490ce9f9b981eb8fd2513bacb514baa24308fe39c1a0b4336f112f571cf6322ca28fe401f5eeb07033ebbf695c46dee89002fbcde13fe21a4a56f982c0f906
|
|
7
|
+
data.tar.gz: 511e71b7d128d4545854cf7c43bc948ec7ff836d2bf16a883fc73bf89a488a4fad7f7e0f3c48d31afb92fb86e21b1f941f468eb5b40fb9abe0b7289161619ca7
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 Bezalel Hermoso
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
module Jekyll
|
|
3
|
+
module RSS
|
|
4
|
+
class CategoryFeed < RSSFeed
|
|
5
|
+
|
|
6
|
+
NON_SLUG_REGEX = /[^a-z0-9\-_]/
|
|
7
|
+
|
|
8
|
+
def initialize(site, path, category)
|
|
9
|
+
@category = category
|
|
10
|
+
@category_slug = category.strip.gsub(' ', '-').gsub(NON_SLUG_REGEX, '')
|
|
11
|
+
super site, path
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def url_placeholders
|
|
15
|
+
placeholders = super
|
|
16
|
+
placeholders[:category] = @category_slug
|
|
17
|
+
placeholders
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Jekyll
|
|
2
|
+
module RSS
|
|
3
|
+
class Generator < ::Jekyll::Generator
|
|
4
|
+
def generate(site)
|
|
5
|
+
return nil unless site.config['rss']
|
|
6
|
+
generate_blog_feed site if File.exists? File.join(site.source, '_rss', 'blog.xml')
|
|
7
|
+
generate_category_feeds site if File.exists? File.join(site.source, '_rss', 'category.xml')
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def generate_blog_feed(site)
|
|
11
|
+
path = File.join site.source, '_rss', 'blog.xml'
|
|
12
|
+
feed = RSSFeed.new site, path
|
|
13
|
+
paginate_blog(site, feed) if site.config['rss'].is_a? Hash and site.config['rss']['paginate']
|
|
14
|
+
site.pages << feed
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def generate_category_feeds(site)
|
|
18
|
+
path = File.join site.source, '_rss', 'category.xml'
|
|
19
|
+
site.categories.each do |category, posts|
|
|
20
|
+
feed = CategoryFeed.new site, path, category
|
|
21
|
+
paginate_category(site, feed, category, posts) if site.config['rss'].is_a? Hash and site.config['rss']['paginate']
|
|
22
|
+
site.pages << feed
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def paginate_blog(site, feed)
|
|
27
|
+
Pagination.paginate site, feed, site.posts do |pager|
|
|
28
|
+
RSSFeed.new feed.site, feed.source
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def paginate_category(site, feed, category_name, category_posts)
|
|
33
|
+
Pagination.paginate site, feed, category_posts do |pager|
|
|
34
|
+
category = CategoryFeed.new feed.site, feed.source, category_name
|
|
35
|
+
category.data['category'] = category_name
|
|
36
|
+
category.data['posts'] = category_posts
|
|
37
|
+
category
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module Jekyll
|
|
2
|
+
module RSS
|
|
3
|
+
class Pager < ::Jekyll::Paginate::Pager
|
|
4
|
+
|
|
5
|
+
attr_reader :path_format
|
|
6
|
+
|
|
7
|
+
def initialize(site, page_num, posts, per_page, index_page)
|
|
8
|
+
@index_page = index_page
|
|
9
|
+
super site, page_num, posts, per_page
|
|
10
|
+
@previous_page_path = paginate_path site, @previous_page
|
|
11
|
+
@next_page_path = paginate_path site, @next_page
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def paginated_permalink
|
|
15
|
+
@index_page.data['paginated_permalink']
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def paginate_path(site, num_page)
|
|
19
|
+
return nil if num_page.nil?
|
|
20
|
+
return @index_page.url if num_page <= 1
|
|
21
|
+
placeholders = @index_page.url_placeholders
|
|
22
|
+
placeholders['num'] = num_page.to_s
|
|
23
|
+
url = ::Jekyll::URL.new :placeholders => placeholders, :permalink => paginated_permalink
|
|
24
|
+
url.to_s
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
module Jekyll
|
|
2
|
+
module RSS
|
|
3
|
+
class Pagination
|
|
4
|
+
def self.paginate(site, index_page, posts)
|
|
5
|
+
total_pages = Paginate::Pager.calculate_pages posts.sort_by(&self.sorter), self.per_page(site)
|
|
6
|
+
(1..total_pages).each do |page_num|
|
|
7
|
+
pager = Pager.new site, page_num, posts, total_pages, index_page
|
|
8
|
+
if page_num > 1
|
|
9
|
+
subpage = yield pager
|
|
10
|
+
subpage.data['permalink'] = index_page.data['paginated_permalink'].gsub(':num', page_num.to_s)
|
|
11
|
+
subpage.pager = pager
|
|
12
|
+
site.pages << subpage
|
|
13
|
+
else
|
|
14
|
+
index_page.pager = pager
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.per_page(site)
|
|
20
|
+
paginate = site.config['rss']['paginate']
|
|
21
|
+
raise(ArgumentError, "rss.paginate is set to `#{paginate}`. Must be a number, and should be greater than 0") unless paginate.is_a? Integer and paginate > 0
|
|
22
|
+
return paginate
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.sorter
|
|
26
|
+
lambda { |post| -post.date.to_f }
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Jekyll
|
|
2
|
+
module RSS
|
|
3
|
+
class RSSFeed < Page
|
|
4
|
+
|
|
5
|
+
attr_reader :source
|
|
6
|
+
|
|
7
|
+
def initialize(site, path)
|
|
8
|
+
@site = site
|
|
9
|
+
@base = site.source
|
|
10
|
+
@source = path
|
|
11
|
+
@dir = File.dirname(path)
|
|
12
|
+
basename = File.basename(path)
|
|
13
|
+
process basename
|
|
14
|
+
read_yaml File.dirname(path), basename
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
permalink: /rss/feed.xml
|
|
3
|
+
paginated_permalink: /rss/:num/feed.xml
|
|
4
|
+
---
|
|
5
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
6
|
+
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
|
7
|
+
<channel>
|
|
8
|
+
<title>{{ site.name | xml_escape }}</title>
|
|
9
|
+
<description>{% if site.description %}{{ site.description | xml_escape }}{% endif %}</description>
|
|
10
|
+
<link>{{ site.site_url }}</link>
|
|
11
|
+
<atom:link href="{{ site.site_url }}{{ page.url }}" rel="self" type="application/rss+xml" />
|
|
12
|
+
{% if paginator.next_page %}
|
|
13
|
+
<atom:link href="{{ site.site_url }}{{ paginator.next_page_path }}" rel="next" type="application/rss+xml" />
|
|
14
|
+
{% endif %}
|
|
15
|
+
{% if paginator.previous_page %}
|
|
16
|
+
<atom:link href="{{ site.site_url }}{{ paginator.previous_page_path }}" rel="previous" type="application/rss+xml" />
|
|
17
|
+
{% endif %}
|
|
18
|
+
{% for post in paginator.posts %}
|
|
19
|
+
<item>
|
|
20
|
+
<title>{{ post.title | xml_escape }}</title>
|
|
21
|
+
{% if post.author.name %}
|
|
22
|
+
<dc:creator>{{ post.author | xml_escape }}</dc:creator>
|
|
23
|
+
{% endif %}
|
|
24
|
+
{% if post.excerpt %}
|
|
25
|
+
<description>{{ post.excerpt | xml_escape }}</description>
|
|
26
|
+
{% else %}
|
|
27
|
+
<description>{{ post.content | xml_escape }}</description>
|
|
28
|
+
{% endif %}
|
|
29
|
+
<pubDate>{{ post.date | date: "%a, %d %b %Y %H:%M:%S %z" }}</pubDate>
|
|
30
|
+
<link>{{ site.site_url }}{{ post.url }}</link>
|
|
31
|
+
<guid isPermaLink="true">{{ site.site_url }}{{ post.url }}</guid>
|
|
32
|
+
</item>
|
|
33
|
+
{% endfor %}
|
|
34
|
+
</channel>
|
|
35
|
+
</rss>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
---
|
|
2
|
+
permalink: /rss/:category.xml
|
|
3
|
+
paginated_permalink: /rss/:num/:category.xml
|
|
4
|
+
---
|
|
5
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
6
|
+
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
|
7
|
+
<channel>
|
|
8
|
+
<title>{{ site.name | xml_escape }}</title>
|
|
9
|
+
<description>{% if site.description %}{{ site.description | xml_escape }}{% endif %}</description>
|
|
10
|
+
<link>{{ site.site_url }}/{{ page.category }}</link>
|
|
11
|
+
<atom:link href="{{ site.site_url }}{{ page.url }}" rel="self" type="application/rss+xml" />
|
|
12
|
+
{% if paginator.next_page %}
|
|
13
|
+
<atom:link href="{{ site.site_url }}{{ paginator.next_page_path }}" rel="next" type="application/rss+xml" />
|
|
14
|
+
{% endif %}
|
|
15
|
+
{% if paginator.previous_page %}
|
|
16
|
+
<atom:link href="{{ site.site_url }}{{ paginator.previous_page_path }}" rel="previous" type="application/rss+xml" />
|
|
17
|
+
{% endif %}
|
|
18
|
+
{% for post in paginator.posts %}
|
|
19
|
+
<item>
|
|
20
|
+
<title>{{ post.title | xml_escape }}</title>
|
|
21
|
+
{% if post.author.name %}
|
|
22
|
+
<dc:creator>{{ post.author | xml_escape }}</dc:creator>
|
|
23
|
+
{% endif %}
|
|
24
|
+
{% if post.excerpt %}
|
|
25
|
+
<description>{{ post.excerpt | xml_escape }}</description>
|
|
26
|
+
{% else %}
|
|
27
|
+
<description>{{ post.content | xml_escape }}</description>
|
|
28
|
+
{% endif %}
|
|
29
|
+
<pubDate>{{ post.date | date: "%a, %d %b %Y %H:%M:%S %z" }}</pubDate>
|
|
30
|
+
<link>{{ site.site_url }}{{ post.url }}</link>
|
|
31
|
+
<guid isPermaLink="true">{{ site.site_url }}{{ post.url }}</guid>
|
|
32
|
+
</item>
|
|
33
|
+
{% endfor %}
|
|
34
|
+
</channel>
|
|
35
|
+
</rss>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Jekyll
|
|
2
|
+
module RSS
|
|
3
|
+
class RSSTemplatesCommand < ::Jekyll::Command
|
|
4
|
+
class << self
|
|
5
|
+
def init_with_program(prog)
|
|
6
|
+
prog.command(:rss_template) do |c|
|
|
7
|
+
c.syntax 'rss_template [options]'
|
|
8
|
+
c.description 'Create the template files you need to format your RSS/Atom feeds.'
|
|
9
|
+
c.option 'blog', '-B', '--blog', 'Generate the blog RSS/Atom feed template'
|
|
10
|
+
c.option 'category', '-C', '--category', 'Generate the category RSS/Atom feed template'
|
|
11
|
+
|
|
12
|
+
c.action do |args, options|
|
|
13
|
+
process options
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def process(options)
|
|
19
|
+
config = configuration_from_options(options)
|
|
20
|
+
%w(blog category).each do |template|
|
|
21
|
+
create_template(config, template) if config[template]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def create_template(config, template)
|
|
26
|
+
from = File.expand_path File.join('..', 'rss_templates', "#{template}.xml"), __FILE__
|
|
27
|
+
dest_dir = File.join File.expand_path(config['source']), '_rss'
|
|
28
|
+
to = File.join dest_dir, "#{template}.xml"
|
|
29
|
+
|
|
30
|
+
FileUtils.mkdir(dest_dir) unless Dir.exists? dest_dir
|
|
31
|
+
|
|
32
|
+
if File.exists? to
|
|
33
|
+
Jekyll.logger.error "#{to} already exists and I refuse to overwrite it, because of reasons."
|
|
34
|
+
else
|
|
35
|
+
FileUtils.cp from, to
|
|
36
|
+
Jekyll.logger.info "#{to} created."
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
data/lib/jekyll-rss.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'jekyll-rss/version'
|
|
2
|
+
require 'jekyll-rss/generator'
|
|
3
|
+
require 'jekyll-rss/rss_feed'
|
|
4
|
+
require 'jekyll-rss/category_feed'
|
|
5
|
+
require 'jekyll-rss/pager'
|
|
6
|
+
require 'jekyll-rss/pagination'
|
|
7
|
+
require 'jekyll-rss/rss_templates_command'
|
|
8
|
+
|
|
9
|
+
module Jekyll
|
|
10
|
+
module RSS
|
|
11
|
+
end
|
|
12
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jekyll-rss
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0alpha
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Bez Hermoso
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-05-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: jekyll-paginate
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: jekyll
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '2.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '2.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: bundler
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '1.5'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '1.5'
|
|
69
|
+
description: Generate RSS/Atom feeds for your Jekyll site. You can have a feed for
|
|
70
|
+
all blog posts and also feeds for each category. Pagination supported.
|
|
71
|
+
email: bezalelhermoso@gmail.com
|
|
72
|
+
executables: []
|
|
73
|
+
extensions: []
|
|
74
|
+
extra_rdoc_files: []
|
|
75
|
+
files:
|
|
76
|
+
- LICENSE
|
|
77
|
+
- lib/jekyll-rss.rb
|
|
78
|
+
- lib/jekyll-rss/category_feed.rb
|
|
79
|
+
- lib/jekyll-rss/generator.rb
|
|
80
|
+
- lib/jekyll-rss/pager.rb
|
|
81
|
+
- lib/jekyll-rss/pagination.rb
|
|
82
|
+
- lib/jekyll-rss/rss_feed.rb
|
|
83
|
+
- lib/jekyll-rss/rss_templates/blog.xml
|
|
84
|
+
- lib/jekyll-rss/rss_templates/category.xml
|
|
85
|
+
- lib/jekyll-rss/rss_templates_command.rb
|
|
86
|
+
- lib/jekyll-rss/version.rb
|
|
87
|
+
homepage: https://github.com/bezhermoso/jekyll-rss
|
|
88
|
+
licenses:
|
|
89
|
+
- MIT
|
|
90
|
+
metadata: {}
|
|
91
|
+
post_install_message:
|
|
92
|
+
rdoc_options: []
|
|
93
|
+
require_paths:
|
|
94
|
+
- lib
|
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
|
+
requirements:
|
|
97
|
+
- - ">="
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: '0'
|
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - ">"
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: 1.3.1
|
|
105
|
+
requirements: []
|
|
106
|
+
rubyforge_project:
|
|
107
|
+
rubygems_version: 2.2.2
|
|
108
|
+
signing_key:
|
|
109
|
+
specification_version: 4
|
|
110
|
+
summary: RSS/Atom feeds for Jekyll
|
|
111
|
+
test_files: []
|