jekyll-webmention_io 2.9.6 → 2.9.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dafe74e10b6f90383f988bab8eaf7ba85b1148e5
4
- data.tar.gz: '09702d5ba8716bb50a1747dc7fcedcb89c1cee0f'
3
+ metadata.gz: b4f0b3379a499a748fbf15fe90655da033e7ea78
4
+ data.tar.gz: b0737d75fe40749f72e5834486c031bd3417da32
5
5
  SHA512:
6
- metadata.gz: 4eb9c71529b677fb254de6b2dac0477e913182c2c8bb5e191765dddaad6c6f12d5011551fdc474f06ba22f77bff4e9e71e370064935eec1612f01bf5326c0dea
7
- data.tar.gz: c7c87537214cccb508b4e8238d1e98785ac5f5f34948601cadf831fbb7b6dd39326013727846e22bfc09e822a3cbff2435878428df92406b4d456395279227b3
6
+ metadata.gz: 519b8c8d762f7061d974fb4e3b46d8915080f400c58c6caef595f7d11c72c7c2b90cec578f549aa20ccad113e6d25342088a84017a6e0e918dd4434609e8069b
7
+ data.tar.gz: 26ead8a785f7ae3990c4117c5d489f031335f7adde98a4d45737ae031e363509d8d1985dff41751d63d1d8bb66c8bedd8afd8270f29b639b4322c3a1ec4325fe
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  require "json"
4
4
 
@@ -42,7 +42,7 @@ module Jekyll
42
42
  end
43
43
  end
44
44
  if count.positive?
45
- File.open(cached_outgoing, "w") { |f| YAML.dump(outgoing, f) }
45
+ Jekyll::WebmentionIO.dump_yaml(cached_outgoing, outgoing)
46
46
  end
47
47
  Jekyll::WebmentionIO.log "msg", "#{count} webmentions sent."
48
48
  end # file exists (outgoing)
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
@@ -45,7 +45,7 @@ module Jekyll
45
45
 
46
46
  @source_file_destination = (config["source"] == false ? Dir.mktmpdir : "#{@site.config["source"]}/#{config["destination"]}")
47
47
 
48
- @javascript = ""
48
+ @javascript = String.new ""
49
49
 
50
50
  concatenate_asset_files
51
51
 
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
@@ -59,8 +59,6 @@ module Jekyll
59
59
  @lookups[post.url]
60
60
  elsif last_webmention
61
61
  Date.parse last_webmention.dig("raw", "verified_date")
62
- else
63
- nil
64
62
  end
65
63
 
66
64
  # should we throttle?
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
data/lib/jekyll/tags/_.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
@@ -96,16 +96,16 @@ module Jekyll
96
96
  set_data(webmentions, types)
97
97
  end
98
98
 
99
- render_into_template
99
+ render_into_template(context.registers)
100
100
  end
101
101
 
102
102
  private
103
103
 
104
- def render_into_template
104
+ def render_into_template(context_registry)
105
105
  if @template && @data
106
106
  Jekyll::WebmentionIO.log "info", "Preparing to render webmention info into the #{@template_name} template."
107
107
  template = Liquid::Template.parse(@template, :error_mode => :strict)
108
- html = template.render(@data, { :strict_variables => false, :strict_filters => true })
108
+ html = template.render!(@data, :registers => context_registry, :strict_variables => false, :strict_filters => true)
109
109
  template.errors.each do |error|
110
110
  Jekyll::WebmentionIO.log "error", error
111
111
  end
@@ -1,17 +1,17 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
5
5
  # Licence : MIT
6
6
  #
7
- # this liquid plugin insert a webmentions into your Octopress or Jekill blog
7
+ # this liquid plugin insert a webmentions into your Octopress or Jekyll blog
8
8
  # using http://webmention.io/ and the following syntax:
9
9
  #
10
10
  # {% webmention_bookmarks post.url %}
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionBookmarksTag < Jekyll::WebmentionIO::WebmentionTag
14
+ class WebmentionBookmarksTag < WebmentionTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
@@ -19,7 +19,7 @@ module Jekyll
19
19
  end
20
20
 
21
21
  def set_data(data, _types)
22
- webmentions = extract_type "bookmarks", data
22
+ webmentions = extract_type @template_name, data
23
23
  @data = { "webmentions" => webmentions.values }
