jekyll-webmention_io 2.9.7 → 3.0.0

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: b4f0b3379a499a748fbf15fe90655da033e7ea78
4
- data.tar.gz: b0737d75fe40749f72e5834486c031bd3417da32
3
+ metadata.gz: 6830a7a6abb84d8ba34c51b817ad817147561818
4
+ data.tar.gz: 37956daf8a417c5a9fcbae7e1337c6993a82e746
5
5
  SHA512:
6
- metadata.gz: 519b8c8d762f7061d974fb4e3b46d8915080f400c58c6caef595f7d11c72c7c2b90cec578f549aa20ccad113e6d25342088a84017a6e0e918dd4434609e8069b
7
- data.tar.gz: 26ead8a785f7ae3990c4117c5d489f031335f7adde98a4d45737ae031e363509d8d1985dff41751d63d1d8bb66c8bedd8afd8270f29b639b4322c3a1ec4325fe
6
+ metadata.gz: 9db99babf8e9e508f875517cb5890d300362018384e56fa9ac3ca30763cca55d500ad836e4153b66516b2f1ad2f7b5549cab682e83c6da833cd7fa9e20e1da5a
7
+ data.tar.gz: 788ede8be0748a6baf69e23354996f51155cbd628dec2af8619ea8bcfb855071d5ed6fd57f66a0577884ebd03fc1e10c66991778cafb502fdc261d5f6069c135
@@ -3,4 +3,6 @@
3
3
  require "jekyll"
4
4
  require "jekyll/webmention_io"
5
5
 
6
- Jekyll::WebmentionIO.bootstrap
6
+ Jekyll::Hooks.register :site, :after_init do |site|
7
+ Jekyll::WebmentionIO.bootstrap(site)
8
+ end
@@ -15,13 +15,13 @@ module Jekyll
15
15
  end
16
16
 
17
17
  def self.process(_args = [], _options = {})
18
- if File.exist? "#{Jekyll::WebmentionIO.cache_folder}/#{Jekyll::WebmentionIO.file_prefix}sent.yml"
18
+ if File.exist? Jekyll::WebmentionIO.cache_file("sent.yml")
19
19
  Jekyll::WebmentionIO.log "error", "Your outgoing webmentions queue needs to be upgraded. Please re-build your project."
20
20
  end
21
21
  count = 0
22
22
  cached_outgoing = Jekyll::WebmentionIO.get_cache_file_path "outgoing"
23
23
  if File.exist?(cached_outgoing)
24
- outgoing = open(cached_outgoing) { |f| YAML.load(f) }
24
+ outgoing = Jekyll::WebmentionIO.load_yaml(cached_outgoing)
25
25
  outgoing.each do |source, targets|
26
26
  targets.each do |target, response|
27
27
  next unless response == false
@@ -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 = String.new ""
48
+ @javascript = +"" # unfrozen String
49
49
 
50
50
  concatenate_asset_files
51
51
 
@@ -62,7 +62,9 @@ module Jekyll
62
62
  end
63
63
  end
64
64
 
65
- private def add_webmention_types
65
+ private
66
+
67
+ def add_webmention_types
66
68
  js_types = []
67
69
  Jekyll::WebmentionIO.types.each do |type|
68
70
  js_types.push "'#{type}': '#{type.to_singular}'"
@@ -76,7 +78,7 @@ module Jekyll
76
78
  @javascript << types_js.sub(/TYPES/, js_types.join(","))
77
79
  end
78
80
 
79
- private def concatenate_asset_files
81
+ def concatenate_asset_files
80
82
  source = File.expand_path("../assets/", __dir__)
81
83
  Dir["#{source}/*.js"].each do |file|
82
84
  handler = File.open(file, "rb")
@@ -84,19 +86,19 @@ module Jekyll
84
86
  end
85
87
  end
86
88
 
87
- private def uglify
89
+ def uglify
88
90
  uglify_config = {
89
91
  :harmony => true,
90
92
  }
91
93
  @javascript = Uglifier.new(uglify_config).compile(@javascript)
92
94
  end
93
95
 
94
- private def create_js_file
96
+ def create_js_file
95
97
  Dir.mkdir(@source_file_destination) unless File.exist?(@source_file_destination)
96
98
  File.open("#{@source_file_destination}/#{@file_name}", "w") { |f| f.write(@javascript) }
97
99
  end
98
100
 
