jekyll-webmention_io 2.8.5 → 2.9.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.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # (c) Aaron Gustafson
2
4
  # https://github.com/aarongustafson/jekyll-webmention_io
3
5
  # Licence : MIT
@@ -11,26 +13,31 @@ module Jekyll
11
13
  priority :low
12
14
 
13
15
  def generate(site)
14
- if site.config.dig("webmentions", "pause_lookups") == true
16
+ @site = site
17
+
18
+ if @site.config.dig("webmentions", "pause_lookups")
15
19
  Jekyll::WebmentionIO.log "info", "Webmention lookups are currently paused."
16
20
  return
17
21
  end
18
22
 
19
- Jekyll::WebmentionIO.log "info", "Beginning to gather webmentions you’ve made. This may take a while."
23
+ Jekyll::WebmentionIO.log "msg", "Beginning to gather webmentions you’ve made. This may take a while."
20
24
 
21
25
  upgrade_outgoing_webmention_cache
22
26
 
23
- cache_file = Jekyll::WebmentionIO.get_cache_file_path "outgoing"
24
- webmentions = open(cache_file) { |f| YAML.safe_load(f) }
27
+ posts = Jekyll::WebmentionIO.gather_documents(@site)
28
+
29
+ gather_webmentions(posts)
30
+ end
31
+
32
+ private
33
+
34
+ def gather_webmentions(posts)
35
+ webmentions = Jekyll::WebmentionIO.read_cached_webmentions "outgoing"
25
36
 
26
- posts = if Jekyll::VERSION >= "3.0.0"
27
- site.posts.docs
28
- else
29
- site.posts
30
- end
37
+ base_uri = @site.config["url"].chomp("/")
31
38
 
32
39
  posts.each do |post|
33
- uri = "#{site.config["url"]}#{post.url}"
40
+ uri = "#{base_uri}#{post.url}"
34
41
  mentions = get_mentioned_uris(post)
35
42
  if webmentions.key? uri
36
43
  mentions.each do |mentioned_uri, response|
@@ -43,10 +50,20 @@ module Jekyll
43
50
  end
44
51
  end
45
52
 
46
- cache_file = Jekyll::WebmentionIO.get_cache_file_path "outgoing"
47
- File.open(cache_file, "w") { |f| YAML.dump(webmentions, f) }
53
+ Jekyll::WebmentionIO.cache_webmentions "outgoing", webmentions
54
+ end
48
55
 
