jekyll-webring 0.3.1 → 0.3.2
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 +4 -4
- data/README.md +23 -11
- data/lib/jekyll-webring.rb +105 -65
- data/lib/jekyll-webring/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3eb0156f786b243af4ce0e3d5290d951aea3a58c94583f1d8f651b37225cabd1
|
4
|
+
data.tar.gz: 71dbe5a025f4e73c433a00d4199aea4710b21240ad0a5671180908feb6ea88e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db481f4c219c4b8757916b582f54256b18fc1678dbc3450cce12711069e335de32cce7c8f8f91c4ea377986361fce3d507dfb38a16bdfddd89a4d71e7b82ff85
|
7
|
+
data.tar.gz: 3f9f4f4d21ecbc238daefb647a487dff32d422162939f6a81aa851f338fc2d2b08ff874c47ea559fa4d3ac969ddfea2bcf080f54de58f9f6eaaf44d638d40ca5
|
data/README.md
CHANGED
@@ -2,7 +2,9 @@
|
|
2
2
|
|
3
3
|
[](https://badge.fury.io/rb/jekyll-webring)
|
4
4
|
|
5
|
-
A plugin designed to generate a webring from rss feeds based on a date, so you
|
5
|
+
A plugin designed to generate a webring from rss feeds based on a date, so you
|
6
|
+
can link to other blogs.
|
7
|
+
Inspiried by [openring](https://git.sr.ht/~sircmpwn/openring).
|
6
8
|
|
7
9
|
## Installation
|
8
10
|
|
@@ -27,7 +29,8 @@ Generate a webring by putting this in a liquid template
|
|
27
29
|
{% webring %}
|
28
30
|
```
|
29
31
|
|
30
|
-
You can pass some options to the tag too. For example pass a date to generate
|
32
|
+
You can pass some options to the tag too. For example pass a date to generate
|
33
|
+
a webring of articles written before that date:
|
31
34
|
|
32
35
|
```liquid
|
33
36
|
{% webring post.date %}
|
@@ -39,7 +42,8 @@ Or pass 'random' to select random items from the rss feeds given:
|
|
39
42
|
{% webring 'random' %}
|
40
43
|
```
|
41
44
|
|
42
|
-
If the `layout_file` config option is set, you can create a liquid template
|
45
|
+
If the `layout_file` config option is set, you can create a liquid template
|
46
|
+
for the webring. The default one looks like:
|
43
47
|
|
44
48
|
```liquid
|
45
49
|
<section class="webring">
|
@@ -66,13 +70,16 @@ If the `layout_file` config option is set, you can create a liquid template for
|
|
66
70
|
```yaml
|
67
71
|
webring:
|
68
72
|
# Will save and read data from _data/webring.yml
|
69
|
-
# suggested to add this file to excludes in _config.yml otherwise jekyll
|
70
|
-
#
|
71
|
-
#
|
73
|
+
# suggested to add this file to excludes in _config.yml otherwise jekyll
|
74
|
+
# watch will get stuck in a permanant regenerate loop.
|
75
|
+
# (I also suggest setting this if you want to guarantee having the same
|
76
|
+
# webring generated, as many feeds only show the most recent items and will
|
77
|
+
# be unable to have a webring item generated for them if not saved)
|
72
78
|
# default: nil
|
73
79
|
data_file: webring
|
74
80
|
|
75
|
-
# Will look for a liquid template at _layouts/webring.html
|
81
|
+
# Will look for a liquid template at _layouts/webring.html
|
82
|
+
# if not set will use a default template
|
76
83
|
# default: nil
|
77
84
|
layout_file: webring
|
78
85
|
|
@@ -89,19 +96,24 @@ webring:
|
|
89
96
|
# default: 3
|
90
97
|
num_items: 3
|
91
98
|
|
92
|
-
# What to do if a date is given and no items in the feed are older than that
|
99
|
+
# What to do if a date is given and no items in the feed are older than that
|
100
|
+
# date
|
93
101
|
# options: ignore, use_oldest, use_latest, random
|
94
102
|
# default: ignore
|
95
103
|
no_item_at_date_behaviour: use_oldest
|
96
104
|
|
97
105
|
# The format the dates will be displayed in.
|
98
|
-
# If not set uses site.date_format, and if that is not set it reverts to
|
106
|
+
# If not set uses site.date_format, and if that is not set it reverts to
|
107
|
+
# default
|
99
108
|
# default: "%-d %B, %Y"
|
100
109
|
date_format: "%-d %B, %Y"
|
101
110
|
```
|
102
111
|
|
103
112
|
## Contributing
|
104
113
|
|
105
|
-
If you'd like to contribute, please [send a patch](https://git-send-email.io)
|
114
|
+
If you'd like to contribute, please [send a patch](https://git-send-email.io)
|
115
|
+
to this [mailing list](https://lists.sr.ht/~syldexia/public-inbox) [<~syldexia/public-inbox@lists.sr.ht>](mailto:~syldexia/public-inbox@lists.sr.ht)!
|
116
|
+
(or just email feedback or issues or w/e)
|
106
117
|
|
107
|
-
I've not really used ruby before, so I'm sure my code is quite bad, and any
|
118
|
+
I've not really used ruby before, so I'm sure my code is quite bad, and any
|
119
|
+
contributions would be welcome!
|
data/lib/jekyll-webring.rb
CHANGED
@@ -6,77 +6,115 @@ require 'sanitize'
|
|
6
6
|
require 'yaml'
|
7
7
|
require 'fileutils'
|
8
8
|
|
9
|
-
module
|
10
|
-
|
11
|
-
|
12
|
-
<
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
<
|
17
|
-
<
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
<
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
{% endfor %}
|
27
|
-
</section>
|
9
|
+
module JekyllWebring
|
10
|
+
TEMPLATE = <<~HTML
|
11
|
+
<section class="webring">
|
12
|
+
<h3>Articles from blogs I follow around the net</h3>
|
13
|
+
<section class="articles">
|
14
|
+
{% for item in webring %}
|
15
|
+
<div class="article">
|
16
|
+
<h4 class="title">
|
17
|
+
<a href="{{ item.url }}" target="_blank" rel="noopener">{{ item.title }}</a>
|
18
|
+
</h4>
|
19
|
+
<p class="summary">{{ item.summary }}</p>
|
20
|
+
<small class="source">
|
21
|
+
via <a href="{{ item.source_url }}">{{ item.source_title }}</a>
|
22
|
+
</small>
|
23
|
+
<small class="date">{{ item.date }}</small>
|
24
|
+
</div>
|
25
|
+
{% endfor %}
|
28
26
|
</section>
|
29
|
-
|
27
|
+
</section>
|
28
|
+
HTML
|
29
|
+
|
30
|
+
def self.set_config (context)
|
31
|
+
jekyll_config = context.registers[:site].config
|
32
|
+
config = jekyll_config['webring'] || {}
|
33
|
+
|
34
|
+
@config ||= {
|
35
|
+
'feeds' => config['feeds'] || [],
|
36
|
+
'layout_file' => config['layout_file'] ? "#{ jekyll_config['layouts_dir'] }/#{ config['layout_file'] }.html" : '',
|
37
|
+
'data_file' => config['data_file'] ? "#{ jekyll_config['data_dir'] }/#{ config['data_file'] }.yml" : '',
|
38
|
+
'date_format' => jekyll_config['date_format'] || config['date_format'] || "%-d %B, %Y",
|
39
|
+
'max_summary_length' => config['max_summary_length'] || 256,
|
40
|
+
'no_item_at_date_behaviour' => config['no_item_at_date_behaviour'],
|
41
|
+
'num_items' => config['num_items'] || 3,
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.config ()
|
46
|
+
@config
|
47
|
+
end
|
48
|
+
|
49
|
+
@feeds = [];
|
50
|
+
def self.feeds ()
|
51
|
+
urls = config['feeds']
|
52
|
+
|
53
|
+
if urls.empty?
|
54
|
+
return [];
|
55
|
+
end
|
30
56
|
|
31
|
-
|
32
|
-
|
33
|
-
DATA_FILE = "#{ Jekyll.configuration['data_dir'] }/#{ CONFIG['data_file'] }.yml"
|
34
|
-
DATE_FORMAT = CONFIG['date_format'] || Jekyll.configuration['date_format'] || "%-d %B, %Y"
|
57
|
+
if @feeds.empty?
|
58
|
+
Jekyll.logger.info("Webring:", "fetching rss feeds")
|
35
59
|
|
36
|
-
|
60
|
+
urls.each do |url|
|
61
|
+
Jekyll.logger.debug("Webring:",
|
62
|
+
"fetching feed at #{ url }")
|
37
63
|
|
38
|
-
|
39
|
-
def self.feeds ()
|
40
|
-
if @feeds.empty?
|
41
|
-
urls = CONFIG['feeds']
|
64
|
+
feed = []
|
42
65
|
|
43
|
-
|
44
|
-
feed = []
|
66
|
+
begin
|
45
67
|
xml = HTTParty.get(url).body
|
68
|
+
rescue
|
69
|
+
Jekyll.logger.error("Webring:",
|
70
|
+
"unable to fetch feed at #{ url }")
|
71
|
+
next
|
72
|
+
end
|
73
|
+
|
74
|
+
begin
|
46
75
|
raw_feed = Feedjira.parse(xml)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
feed_item = {
|
53
|
-
'source_title' => raw_feed.title,
|
54
|
-
'source_url' => raw_feed.url,
|
55
|
-
'title' => item.title,
|
56
|
-
'url' => item.url,
|
57
|
-
'_date' => item.published,
|
58
|
-
'summary' => summary,
|
59
|
-
}
|
60
|
-
|
61
|
-
feed << feed_item
|
62
|
-
end
|
63
|
-
@feeds << feed
|
76
|
+
rescue
|
77
|
+
Jekyll.logger.error("Webring:",
|
78
|
+
"unable to parse feed fetched from #{ url }")
|
79
|
+
next
|
64
80
|
end
|
65
|
-
end
|
66
81
|
|
67
|
-
|
68
|
-
|
82
|
+
raw_feed.entries.each do |item|
|
83
|
+
sanitized = Sanitize.fragment(
|
84
|
+
item.content || item.summary)
|
85
|
+
|
86
|
+
summary = sanitized.length > config['max_summary_length'] ?
|
87
|
+
"#{ sanitized[0 ... config['max_summary_length']] }..." : sanitized
|
69
88
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
89
|
+
feed_item = {
|
90
|
+
'source_title' => raw_feed.title,
|
91
|
+
'source_url' => raw_feed.url,
|
92
|
+
'title' => item.title,
|
93
|
+
'url' => item.url,
|
94
|
+
'_date' => item.published,
|
95
|
+
'summary' => summary,
|
96
|
+
}
|
97
|
+
|
98
|
+
feed << feed_item
|
99
|
+
end
|
100
|
+
@feeds << feed
|
74
101
|
end
|
102
|
+
end
|
75
103
|
|
76
|
-
|
104
|
+
@feeds
|
105
|
+
end
|
106
|
+
|
107
|
+
@data = nil
|
108
|
+
def self.get_data (site)
|
109
|
+
unless @data
|
110
|
+
@data = site.data['webring'] || {}
|
77
111
|
end
|
112
|
+
|
113
|
+
@data
|
78
114
|
end
|
115
|
+
end
|
79
116
|
|
117
|
+
module Jekyll
|
80
118
|
class WebringTag < Liquid::Tag
|
81
119
|
def initialize (tag_name, text, tokens)
|
82
120
|
super
|
@@ -100,7 +138,7 @@ module Jekyll
|
|
100
138
|
def get_items_from_feeds (param)
|
101
139
|
items = []
|
102
140
|
|
103
|
-
feeds =
|
141
|
+
feeds = JekyllWebring.feeds
|
104
142
|
case param
|
105
143
|
when 'random'
|
106
144
|
feeds.each do |feed_items|
|
@@ -123,7 +161,7 @@ module Jekyll
|
|
123
161
|
next
|
124
162
|
end
|
125
163
|
|
126
|
-
case
|
164
|
+
case JekyllWebring::config['no_item_at_date_behaviour']
|
127
165
|
when 'use_oldest'
|
128
166
|
items << feed_items.last
|
129
167
|
when 'use_latest'
|
@@ -142,10 +180,12 @@ module Jekyll
|
|
142
180
|
end
|
143
181
|
|
144
182
|
def render (context)
|
183
|
+
JekyllWebring::set_config(context)
|
184
|
+
|
145
185
|
site = context.registers[:site]
|
146
186
|
param = get_value(context, @text.strip)
|
147
187
|
|
148
|
-
webring_data =
|
188
|
+
webring_data = JekyllWebring.get_data(site)
|
149
189
|
|
150
190
|
if webring_data[param]
|
151
191
|
items = webring_data[param]
|
@@ -153,8 +193,8 @@ module Jekyll
|
|
153
193
|
items = get_items_from_feeds(param)
|
154
194
|
webring_data[param] = items if param
|
155
195
|
|
156
|
-
if
|
157
|
-
filename =
|
196
|
+
if JekyllWebring::config['data_file']
|
197
|
+
filename = JekyllWebring::config['data_file']
|
158
198
|
dirname = File.dirname filename
|
159
199
|
unless File.directory? dirname
|
160
200
|
FileUtils.mkdir_p dirname
|
@@ -168,11 +208,11 @@ module Jekyll
|
|
168
208
|
|
169
209
|
liquid_opts = site.config['liquid']
|
170
210
|
|
171
|
-
content =
|
211
|
+
content = JekyllWebring::TEMPLATE
|
172
212
|
payload = context
|
173
213
|
|
174
214
|
# stuff beyond this point mainly hacked together from jekyll internals
|
175
|
-
filename =
|
215
|
+
filename = JekyllWebring::config['layout_file']
|
176
216
|
if File.file? filename
|
177
217
|
begin
|
178
218
|
content = File.read filename
|
@@ -197,8 +237,8 @@ module Jekyll
|
|
197
237
|
:strict_variables => liquid_opts['strict_variables'],
|
198
238
|
}
|
199
239
|
|
200
|
-
webring_items = items.take(
|
201
|
-
webring_items.each { |item| item['date'] = item['_date'].strftime(
|
240
|
+
webring_items = items.take(JekyllWebring::config['num_items'])
|
241
|
+
webring_items.each { |item| item['date'] = item['_date'].strftime(JekyllWebring::config['date_format']) }
|
202
242
|
|
203
243
|
payload['webring'] = webring_items
|
204
244
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-webring
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sophie Askew
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|