99
- private def deploy_js_file
101
+ def deploy_js_file
100
102
  js_file = Jekyll::WebmentionIO::JavaScriptFile.new(@site, @source_file_destination, "", @file_name)
101
103
  @site.static_files << js_file
102
104
  end
@@ -72,13 +72,13 @@ module Jekyll
72
72
  end
73
73
 
74
74
  def upgrade_outgoing_webmention_cache
75
- old_sent_file = "#{Jekyll::WebmentionIO.cache_folder}/#{Jekyll::WebmentionIO.file_prefix}sent.yml"
76
- old_outgoing_file = "#{Jekyll::WebmentionIO.cache_folder}/#{Jekyll::WebmentionIO.file_prefix}queued.yml"
75
+ old_sent_file = Jekyll::WebmentionIO.cache_file("sent.yml")
76
+ old_outgoing_file = Jekyll::WebmentionIO.cache_file("queued.yml")
77
77
  unless File.exist? old_sent_file
78
78
  return
79
79
  end
80
- sent_webmentions = open(old_sent_file) { |f| YAML.load(f) }
81
- outgoing_webmentions = open(old_outgoing_file) { |f| YAML.load(f) }
80
+ sent_webmentions = Jekyll::WebmentionIO.load_yaml(old_sent_file)
81
+ outgoing_webmentions = Jekyll::WebmentionIO.load_yaml(old_outgoing_file)
82
82
  merged = {}
83
83
  outgoing_webmentions.each do |source_url, webmentions|
84
84
  collection = {}
@@ -11,17 +11,12 @@
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionBookmarksTag < WebmentionTag
14
+ class WebmentionBookmarksTag < WebmentionTypeTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
18
18
  self.template = "bookmarks"
19
19
  end
20
-
21
- def set_data(data, _types)
22
- webmentions = extract_type @template_name, data
23
- @data = { "webmentions" => webmentions.values }
24
- end
25
20
  end
26
21
  end
27
22
  end
@@ -11,17 +11,12 @@
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionLikesTag < WebmentionTag
14
+ class WebmentionLikesTag < WebmentionTypeTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
18
18
  self.template = "likes"
19
19
  end
20
-
21
- def set_data(data, _types)
22
- webmentions = extract_type @template_name, data
23
- @data = { "webmentions" => webmentions.values }
24
- end
25
20
  end
26
21
  end
27
22
  end
@@ -11,17 +11,12 @@
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionLinksTag < WebmentionTag
14
+ class WebmentionLinksTag < WebmentionTypeTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
18
18
  self.template = "links"
19
19
  end
20
-
21
- def set_data(data, _types)
22
- webmentions = extract_type @template_name, data
23
- @data = { "webmentions" => webmentions.values }
24
- end
25
20
  end
26
21
  end
27
22
  end
@@ -11,17 +11,12 @@
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionPostsTag < WebmentionTag
14
+ class WebmentionPostsTag < WebmentionTypeTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
18
18
  self.template = "posts"
19
19
  end
20
-
21
- def set_data(data, _types)
22
- webmentions = extract_type @template_name, data
23
- @data = { "webmentions" => webmentions.values }
24
- end
25
20
  end
26
21
  end
27
22
  end
@@ -11,17 +11,12 @@
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionRepliesTag < WebmentionTag
14
+ class WebmentionRepliesTag < WebmentionTypeTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
18
18
  self.template = "replies"
19
19
  end
20
-
21
- def set_data(data, _types)
22
- webmentions = extract_type @template_name, data
23
- @data = { "webmentions" => webmentions.values }
24
- end
25
20
  end
26
21
  end
27
22
  end
@@ -11,17 +11,12 @@
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionRepostsTag < WebmentionTag
14
+ class WebmentionRepostsTag < WebmentionTypeTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
18
18
  self.template = "reposts"
19
19
  end
20
-
21
- def set_data(data, _types)
22
- webmentions = extract_type @template_name, data
23
- @data = { "webmentions" => webmentions.values }
24
- end
25
20
  end
26
21
  end
27
22
  end
@@ -11,17 +11,12 @@
11
11
  #
12
12
  module Jekyll
13
13
  module WebmentionIO
14
- class WebmentionRsvpsTag < WebmentionTag
14
+ class WebmentionRsvpsTag < WebmentionTypeTag
15
15
  def initialize(tag_name, text, tokens)
16
16
  super
17
17
  @text = text
18
18
  self.template = "rsvps"
19
19
  end