49
- Jekyll::WebmentionIO.log "info", "Webmentions have been gathered and cached."
56
+ def get_mentioned_uris(post)
57
+ uris = {}
58
+ if post.data["in_reply_to"]
59
+ uris[post.data["in_reply_to"]] = false
60
+ end
61
+ post.content.scan(/(?:https?:)?\/\/[^\s)#"]+/) do |match|
62
+ unless uris.key? match
63
+ uris[match] = false
64
+ end
65
+ end
66
+ return uris
50
67
  end
51
68
 
52
69
  def upgrade_outgoing_webmention_cache
@@ -55,8 +72,8 @@ module Jekyll
55
72
  unless File.exist? old_sent_file
56
73
  return
57
74
  end
58
- sent_webmentions = open(old_sent_file) { |f| YAML.safe_load(f) }
59
- outgoing_webmentions = open(old_outgoing_file) { |f| YAML.safe_load(f) }
75
+ sent_webmentions = open(old_sent_file) { |f| YAML.load(f) }
76
+ outgoing_webmentions = open(old_outgoing_file) { |f| YAML.load(f) }
60
77
  merged = {}
61
78
  outgoing_webmentions.each do |source_url, webmentions|
62
79
  collection = {}
@@ -69,23 +86,9 @@ module Jekyll
69
86
  end
70
87
  merged[source_url] = collection
71
88
  end
72
- cached_outgoing = Jekyll::WebmentionIO.get_cache_file_path "outgoing"
73
- File.open(cached_outgoing, "w") { |f| YAML.dump(merged, f) }
89
+ Jekyll::WebmentionIO.cache_webmentions "outgoing", merged
74
90
  File.delete old_sent_file, old_outgoing_file
75
- Jekyll::WebmentionIO.log "info", "Upgraded your sent webmentions cache."
76
- end
77
-
78
- def get_mentioned_uris(post)
79
- uris = {}
80
- if post.data["in_reply_to"]
81
- uris[post.data["in_reply_to"]] = false
82
- end
83
- post.content.scan(/(?:https?:)?\/\/[^\s)#"]+/) do |match|
84
- unless uris.key? match
85
- uris[match] = false
86
- end
87
- end
88
- return uris
91
+ Jekyll::WebmentionIO.log "msg", "Upgraded your sent webmentions cache."
89
92
  end
90
93
  end
91
94
  end
data/lib/jekyll/tags/_.rb CHANGED
@@ -1,71 +1,67 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # (c) Aaron Gustafson
2
- # https://github.com/aarongustafson/jekyll-webmention_io
4
+ # https://github.com/aarongustafson/jekyll-webmention_io
3
5
  # Licence : MIT
4
- #
6
+ #
5
7
  # Base webmention tag
6
8
  #
7
9
 
8
- require 'htmlbeautifier'
10
+ require "htmlbeautifier"
9
11
 
10
12
  module Jekyll
11
13
  module WebmentionIO
12
14
  using StringInflection
13
15
  class WebmentionTag < Liquid::Tag
14
-
15
- def initialize(tagName, text, tokens)
16
+ def initialize(tag_name, text, tokens)
16
17
  super
17
- cache_file = Jekyll::WebmentionIO::get_cache_file_path 'incoming'
18
- if File.exists?(cache_file)
19
- @cached_webmentions = open(cache_file) { |f| YAML.load(f) }
20
- else
21
- @cached_webmentions = {}
22
- end
18
+ cache_file = Jekyll::WebmentionIO.get_cache_file_path "incoming"
19
+ @cached_webmentions = if File.exist? cache_file
20
+ open(cache_file) { |f| YAML.load(f) }
21
+ else
22
+ {}
23
+ end
23
24
  end
24
25
 
25
26
  def lookup(context, name)
26
27
  lookup = context
27
- name&.split('.')&.each do |value|
28
+ name&.split(".")&.each do |value|
28
29
  lookup = lookup[value]
29
30
  end
30
31
  lookup
31
32
  end
32
-
33
- def set_template( template )
34
- supported_templates = Jekyll::WebmentionIO::types + ['count', 'webmentions']
35
- Jekyll::WebmentionIO::log 'error', "#{template} is not supported" if ! supported_templates.include? template
36
- @template = Jekyll::WebmentionIO::get_template_contents( template )
37
- # Jekyll::WebmentionIO::log 'info', "template: #{@template}"
33
+
34
+ def template=(template)
35
+ supported_templates = Jekyll::WebmentionIO.types + %w(count webmentions)
36
+ Jekyll::WebmentionIO.log "error", "#{template.capitalize} is not supported" unless supported_templates.include? template
37
+ @template_name = template
38
+ @template = Jekyll::WebmentionIO.get_template_contents(template)
39
+ Jekyll::WebmentionIO.log "info", "#{template.capitalize} template:\n\n#{@template}\n\n"
38
40
  end
39
41
 
40
- def set_data( data, types )
41
- @data = { 'webmentions' => data, 'types' => types }
42
+ def set_data(data, types)
43
+ @data = { "webmentions" => data, "types" => types }
42
44
  end
43
45
 
44
- def extract_type( type, webmentions )
45
- # Jekyll::WebmentionIO::log 'info', "Looking for #{type}"
46
+ def extract_type(type, webmentions)
47
+ Jekyll::WebmentionIO.log "info", "Looking for #{type}"
46
48
  keep = {}
47
- if ! Jekyll::WebmentionIO::types.include? type
48
- Jekyll::WebmentionIO::log 'warn', "#{type} are not extractable"
49
+ if !Jekyll::WebmentionIO.types.include? type
50
+ Jekyll::WebmentionIO.log "warn", "#{type} are not extractable"
49
51
  else
50
52
  type = type.to_singular
51
- # Jekyll::WebmentionIO::log 'info', "Searching #{webmentions.length} webmentions for type==#{type}"
53
+ Jekyll::WebmentionIO.log "info", "Searching #{webmentions.length} webmentions for type==#{type}"
52
54
  if webmentions.is_a? Hash
53
55
  webmentions = webmentions.values
54
56
  end
55
57
  webmentions.each do |webmention|
56
- keep[webmention['id']] = webmention if webmention['type'] == type
58
+ keep[webmention["id"]] = webmention if webmention["type"] == type
57
59
  end
58
60
  end
59
61
  keep
60
62
  end
61
63
 
62
- def sort_webmentions( webmentions )
63
- return webmentions.sort_by { |webmention| webmention['pubdate'].to_i }
64
- end
65
-
66
64
  def render(context)
67
- output = super
68
-
69
65
  # Get the URI
70
66
  args = @text.split(/\s+/).map(&:strip)
71
67
  uri = args.shift
@@ -74,20 +70,21 @@ module Jekyll
74
70
  # capture the types in case JS needs them
75
71
  types = []
76
72
 
77
- if @cached_webmentions.has_key? uri
78
- all_webmentions = @cached_webmentions[uri].clone
79
- # Jekyll::WebmentionIO::log 'info', "#{all_webmentions.length} total webmentions for #{uri}"
80
- if args.length > 0
81
- # Jekyll::WebmentionIO::log 'info', "Requesting only #{args.inspect}"
73
+ if @cached_webmentions.key? uri
74
+ all_webmentions = @cached_webmentions[uri].clone
75
+ Jekyll::WebmentionIO.log "info", "#{all_webmentions.length} total webmentions for #{uri}"
76
+
77
+ if args.length.positive?
78
+ Jekyll::WebmentionIO.log "info", "Requesting only #{args.inspect}"
82
79
  webmentions = {}
83
80
  args.each do |type|
84
81
  types.push type
85
- extracted = extract_type( type, all_webmentions )
86
- # Jekyll::WebmentionIO::log 'info', "Merging in #{extracted.length} #{type}"
87
- webmentions = webmentions.merge( extracted )
82
+ extracted = extract_type(type, all_webmentions)
83
+ Jekyll::WebmentionIO.log "info", "Merging in #{extracted.length} #{type}"
84
+ webmentions = webmentions.merge(extracted)
88
85
  end
89
86
  else
90
- # Jekyll::WebmentionIO::log 'info', 'Grabbing all webmentions'
87
+ Jekyll::WebmentionIO.log "info", "Grabbing all webmentions"
91
88
  webmentions = all_webmentions
92
89
  end
93
90
 
@@ -95,32 +92,39 @@ module Jekyll
95
92
  webmentions = webmentions.values
96
93
  end
97
94
 
98
- webmentions = sort_webmentions( webmentions )
99
-
100
- set_data( webmentions, types )
95
+ webmentions = sort_webmentions(webmentions)
96
+ set_data(webmentions, types)
101
97
  end
102
-
103
- args = nil
104
98
 
105
- if @template and @data
106
- # Jekyll::WebmentionIO::log 'info', "Preparing to render\n\n#{@data.inspect}\n\ninto\n\n#{@template}"
99
+ render_into_template
100
+ end
101
+
102
+ private
103
+
104
+ def render_into_template
105
+ if @template && @data
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, { :strict_variables => false, :strict_filters => true })
109
109
  template.errors.each do |error|
110
- Jekyll::WebmentionIO::log 'error', error
110
+ Jekyll::WebmentionIO.log "error", error
111
111
  end
112
112
  # Clean up the output
113
- HtmlBeautifier.beautify html.each_line.reject{|x| x.strip == ""}.join
113
+ HtmlBeautifier.beautify html.each_line.reject { |x| x.strip == "" }.join
114
114
  else
115
- if ! @template
116
- Jekyll::WebmentionIO::log 'warn', "#{self.class} No template provided"
115
+ unless @template
116
+ Jekyll::WebmentionIO.log "warn", "#{self.class} No template provided"
117
117
  end
118
- if ! @data
119
- Jekyll::WebmentionIO::log 'warn', "#{self.class} No data provided"
118
+ unless @data
119
+ Jekyll::WebmentionIO.log "warn", "#{self.class} No data provided"
120
120
  end
121
121
  ""
122
122
  end
123
123
  end
124
+
125
+ def sort_webmentions(webmentions)
126
+ return webmentions.sort_by { |webmention| webmention["pubdate"].to_i }
127
+ end
124
128
  end
125
129
  end
126
- end
130
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: false
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 Jekill blog
8
+ # using http://webmention.io/ and the following syntax:
9
+ #
10
+ # {% webmention_bookmarks post.url %}
11
+ #
12
+ module Jekyll
13
+ module WebmentionIO
14
+ class WebmentionBookmarksTag < Jekyll::WebmentionIO::WebmentionTag
15
+ def initialize(tag_name, text, tokens)
16
+ super
17
+ @text = text
18
+ self.template = "bookmarks"
19
+ end
20
+
21
+ def set_data(data, _types)
22
+ webmentions = extract_type "bookmarks", data
23
+ @data = { "webmentions" => webmentions.values }
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ Liquid::Template.register_tag("webmention_bookmarks", Jekyll::WebmentionIO::WebmentionBookmarksTag)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # (c) Aaron Gustafson
2
4
  # https://github.com/aarongustafson/jekyll-webmention_io
3
5
  # Licence : MIT
@@ -5,15 +7,15 @@
5
7
  # this liquid plugin insert a webmentions into your Octopress or Jekill blog
6
8
  # using http://webmention.io/ and the following syntax:
7
9
  #
8
- # {% webmention_count post.url [ likes | links | posts | replies | reposts ]* %}
10
+ # {% webmention_count post.url [ bookmarks | likes | links | posts | replies | reposts | rsvps ]* %}
9
11
  #
10
12
  module Jekyll
11
13
  module WebmentionIO
12
14
  class WebmentionCountTag < Jekyll::WebmentionIO::WebmentionTag
13
- def initialize(tagName, text, tokens)
15
+ def initialize(tag_name, text, tokens)
14
16
  super
15
17
  @text = text
16
- set_template "count"
18
+ self.template = "count"
17
19
  end
18
20
 
19
21
  def set_data(data, types)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # (c) Aaron Gustafson
2
4
  # https://github.com/aarongustafson/jekyll-webmention_io
3
5
  # Licence : MIT
@@ -10,10 +12,10 @@
10
12
  module Jekyll
11
13
  module WebmentionIO
12
14
  class WebmentionLikesTag < Jekyll::WebmentionIO::WebmentionTag
13
- def initialize(tagName, text, tokens)
15
+ def initialize(tag_name, text, tokens)
14
16
  super
15
17
  @text = text
16
- set_template "likes"
18
+ self.template = "likes"
17
19
  end
18
20
 
19
21
  def set_data(data, _types)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # (c) Aaron Gustafson
2
4
  # https://github.com/aarongustafson/jekyll-webmention_io
3
5
  # Licence : MIT
@@ -10,10 +12,10 @@
10
12
  module Jekyll
11
13
  module WebmentionIO
12
14
  class WebmentionLinksTag < Jekyll::WebmentionIO::WebmentionTag
13
- def initialize(tagName, text, tokens)
15
+ def initialize(tag_name, text, tokens)
14
16
  super
15
17
  @text = text
16
- set_template "links"
18
+ self.template = "links"
17
19
  end
18
20
 
19
21
  def set_data(data, _types)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # (c) Aaron Gustafson
2
4
  # https://github.com/aarongustafson/jekyll-webmention_io
3
5
  # Licence : MIT
@@ -9,11 +11,11 @@
9
11
  #
10
12
  module Jekyll
11
13
  module WebmentionIO
12
- class WebmentionRepostsTag < Jekyll::WebmentionIO::WebmentionTag
13
- def initialize(tagName, text, tokens)
14
+ class WebmentionPostsTag < Jekyll::WebmentionIO::WebmentionTag
15
+ def initialize(tag_name, text, tokens)
14
16
  super
15
17
  @text = text
16
- set_template "posts"
18
+ self.template = "posts"
17
19
  end
18
20
 
19
21
  def set_data(data, _types)
@@ -24,4 +26,4 @@ module Jekyll
24
26
  end
25
27
  end
26
28
 
27
- Liquid::Template.register_tag("webmention_posts", Jekyll::WebmentionIO::WebmentionRepostsTag)
29
+ Liquid::Template.register_tag("webmention_posts", Jekyll::WebmentionIO::WebmentionPostsTag)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # (c) Aaron Gustafson
2
4
  # https://github.com/aarongustafson/jekyll-webmention_io
3
5
  # Licence : MIT
@@ -10,10 +12,10 @@
10
12
  module Jekyll
11
13
  module WebmentionIO
12
14
  class WebmentionRepliesTag < Jekyll::WebmentionIO::WebmentionTag
13
- def initialize(tagName, text, tokens)
15
+ def initialize(tag_name, text, tokens)
14
16
  super
15
17
  @text = text
16
- set_template "replies"
18
+ self.template = "replies"
17
19
  end
18
20
 
19
21
  def set_data(data, _types)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  # (c) Aaron Gustafson
2
4
  # https://github.com/aarongustafson/jekyll-webmention_io
3
5
  # Licence : MIT
@@ -10,10 +12,10 @@
10
12
  module Jekyll
11
13
  module WebmentionIO
12
14
  class WebmentionRepostsTag < Jekyll::WebmentionIO::WebmentionTag
13
- def initialize(tagName, text, tokens)
15
+ def initialize(tag_name, text, tokens)
14
16
  super
15
17
  @text = text
16
- set_template "reposts"
18
+ self.template = "reposts"
17
19
  end
18
20
 
19
21
  def set_data(data, _types)