jekyll-webmention_io 2.3.0 → 2.5.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02faf38bb1fff4fb2fdb3e3274bbef6a97374912
|
4
|
+
data.tar.gz: 4f15f2fc0a505a8cabed08d870dd03cfb434add7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a99c35424a946da6fd8eaed7c00311bab66787f970c9f91d0c79c466bd4f6b3bc7a0816bb8288f3ef467fead2a8ae8613e2dde9a47c34b13d34133d6026e40c6
|
7
|
+
data.tar.gz: 4556763d36bea886bd93df5f6f8ba8516a83f5920ed2dad23a0add451bb8cce68120afd911d4b74e208b9677936e692d658f1cf8562718ff0fead673a1b3bc7b
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module Jekyll
|
2
4
|
module Commands
|
3
5
|
class WebmentionCommand < Command
|
@@ -11,21 +13,16 @@ module Jekyll
|
|
11
13
|
end
|
12
14
|
|
13
15
|
def self.process( args=[], options={} )
|
16
|
+
if File.exists? "#{Jekyll::WebmentionIO::cache_folder}/#{Jekyll::WebmentionIO::file_prefix}sent.yml"
|
17
|
+
Jekyll::WebmentionIO::log 'error', 'Your outgoing webmentions queue needs to be upgraded. Please re-build your project.'
|
18
|
+
end
|
19
|
+
count = 0
|
14
20
|
cached_outgoing = Jekyll::WebmentionIO::get_cache_file_path 'outgoing'
|
15
|
-
cached_sent = Jekyll::WebmentionIO::get_cache_file_path 'sent'
|
16
21
|
if File.exists?(cached_outgoing)
|
17
|
-
if File.exists?(cached_sent)
|
18
|
-
sent = open(cached_sent) { |f| YAML.load(f) }
|
19
|
-
else
|
20
|
-
sent = {}
|
21
|
-
end # file exists (sent)
|
22
22
|
outgoing = open(cached_outgoing) { |f| YAML.load(f) }
|
23
|
-
outgoing.
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
targets.each do |target|
|
28
|
-
if target and ! sent[source].find_index( target )
|
23
|
+
outgoing.each do |source, targets|
|
24
|
+
targets.each do |target, response|
|
25
|
+
if response === false
|
29
26
|
if target.index( "//" ) == 0
|
30
27
|
target = "http:#{target}"
|
31
28
|
end
|
@@ -33,13 +30,17 @@ module Jekyll
|
|
33
30
|
if endpoint
|
34
31
|
response = Jekyll::WebmentionIO::webmention( source, target, endpoint )
|
35
32
|
if response
|
36
|
-
|
33
|
+
outgoing[source][target] = JSON.parse response.body
|
34
|
+
count += 1
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
40
38
|
end
|
41
39
|
end
|
42
|
-
|
40
|
+
if count > 0
|
41
|
+
File.open(cached_outgoing, 'w') { |f| YAML.dump(outgoing, f) }
|
42
|
+
end
|
43
|
+
Jekyll::WebmentionIO::log 'info', "#{count} webmentions sent."
|
43
44
|
end # file exists (outgoing)
|
44
45
|
end # def process
|
45
46
|
end # WebmentionCommand
|
@@ -24,11 +24,7 @@ module Jekyll
|
|
24
24
|
Jekyll::WebmentionIO::set_api_suffix('&perPage=9999')
|
25
25
|
|
26
26
|
cache_file = Jekyll::WebmentionIO::get_cache_file_path 'incoming'
|
27
|
-
|
28
|
-
@cached_webmentions = open(cache_file) { |f| YAML.load(f) }
|
29
|
-
else
|
30
|
-
@cached_webmentions = {}
|
31
|
-
end
|
27
|
+
@cached_webmentions = open(cache_file) { |f| YAML.load(f) }
|
32
28
|
|
33
29
|
if Jekyll::VERSION >= "3.0.0"
|
34
30
|
posts = site.posts.docs
|
@@ -48,11 +44,19 @@ module Jekyll
|
|
48
44
|
posts.each do |post|
|
49
45
|
# Gather the URLs
|
50
46
|
targets = get_webmention_target_urls(site, post)
|
47
|
+
|
48
|
+
# Get the last id we have in the hash
|
49
|
+
since_id = false
|
50
|
+
if @cached_webmentions.has_key? post.url
|
51
|
+
past_webmentions = @cached_webmentions[post.url]
|
52
|
+
since_id = past_webmentions[past_webmentions.keys.last]['raw']['id']
|
53
|
+
end
|
51
54
|
|
52
55
|
# execute the API
|
53
56
|
api_params = targets.collect { |v| "target[]=#{v}" }.join('&')
|
57
|
+
api_params << "&since_id=#{since_id}" if since_id
|
54
58
|
response = Jekyll::WebmentionIO::get_response(api_params)
|
55
|
-
#
|
59
|
+
# Jekyll::WebmentionIO::log 'info', response.inspect
|
56
60
|
|
57
61
|
process_webmentions( post.url, response )
|
58
62
|
end # posts loop
|
@@ -157,8 +161,8 @@ module Jekyll
|
|
157
161
|
# webmentions[the_date] = {}
|
158
162
|
# end
|
159
163
|
|
160
|
-
# Make sure we have the webmention
|
161
|
-
|
164
|
+
# Make sure we don’t have the webmention
|
165
|
+
unless webmentions.has_key? id
|
162
166
|
|
163
167
|
# Scaffold the webmention
|
164
168
|
webmention = {
|
@@ -237,7 +241,7 @@ module Jekyll
|
|
237
241
|
# @webmention_io.log 'info', webmention.inspect
|
238
242
|
webmentions[id] = webmention
|
239
243
|
|
240
|
-
end #
|
244
|
+
end # Make sure we don’t have the webmention
|
241
245
|
|
242
246
|
end # each link
|
243
247
|
|
@@ -12,44 +12,82 @@ module Jekyll
|
|
12
12
|
priority :low
|
13
13
|
|
14
14
|
def generate(site)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
if site.config['webmentions']['pause_lookups'] == true
|
16
|
+
Jekyll::WebmentionIO::log 'info', 'Webmention lookups are currently paused.'
|
17
|
+
return
|
18
|
+
end
|
19
19
|
|
20
|
-
|
20
|
+
Jekyll::WebmentionIO::log 'info', 'Beginning to gather webmentions you’ve made. This may take a while.'
|
21
21
|
|
22
|
-
|
22
|
+
upgrade_outgoing_webmention_cache()
|
23
|
+
|
24
|
+
cache_file = Jekyll::WebmentionIO::get_cache_file_path 'outgoing'
|
25
|
+
webmentions = open(cache_file) { |f| YAML.load(f) }
|
23
26
|
|
24
27
|
if Jekyll::VERSION >= "3.0.0"
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
28
|
+
posts = site.posts.docs
|
29
|
+
else
|
30
|
+
posts = site.posts
|
31
|
+
end
|
32
|
+
|
30
33
|
posts.each do |post|
|
31
34
|
uri = "#{site.config['url']}#{post.url}"
|
32
|
-
|
35
|
+
mentions = get_mentioned_uris(post)
|
36
|
+
if webmentions.has_key? uri
|
37
|
+
mentions.each do |mentioned_uri, response|
|
38
|
+
unless webmentions[uri].has_key? mentioned_uri
|
39
|
+
webmentions[uri][mentioned_uri] = response
|
40
|
+
end
|
41
|
+
end
|
42
|
+
else
|
43
|
+
webmentions[uri] = mentions
|
44
|
+
end
|
33
45
|
end
|
34
46
|
|
35
|
-
|
47
|
+
cache_file = Jekyll::WebmentionIO::get_cache_file_path 'outgoing'
|
36
48
|
File.open(cache_file, 'w') { |f| YAML.dump(webmentions, f) }
|
37
49
|
|
38
|
-
|
50
|
+
Jekyll::WebmentionIO::log 'info', 'Webmentions have been gathered and cached.'
|
39
51
|
end
|
40
52
|
|
53
|
+
def upgrade_outgoing_webmention_cache
|
54
|
+
old_sent_file = "#{Jekyll::WebmentionIO::cache_folder}/#{Jekyll::WebmentionIO::file_prefix}sent.yml"
|
55
|
+
old_outgoing_file = "#{Jekyll::WebmentionIO::cache_folder}/#{Jekyll::WebmentionIO::file_prefix}queued.yml"
|
56
|
+
unless File.exists? old_sent_file
|
57
|
+
return
|
58
|
+
end
|
59
|
+
sent_webmentions = open(old_sent_file) { |f| YAML.load(f) }
|
60
|
+
outgoing_webmentions = open(old_outgoing_file) { |f| YAML.load(f) }
|
61
|
+
merged = {}
|
62
|
+
outgoing_webmentions.each do |source_url, webmentions|
|
63
|
+
collection = {}
|
64
|
+
webmentions.each do |target_url|
|
65
|
+
if sent_webmentions.has_key? source_url and sent_webmentions[source_url].include? target_url
|
66
|
+
collection[target_url] = ""
|
67
|
+
else
|
68
|
+
collection[target_url] = false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
merged[source_url] = collection
|
72
|
+
end
|
73
|
+
cached_outgoing = Jekyll::WebmentionIO::get_cache_file_path 'outgoing'
|
74
|
+
File.open(cached_outgoing, 'w') { |f| YAML.dump(merged, f) }
|
75
|
+
File.delete old_sent_file, old_outgoing_file
|
76
|
+
Jekyll::WebmentionIO::log 'info', 'Upgraded your sent webmentions cache.'
|
77
|
+
end
|
78
|
+
|
41
79
|
def get_mentioned_uris(post)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
80
|
+
uris = {}
|
81
|
+
if post.data['in_reply_to']
|
82
|
+
uris[post.data['in_reply_to']] = false
|
83
|
+
end
|
84
|
+
post.content.scan(/(?:https?:)?\/\/[^\s)#"]+/) do |match|
|
85
|
+
unless uris.has_key? match
|
86
|
+
uris[match] = false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
return uris
|
90
|
+
end
|
53
91
|
|
54
92
|
end
|
55
93
|
end
|
data/lib/jekyll/webmention_io.rb
CHANGED
@@ -31,17 +31,16 @@ module Jekyll
|
|
31
31
|
@config = @jekyll_config['webmentions'] || {}
|
32
32
|
|
33
33
|
# Set up the cache folder & files
|
34
|
-
cache_folder = @config['cache_folder'] || '.jekyll-cache'
|
35
|
-
Dir.mkdir(cache_folder) unless File.exists?(cache_folder)
|
36
|
-
file_prefix = ''
|
37
|
-
if ! cache_folder.include? 'webmention'
|
38
|
-
file_prefix = 'webmention_io_'
|
34
|
+
@cache_folder = @config['cache_folder'] || '.jekyll-cache'
|
35
|
+
Dir.mkdir(@cache_folder) unless File.exists?(@cache_folder)
|
36
|
+
@file_prefix = ''
|
37
|
+
if ! @cache_folder.include? 'webmention'
|
38
|
+
@file_prefix = 'webmention_io_'
|
39
39
|
end
|
40
40
|
@cache_files = {
|
41
|
-
'incoming' => "#{cache_folder}/#{file_prefix}received.yml",
|
42
|
-
'outgoing' => "#{cache_folder}/#{file_prefix}
|
43
|
-
'
|
44
|
-
'bad_uris' => "#{cache_folder}/#{file_prefix}bad_uris.yml"
|
41
|
+
'incoming' => "#{@cache_folder}/#{@file_prefix}received.yml",
|
42
|
+
'outgoing' => "#{@cache_folder}/#{@file_prefix}outgoing.yml",
|
43
|
+
'bad_uris' => "#{@cache_folder}/#{@file_prefix}bad_uris.yml"
|
45
44
|
}
|
46
45
|
@cache_files.each do |key, file|
|
47
46
|
if ! File.exists?(file)
|
@@ -60,6 +59,12 @@ module Jekyll
|
|
60
59
|
def self.cache_files
|
61
60
|
@cache_files
|
62
61
|
end
|
62
|
+
def self.cache_folder
|
63
|
+
@cache_folder
|
64
|
+
end
|
65
|
+
def self.file_prefix
|
66
|
+
@file_prefix
|
67
|
+
end
|
63
68
|
def self.types
|
64
69
|
@types
|
65
70
|
end
|
@@ -98,18 +103,24 @@ module Jekyll
|
|
98
103
|
end
|
99
104
|
|
100
105
|
def self.get_webmention_endpoint( uri )
|
101
|
-
log 'info', "Looking for webmention endpoint at #{uri}"
|
106
|
+
# log 'info', "Looking for webmention endpoint at #{uri}"
|
102
107
|
endpoint = Webmention::Client.supports_webmention?( uri )
|
103
|
-
if ! endpoint
|
104
|
-
|
105
|
-
end
|
108
|
+
# if ! endpoint
|
109
|
+
# log 'info', "No webmention endpoint at #{uri}"
|
110
|
+
# end
|
106
111
|
endpoint
|
107
112
|
end
|
108
113
|
|
109
114
|
def self.webmention( source, target, endpoint )
|
110
|
-
log 'info', "Sending webmention of #{target} in #{source}
|
115
|
+
log 'info', "Sending webmention of #{target} in #{source}"
|
111
116
|
#return `curl -s -i -d \"source=#{source}&target=#{target}\" -o /dev/null #{endpoint}`
|
112
|
-
|
117
|
+
response = Webmention::Client.send_mention( endpoint, source, target, true )
|
118
|
+
if response
|
119
|
+
log 'info', "Webmention successful!"
|
120
|
+
else
|
121
|
+
log 'info', "Webmention failed, but will remain queued for next time"
|
122
|
+
end
|
123
|
+
response
|
113
124
|
end
|
114
125
|
|
115
126
|
# Utilities
|
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.
|
4
|
+
version: 2.5.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: 2017-07-
|
11
|
+
date: 2017-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|