20
-
21
- def set_data(data, _types)
22
- webmentions = extract_type @template_name, data
23
- @data = { "webmentions" => webmentions.values }
24
- end
25
20
  end
26
21
  end
27
22
  end
@@ -17,7 +17,7 @@ module Jekyll
17
17
  super
18
18
  cache_file = Jekyll::WebmentionIO.get_cache_file_path "incoming"
19
19
  @cached_webmentions = if File.exist? cache_file
20
- open(cache_file) { |f| YAML.load(f) }
20
+ Jekyll::WebmentionIO.load_yaml(cache_file)
21
21
  else
22
22
  {}
23
23
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # (c) Aaron Gustafson
4
+ # https://github.com/aarongustafson/jekyll-webmention_io
5
+ # Licence : MIT
6
+ #
7
+ # this liquid plugin insert a webmentions into your Octopress or Jekyll blog
8
+ # using http://webmention.io/
9
+ #
10
+ module Jekyll
11
+ module WebmentionIO
12
+ # Superclass for Webmention types:
13
+ # [ bookmarks | likes | links | posts | replies | reposts | rsvps ]
14
+ class WebmentionTypeTag < WebmentionTag
15
+ def set_data(data, _types)
16
+ webmentions = extract_type @template_name, data
17
+ @data = { "webmentions" => webmentions.values }
18
+ end
19
+ end
20
+ end
21
+ end
@@ -11,7 +11,7 @@ module Jekyll
11
11
  module WebmentionIO
12
12
  class WebmentionHeadTag < Liquid::Tag
13
13
  def render(context)
14
- head = String.new ""
14
+ head = +"" # unfrozen String
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">'
@@ -27,14 +27,15 @@ module Jekyll
27
27
  config = config.merge(site_config)
28
28
 
29
29
  # JS file
30
- js = String.new ""
30
+ js = +"" # unfrozen String
31
31
  unless config["deploy"] == false
32
- js_file_path = "#{site.config["baseurl"]}/#{config["destination"]}/JekyllWebmentionIO.js"
32
+ destination = config["destination"].chomp("/").reverse.chomp("/").reverse # removes prefix & suffix "/"
33
+ js_file_path = "#{site.config["baseurl"]}/#{destination}/JekyllWebmentionIO.js"
33
34
  js << "<script src=\"#{js_file_path}\" async></script>"
34
35
  end
35
36
 
36
37
  Jekyll::WebmentionIO.log "info", "Gathering templates for JavaScript."
37
- templates = String.new ""
38
+ templates = +"" # unfrozen String
38
39
  template_files = Jekyll::WebmentionIO.types + %w(count webmentions)
39
40
  template_files.each do |template|
40
41
  templates << "<template style=\"display:none\" id=\"webmention-#{template}\">"
@@ -41,21 +41,21 @@ module Jekyll
41
41
  OpenSSL::SSL::SSLError,
42
42
  ].freeze
43
43
 
44
- def self.bootstrap
45
- # @jekyll_config = Jekyll.configuration({ 'quiet' => true })
46
- @jekyll_config = Jekyll.configuration({})
44
+ def self.bootstrap(site)
45
+ @site = site
46
+ @jekyll_config = site.config
47
47
  @config = @jekyll_config["webmentions"] || {}
48
48
 
49
49
  # Set up the cache folder & files
50
- @cache_folder = @config["cache_folder"] || ".jekyll-cache"
50
+ @cache_folder = site.in_source_dir(@config["cache_folder"] || ".jekyll-cache")
51
51
  Dir.mkdir(@cache_folder) unless File.exist?(@cache_folder)
52
52
  @file_prefix = ""
53
53
  @file_prefix = "webmention_io_" unless @cache_folder.include? "webmention"
54
54
  @cache_files = {
55
- "incoming" => "#{@cache_folder}/#{@file_prefix}received.yml",
56
- "outgoing" => "#{@cache_folder}/#{@file_prefix}outgoing.yml",
57
- "bad_uris" => "#{@cache_folder}/#{@file_prefix}bad_uris.yml",
58
- "lookups" => "#{@cache_folder}/#{@file_prefix}lookups.yml"
55
+ "incoming" => cache_file("received.yml"),
56
+ "outgoing" => cache_file("outgoing.yml"),
57
+ "bad_uris" => cache_file("bad_uris.yml"),
58
+ "lookups" => cache_file("lookups.yml")
59
59
  }
60
60
  @cache_files.each_value do |file|
61
61
  unless File.exist?(file)