24
24
  end
25
25
  end
@@ -1,17 +1,17 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
5
5
  # Licence : MIT
6
6
  #
7
- # this liquid plugin insert a webmentions into your Octopress or Jekill blog
7
+ # this liquid plugin insert a webmentions into your Octopress or Jekyll blog
8
8
  # using http://webmention.io/ and the following syntax:
9
9
  #
10
10
  # {% webmention_count post.url [ bookmarks | likes | links | posts | replies | reposts | rsvps ]* %}
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionCountTag < Jekyll::WebmentionIO::WebmentionTag
14
+ class WebmentionCountTag < WebmentionTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
@@ -1,17 +1,17 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
5
5
  # Licence : MIT
6
6
  #
7
- # this liquid plugin insert a webmentions into your Octopress or Jekill blog
7
+ # this liquid plugin insert a webmentions into your Octopress or Jekyll blog
8
8
  # using http://webmention.io/ and the following syntax:
9
9
  #
10
10
  # {% webmention_likes post.url %}
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionLikesTag < Jekyll::WebmentionIO::WebmentionTag
14
+ class WebmentionLikesTag < WebmentionTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
@@ -19,7 +19,7 @@ module Jekyll
19
19
  end
20
20
 
21
21
  def set_data(data, _types)
22
- webmentions = extract_type "likes", data
22
+ webmentions = extract_type @template_name, data
23
23
  @data = { "webmentions" => webmentions.values }
24
24
  end
25
25
  end
@@ -1,17 +1,17 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
5
5
  # Licence : MIT
6
6
  #
7
- # this liquid plugin insert a webmentions into your Octopress or Jekill blog
7
+ # this liquid plugin insert a webmentions into your Octopress or Jekyll blog
8
8
  # using http://webmention.io/ and the following syntax:
9
9
  #
10
10
  # {% webmention_links post.url %}
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionLinksTag < Jekyll::WebmentionIO::WebmentionTag
14
+ class WebmentionLinksTag < WebmentionTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
@@ -19,7 +19,7 @@ module Jekyll
19
19
  end
20
20
 
21
21
  def set_data(data, _types)
22
- webmentions = extract_type "links", data
22
+ webmentions = extract_type @template_name, data
23
23
  @data = { "webmentions" => webmentions.values }
24
24
  end
25
25
  end
@@ -1,17 +1,17 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
5
5
  # Licence : MIT
6
6
  #
7
- # this liquid plugin insert a webmentions into your Octopress or Jekill blog
7
+ # this liquid plugin insert a webmentions into your Octopress or Jekyll blog
8
8
  # using http://webmention.io/ and the following syntax:
9
9
  #
10
10
  # {% webmention_posts post.url %}
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionPostsTag < Jekyll::WebmentionIO::WebmentionTag
14
+ class WebmentionPostsTag < WebmentionTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
@@ -19,7 +19,7 @@ module Jekyll
19
19
  end
20
20
 
21
21
  def set_data(data, _types)
22
- webmentions = extract_type "posts", data
22
+ webmentions = extract_type @template_name, data
23
23
  @data = { "webmentions" => webmentions.values }
24
24
  end
25
25
  end
@@ -1,17 +1,17 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
5
5
  # Licence : MIT
6
6
  #
7
- # this liquid plugin insert a webmentions into your Octopress or Jekill blog
7
+ # this liquid plugin insert a webmentions into your Octopress or Jekyll blog
8
8
  # using http://webmention.io/ and the following syntax:
9
9
  #
10
10
  # {% webmention_replies post.url %}
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionRepliesTag < Jekyll::WebmentionIO::WebmentionTag
14
+ class WebmentionRepliesTag < WebmentionTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
@@ -19,7 +19,7 @@ module Jekyll
19
19
  end
20
20
 
21
21
  def set_data(data, _types)
22
- webmentions = extract_type "replies", data
22
+ webmentions = extract_type @template_name, data
23
23
  @data = { "webmentions" => webmentions.values }
24
24
  end
25
25
  end
@@ -1,17 +1,17 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
5
5
  # Licence : MIT
6
6
  #
7
- # this liquid plugin insert a webmentions into your Octopress or Jekill blog
7
+ # this liquid plugin insert a webmentions into your Octopress or Jekyll blog
8
8
  # using http://webmention.io/ and the following syntax:
