mako_rss 0.2.1 → 0.2.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/lib/mako/article.rb +18 -6
- data/lib/mako/commands/subscribe.rb +1 -0
- data/lib/mako/core.rb +0 -1
- data/lib/mako/core_ext/uri.rb +12 -0
- data/lib/mako/core_ext.rb +1 -0
- data/lib/mako/feed_constructor.rb +0 -1
- data/lib/mako/feed_finder.rb +5 -7
- data/lib/mako/subscription_list_writer.rb +0 -1
- data/lib/mako/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36e2ef1d6c047979056ee71f1bc6b1b60ad42f8c
|
4
|
+
data.tar.gz: da1e7fc95881733c0263c3f9a5e0bb9cdba579de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c171053333bb66e7781ecac1e3239447fa896358002eeae728f92608a9e4c62fa4f72cebd29855fecf1845d45e0770d9bc49438b141ddba6f954338e65080548
|
7
|
+
data.tar.gz: bd83759022b68479a87eed75d5bb662af64f2c154e3fb6469d526fdce5e8b615bec48bf7351d2dd6382798d6516c16e8f12f6692ec9822fd669a3b9927563947
|
data/lib/mako/article.rb
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
|
3
3
|
module Mako
|
4
4
|
class Article
|
5
|
-
attr_reader :title, :published, :summary, :
|
5
|
+
attr_reader :title, :published, :summary, :uri
|
6
6
|
|
7
7
|
def initialize(args)
|
8
8
|
@title = args.fetch(:title, '')
|
9
9
|
@published = args.fetch(:published)
|
10
|
+
@uri = URI.parse(args.fetch(:url))
|
10
11
|
@summary = sanitize(args.fetch(:summary))
|
11
|
-
@url = args.fetch(:url)
|
12
12
|
end
|
13
13
|
|
14
14
|
# Converts published Time object to formatted string
|
@@ -18,17 +18,29 @@ module Mako
|
|
18
18
|
@published.strftime('%A, %d %B %Y at %I:%M %P')
|
19
19
|
end
|
20
20
|
|
21
|
+
# Converts URI object into string
|
22
|
+
#
|
23
|
+
# @return [String]
|
24
|
+
def url
|
25
|
+
uri.to_s
|
26
|
+
end
|
27
|
+
|
21
28
|
private
|
22
29
|
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# p tags with the class bold
|
30
|
+
# Transforms img tags into a tags (if configured) and transforms h1 tags
|
31
|
+
# into p tags with the class bold
|
26
32
|
#
|
27
33
|
# @param [String] html an html document string
|
28
34
|
# @return [String] a sanitized html document string
|
29
35
|
def sanitize(html)
|
30
36
|
doc = Nokogiri::HTML::DocumentFragment.parse(html)
|
31
|
-
|
37
|
+
if Mako.config.sanitize_images
|
38
|
+
doc.css('img').each do |n|
|
39
|
+
n.name = 'a'
|
40
|
+
n.content = "📷 #{n['alt']}" || '📷 Image'
|
41
|
+
n['href'] = URI.parse(n['src']).absolutize!(uri)
|
42
|
+
end
|
43
|
+
end
|
32
44
|
doc.css('h1,h2,h3,h4,h5,h6').each { |n| n.name = 'p'; n.set_attribute('class', 'bold') }
|
33
45
|
doc.to_s
|
34
46
|
end
|
data/lib/mako/core.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module URI
|
4
|
+
class Generic
|
5
|
+
# Compares parsed URI with a base URI and adds the host section, if needed
|
6
|
+
#
|
7
|
+
# @param base_uri [URI]
|
8
|
+
def absolutize!(base_uri)
|
9
|
+
base_uri.host == host ? to_s : base_uri.merge(self).to_s
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/mako/core_ext.rb
CHANGED
data/lib/mako/feed_finder.rb
CHANGED
@@ -30,21 +30,19 @@ module Mako
|
|
30
30
|
else
|
31
31
|
html = Nokogiri::HTML(request[:body])
|
32
32
|
potential_feed_uris = html.xpath(XPATHS.detect { |path| !html.xpath(path).empty? })
|
33
|
-
|
33
|
+
if potential_feed_uris.empty?
|
34
|
+
Mako.errors.add_error "Could not find feed for #{request[:uri]}"
|
35
|
+
next
|
36
|
+
end
|
34
37
|
uri_string = potential_feed_uris.first.value
|
35
38
|
feed_uri = URI.parse(uri_string)
|
36
|
-
|
37
|
-
feed_uri.to_s
|
38
|
-
else
|
39
|
-
request[:uri].merge(feed_uri).to_s
|
40
|
-
end
|
39
|
+
feed_uri.absolutize!(request[:uri])
|
41
40
|
end
|
42
41
|
end.compact
|
43
42
|
end
|
44
43
|
|
45
44
|
private
|
46
45
|
|
47
|
-
# @private
|
48
46
|
# Make requests for each URI passed in and return an array of hashes
|
49
47
|
# with either just the URI (in the case that the URI passed in was already
|
50
48
|
# a feed URI), or the URI and the response body.
|
data/lib/mako/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mako_rss
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Pike
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -181,6 +181,7 @@ files:
|
|
181
181
|
- lib/mako/core_ext.rb
|
182
182
|
- lib/mako/core_ext/numeric.rb
|
183
183
|
- lib/mako/core_ext/time.rb
|
184
|
+
- lib/mako/core_ext/uri.rb
|
184
185
|
- lib/mako/errors.rb
|
185
186
|
- lib/mako/feed.rb
|
186
187
|
- lib/mako/feed_constructor.rb
|