@@ -69,7 +69,11 @@ module Jekyll
69
69
  @api_endpoint = "#{@api_url}/#{path}"
70
70
  end
71
71
 
72
- # Heplers
72
+ # Helpers
73
+ def self.cache_file(filename)
74
+ Jekyll.sanitized_path(@cache_folder, "#{@file_prefix}#{filename}")
75
+ end
76
+
73
77
  def self.get_cache_file_path(key)
74
78
  path = false
75
79
  if @cache_files.key? key
@@ -84,9 +88,7 @@ module Jekyll
84
88
  end
85
89
 
86
90
  cache_file = get_cache_file_path which
87
- cached_webmentions = open(cache_file) { |f| YAML.load(f) }
88
-
89
- cached_webmentions
91
+ load_yaml(cache_file)
90
92
  end
91
93
 
92
94
  def self.cache_webmentions(which, webmentions)
@@ -140,8 +142,7 @@ module Jekyll
140
142
 
141
143
  def self.read_lookup_dates()
142
144
  cache_file = get_cache_file_path "lookups"
143
- lookups = open(cache_file) { |f| YAML.load(f) }
144
- lookups
145
+ load_yaml(cache_file)
145
146
  end
146
147
 
147
148
  def self.cache_lookup_dates(lookups)
@@ -286,6 +287,14 @@ module Jekyll
286
287
  File.open(file, "wb") { |f| f.puts YAML.dump(data) }
287
288
  end
288
289
 
290
+ # Utility Method
291
+ # Safely parse given YAML +file+ path and return data.
292
+ #
293
+ # Returns empty hash if parsing fails to return data
294
+ def self.load_yaml(file)
295
+ SafeYAML.load_file(file) || {}
296
+ end
297
+
289
298
  private
290
299
 
291
300
  def self.get_http_response(uri)
@@ -315,7 +324,7 @@ module Jekyll
315
324
  # Never cache webmention.io in here
316
325
  return if uri.host == "webmention.io"
317
326
  cache_file = @cache_files["bad_uris"]
318
- bad_uris = open(cache_file) { |f| YAML.load(f) }
327
+ bad_uris = load_yaml(cache_file)
319
328
  bad_uris[uri.host] = Time.now.to_s
320
329
  dump_yaml(cache_file, bad_uris)
321
330
  end
@@ -323,7 +332,7 @@ module Jekyll
323
332
  def self.uri_ok?(uri)
324
333
  uri = URI.parse(URI.encode(uri))
325
334
  now = Time.now.to_s
326
- bad_uris = open(@cache_files["bad_uris"]) { |f| YAML.load(f) }
335
+ bad_uris = load_yaml(@cache_files["bad_uris"])
327
336
  if bad_uris.key? uri.host
328
337
  last_checked = DateTime.parse(bad_uris[uri.host])
329
338
  cache_bad_uris_for = @config["cache_bad_uris_for"] || 1 # in days
@@ -345,5 +354,6 @@ end
345
354
  require_all "commands"
346
355
  require_all "generators"
347
356
 
348
- require_relative "tags/_.rb"
357
+ require_relative "tags/webmention"
358
+ require_relative "tags/webmention_type"
349
359
  require_all "tags"
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module WebmentionIO
5
- VERSION = "2.9.7"
5
+ VERSION = "3.0.0"
6
6
  end
7
7
  end
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.7
4
+ version: 3.0.0
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-09-04 00:00:00.000000000 Z
11
+ date: 2018-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -232,7 +232,6 @@ files:
232
232
  - lib/jekyll/generators/compile_js.rb
233
233
  - lib/jekyll/generators/gather_webmentions.rb
234
234
  - lib/jekyll/generators/queue_webmentions.rb
235
- - lib/jekyll/tags/_.rb
236
235
  - lib/jekyll/tags/bookmarks.rb
237
236
  - lib/jekyll/tags/count.rb
238
237
  - lib/jekyll/tags/likes.rb
@@ -241,6 +240,8 @@ files:
241
240
  - lib/jekyll/tags/replies.rb
242
241
  - lib/jekyll/tags/reposts.rb
243
242
  - lib/jekyll/tags/rsvps.rb
243
+ - lib/jekyll/tags/webmention.rb
244
+ - lib/jekyll/tags/webmention_type.rb
244
245
  - lib/jekyll/tags/webmentions.rb
245
246
  - lib/jekyll/tags/webmentions_head.rb
246
247
  - lib/jekyll/tags/webmentions_js.rb