9
9
  #
10
10
  # {% webmention_reposts post.url %}
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionRepostsTag < Jekyll::WebmentionIO::WebmentionTag
14
+ class WebmentionRepostsTag < WebmentionTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
@@ -19,7 +19,7 @@ module Jekyll
19
19
  end
20
20
 
21
21
  def set_data(data, _types)
22
- webmentions = extract_type "reposts", data
22
+ webmentions = extract_type @template_name, data
23
23
  @data = { "webmentions" => webmentions.values }
24
24
  end
25
25
  end
@@ -1,17 +1,17 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
5
5
  # Licence : MIT
6
6
  #
7
- # this liquid plugin insert a webmentions into your Octopress or Jekill blog
7
+ # this liquid plugin insert a webmentions into your Octopress or Jekyll blog
8
8
  # using http://webmention.io/ and the following syntax:
9
9
  #
10
10
  # {% webmention_rsvps post.url %}
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionRsvpsTag < Jekyll::WebmentionIO::WebmentionTag
14
+ class WebmentionRsvpsTag < WebmentionTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
@@ -19,7 +19,7 @@ module Jekyll
19
19
  end
20
20
 
21
21
  def set_data(data, _types)
22
- webmentions = extract_type "rsvps", data
22
+ webmentions = extract_type @template_name, data
23
23
  @data = { "webmentions" => webmentions.values }
24
24
  end
25
25
  end
@@ -1,17 +1,17 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
5
5
  # Licence : MIT
6
6
  #
7
- # this liquid plugin insert a webmentions into your Octopress or Jekill blog
7
+ # this liquid plugin insert a webmentions into your Octopress or Jekyll blog
8
8
  # using http://webmention.io/ and the following syntax:
9
9
  #
10
10
  # {% webmentions post.url [ bookmarks | likes | links | posts | replies | reposts | rsvps ]* %}
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionsTag < Jekyll::WebmentionIO::WebmentionTag
14
+ class WebmentionsTag < WebmentionTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
@@ -11,7 +11,7 @@ module Jekyll
11
11
  module WebmentionIO
12
12
  class WebmentionHeadTag < Liquid::Tag
13
13
  def render(context)
14
- head = ""
14
+ head = String.new ""
15
15
  head << '<link rel="dns-prefetch" href="https://webmention.io">'
16
16
  head << '<link rel="preconnect" href="https://webmention.io">'
17
17
  head << '<link rel="preconnect" href="ws://webmention.io:8080">'
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
@@ -27,14 +27,14 @@ module Jekyll
27
27
  config = config.merge(site_config)
28
28
 
29
29
  # JS file
30
- js = ""
30
+ js = String.new ""
31
31
  unless config["deploy"] == false
32
32
  js_file_path = "#{site.config["baseurl"]}/#{config["destination"]}/JekyllWebmentionIO.js"
33
33
  js << "<script src=\"#{js_file_path}\" async></script>"
34
34
  end
35
35
 
36
36
  Jekyll::WebmentionIO.log "info", "Gathering templates for JavaScript."
37
- templates = ""
37
+ templates = String.new ""
38
38
  template_files = Jekyll::WebmentionIO.types + %w(count webmentions)
39
39
  template_files.each do |template|
40
40
  templates << "<template style=\"display:none\" id=\"webmention-#{template}\">"
@@ -1,10 +1,10 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
5
5
  # Licence : MIT
6
6
  #
7
- # this liquid plugin insert a webmentions into your Octopress or Jekill blog
7
+ # this liquid plugin insert a webmentions into your Octopress or Jekyll blog
8
8
  # using http://webmention.io/ and the following syntax:
9
9
  #
10
10
  require_relative "webmention_io/version"
@@ -19,6 +19,12 @@ require "webmention"
19
19
 
20
20
  module Jekyll
21
21
  module WebmentionIO
22
+ class << self
23
+ # define simple getters and setters
24
+ attr_reader :config, :jekyll_config, :cache_files, :cache_folder,
25
+ :file_prefix, :types
26
+ attr_writer :api_suffix
27
+ end
22
28
 
23
29
  @logger_prefix = "[jekyll-webmention_io]"
24
30
 
@@ -28,10 +34,12 @@ module Jekyll
28
34
 
29
35
  @types = %w(bookmarks likes links posts replies reposts rsvps)
30
36
 
31
- EXCEPTIONS = [ SocketError, Timeout::Error, Errno::EINVAL,
32
- Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError,
33
- Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
34
- Net::ProtocolError, OpenSSL::SSL::SSLError, ].freeze
37
+ EXCEPTIONS = [
38
+ SocketError, Timeout::Error,
39
+ Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError,
40
+ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
41
+ OpenSSL::SSL::SSLError,
42
+ ].freeze
35
43
 
36
44
  def self.bootstrap
37
45
  # @jekyll_config = Jekyll.configuration({ 'quiet' => true })
@@ -42,56 +50,25 @@ module Jekyll
42
50
  @cache_folder = @config["cache_folder"] || ".jekyll-cache"
43
51
  Dir.mkdir(@cache_folder) unless File.exist?(@cache_folder)
44
52
  @file_prefix = ""
45
- unless @cache_folder.include? "webmention"
46
- @file_prefix = "webmention_io_"
47
- end
53
+ @file_prefix = "webmention_io_" unless @cache_folder.include? "webmention"
48
54
  @cache_files = {
49
55
  "incoming" => "#{@cache_folder}/#{@file_prefix}received.yml",
50
56
  "outgoing" => "#{@cache_folder}/#{@file_prefix}outgoing.yml",
51
57
  "bad_uris" => "#{@cache_folder}/#{@file_prefix}bad_uris.yml",
52
58
  "lookups" => "#{@cache_folder}/#{@file_prefix}lookups.yml"
53
59
  }
54
- @cache_files.each do |_key, file|
60
+ @cache_files.each_value do |file|
55
61
  unless File.exist?(file)
56
- File.open(file, "w") { |f| YAML.dump({}, f) }
62
+ dump_yaml(file)
57
63
  end
58
64
  end
59
65
  end
60
66
 
61
- # Getters
62
- def self.config
63
- @config
64
- end
65
-
66
- def self.jekyll_config
67
- @jekyll_config
68
- end
69
-
70
- def self.cache_files
71
- @cache_files
72
- end
73
-
74
- def self.cache_folder
75
- @cache_folder
76
- end
77
-
78
- def self.file_prefix
79
- @file_prefix
80
- end
81
-
82
- def self.types
83
- @types
84
- end
85
-
86
- # Setters
67
+ # Setter
87
68
  def self.api_path=(path)
88
69
  @api_endpoint = "#{@api_url}/#{path}"
89
70
  end
90
71
 
91
- def self.api_suffix=(suffix)
92
- @api_suffix = suffix
93
- end
94
-
95
72
  # Heplers
96
73
  def self.get_cache_file_path(key)
97
74
  path = false
@@ -115,9 +92,9 @@ module Jekyll
115
92
  def self.cache_webmentions(which, webmentions)
116
93
  if %w(incoming outgoing).include? which
117
94
  cache_file = get_cache_file_path which
118
- File.open(cache_file, "w") { |f| YAML.dump(webmentions, f) }
95
+ dump_yaml(cache_file, webmentions)
119
96
 
120
- Jekyll::WebmentionIO.log "msg", "#{which.capitalize} webmentions have been cached."
97
+ log "msg", "#{which.capitalize} webmentions have been cached."
121
98
  end
122
99
  end
123
100
 
@@ -129,13 +106,13 @@ module Jekyll
129
106
  end
130
107
 
131
108
  if @config.dig("pages") == true
132
- Jekyll::WebmentionIO.log "info", "Including site pages."
109
+ log "info", "Including site pages."
133
110
  documents.concat site.pages.clone
134
111
  end
135
112
 
136
113
  collections = @config.dig("collections")
137
114
  if collections
138
- Jekyll::WebmentionIO.log "info", "Adding collections."
115
+ log "info", "Adding collections."
139
116
  site.collections.each do |name, collection|
140
117
  # skip _posts
141
118
  next if name == "posts"
@@ -152,7 +129,7 @@ module Jekyll
152
129
  def self.get_response(api_params)
153
130
  api_params << @api_suffix
154
131
  url = "#{@api_endpoint}?#{api_params}"
155
- Jekyll::WebmentionIO.log "info", "Sending request to #{url}."
132
+ log "info", "Sending request to #{url}."
156
133
  source = get_uri_source(url)
157
134
  if source
158
135
  JSON.parse(source)
@@ -169,9 +146,9 @@ module Jekyll
169
146
 
170
147
  def self.cache_lookup_dates(lookups)
171
148
  cache_file = get_cache_file_path "lookups"
172
- File.open(cache_file, "w") { |f| YAML.dump(lookups, f) }
149
+ dump_yaml(cache_file, lookups)
173
150
 
174
- Jekyll::WebmentionIO.log "msg", "Lookups have been cached."
151
+ log "msg", "Lookups have been cached."
175
152
  end
176
153
 
177
154
  # allowed throttles: last_week, last_month, last_year, older
@@ -189,23 +166,21 @@ module Jekyll
189
166
  return false
190
167
  end
191
168
 
169
+ TIMEFRAMES = {
170
+ "last_week" => "weekly",
171
+ "last_month" => "monthly",
172
+ "last_year" => "yearly",
173
+ }.freeze
174
+
192
175
  def self.get_timeframe_from_date(time)
193
176
  date = time.to_date
194
- timeframes = {
195
- "last_week" => "weekly",
196
- "last_month" => "monthly",
197
- "last_year" => "yearly",
198
- }
199
- timeframe = nil
200
- timeframes.each do |key, value|
177
+ TIMEFRAMES.each do |key, value|
201
178
  if date.to_date > get_date_from_string(value)
202
179
  timeframe = key
203
180
  break
204
181
  end
205
182
  end
206
- unless timeframe
207
- timeframe = "older"
208
- end
183
+ timeframe = "older" unless timeframe
209
184
  return timeframe
210
185
  end
211
186
 
@@ -218,7 +193,7 @@ module Jekyll
218
193
  text = if text == "daily"
219
194
  "every 1 day"
220
195
  else
221
- "every 1 " + text.sub("ly", "")
196
+ "every 1 #{text.sub("ly", "")}"
222
197
  end
223
198
  matches = text.match(pattern)
224
199
  end
@@ -237,9 +212,7 @@ module Jekyll
237
212
  # log "info", "Looking for webmention endpoint at #{uri}"
238
213
  begin
239
214
  endpoint = Webmention::Client.supports_webmention?(uri)
240
- unless endpoint
241
- log "info", "Could not find a webmention endpoint at #{uri}"
242
- end
215
+ log("info", "Could not find a webmention endpoint at #{uri}") unless endpoint
243
216
  rescue => e
244
217
  log "info", "Endpoint lookup failed for #{uri}: #{e.message}"
245
218
  endpoint = false
@@ -262,23 +235,21 @@ module Jekyll
262
235
  end
263
236
 
264
237
  def self.get_template_contents(template)
265
- template_file = if Jekyll::WebmentionIO.config.dig("templates", template)
266
- Jekyll::WebmentionIO.log "info", "Using custom #{template} template"
267
- Jekyll::WebmentionIO.config["templates"][template]
238
+ template_file = if @config.dig("templates", template)
239
+ log "info", "Using custom #{template} template"
240
+ @config["templates"][template]
268
241
  else
269
242
  File.expand_path("templates/#{template}.html", __dir__)
270
243
  end
271
- Jekyll::WebmentionIO.log "info", "Template file: #{template_file}"
272
- handler = File.open(template_file, "rb")
273
- handler.read
244
+ log "info", "Template file: #{template_file}"
245
+ File.read(template_file)
274
246
  end
275
247
 
276
248
  # Connections
277
249
  def self.get_uri_source(uri, redirect_limit = 10, original_uri = false)
278
250
  original_uri ||= uri
279
- unless uri_ok?(uri)
280
- return false
281
- end
251
+ return false unless uri_ok?(uri)
252
+
282
253
  if redirect_limit.positive?
283
254
  response = get_http_response(uri)
284
255
  case response
@@ -293,9 +264,7 @@ module Jekyll
293
264
  return false
294
265
  end
295
266
  else
296
- if original_uri
297
- log "warn", "too many redirects for #{original_uri}"
298
- end
267
+ log("warn", "too many redirects for #{original_uri}") if original_uri
299
268
  uri_is_not_ok(uri)
300
269
  return false
301
270
  end
@@ -304,26 +273,34 @@ module Jekyll
304
273
  def self.log(type, message)
305
274
  debug = !!@config.dig("debug")
306
275
  if debug || %w(error msg).include?(type)
307
- if type == "msg"
308
- type = "info"
309
- end
276
+ type = "info" if type == "msg"
310
277
  Jekyll.logger.method(type).call("#{@logger_prefix} #{message}")
311
278
  end
312
279
  end
313
280
 
281
+ # Utility Method
282
+ # Writes given +data+ as YAML string into +file+ path.
283
+ #
284
+ # Returns nothing.
285
+ def self.dump_yaml(file, data = {})
286
+ File.open(file, "wb") { |f| f.puts YAML.dump(data) }
287
+ end
288
+
314
289
  private
315
290
 
316
291
  def self.get_http_response(uri)
317
- uri = URI.parse(URI.encode(uri))
292
+ uri = URI.parse(URI.encode(uri))
318
293
  http = Net::HTTP.new(uri.host, uri.port)
319
294
  http.read_timeout = 10
295
+
320
296
  if uri.scheme == "https"
321
297
  http.use_ssl = true
322
298
  http.ciphers = "ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:-LOW"
323
299
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
324
300
  end
301
+
325
302
  begin
326
- request = Net::HTTP::Get.new(uri.request_uri)
303
+ request = Net::HTTP::Get.new(uri.request_uri)
327
304
  response = http.request(request)
328
305
  return response
329
306
  rescue *EXCEPTIONS => e
@@ -336,13 +313,11 @@ module Jekyll
336
313
  # Cache bad URLs for a bit
337
314
  def self.uri_is_not_ok(uri)
338
315
  # Never cache webmention.io in here
339
- if uri.host == "webmention.io"
340
- return
341
- end
316
+ return if uri.host == "webmention.io"
342
317
  cache_file = @cache_files["bad_uris"]
343
318
  bad_uris = open(cache_file) { |f| YAML.load(f) }
344
319
  bad_uris[uri.host] = Time.now.to_s
345
- File.open(cache_file, "w") { |f| YAML.dump(bad_uris, f) }
320
+ dump_yaml(cache_file, bad_uris)
346
321
  end
347
322
 
348
323
  def self.uri_ok?(uri)
@@ -353,9 +328,7 @@ module Jekyll
353
328
  last_checked = DateTime.parse(bad_uris[uri.host])
354
329
  cache_bad_uris_for = @config["cache_bad_uris_for"] || 1 # in days
355
330
  recheck_at = last_checked.next_day(cache_bad_uris_for).to_s
356
- if recheck_at > now
357
- return false
358
- end
331
+ return false if recheck_at > now
359
332
  end
360
333
  return true
361
334
  end
@@ -363,13 +336,14 @@ module Jekyll
363
336
  end
364
337
 
365
338
  # Load all the bits
366
- Dir[File.expand_path("commands/*.rb", __dir__)].each do |file|
367
- require file
368
- end
369
- Dir[File.expand_path("generators/*.rb", __dir__)].each do |file|
370
- require file
371
- end
372
- require "#{__dir__}/tags/_.rb"
373
- Dir[File.expand_path("tags/*.rb", __dir__)].each do |file|
374
- require file unless file.include? "_.rb"
339
+ def require_all(group)
340
+ Dir[File.expand_path("#{group}/*.rb", __dir__)].each do |file|
341
+ require file
342
+ end
375
343
  end
344
+
345
+ require_all "commands"
346
+ require_all "generators"
347
+
348
+ require_relative "tags/_.rb"
349
+ require_all "tags"
@@ -1,7 +1,7 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Jekyll
4
4
  module WebmentionIO
5
- VERSION = "2.9.6".freeze
5
+ VERSION = "2.9.7"
6
6
  end
7
7
  end
@@ -1,10 +1,10 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
 
3
3
  # (c) Aaron Gustafson
4
4
  # https://github.com/aarongustafson/jekyll-webmention_io
5
5
  # Licence : MIT
6
6
  #
7
- # this liquid plugin insert a webmentions into your Octopress or Jekill blog
7
+ # this liquid plugin insert a webmentions into your Octopress or Jekyll blog
8
8
  # using http://webmention.io/ and the following syntax:
9
9
  #
10
10
  module Jekyll
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-webmention_io
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.6
4
+ version: 2.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Gustafson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-31 00:00:00.000000000 Z
11
+ date: 2018-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll