18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/jekyll/commands/webmention.rb', line 18
def self.process(_args = [], options = {})
options = configuration_from_options(options)
WebmentionIO.bootstrap(Jekyll::Site.new(options))
if File.exist? WebmentionIO.cache_file("sent.yml")
WebmentionIO.log "error", "Your outgoing webmentions queue needs to be upgraded. Please re-build your project."
end
WebmentionIO.log "msg", "Getting ready to send webmentions (this may take a while)."
count = 0
max_attempts = WebmentionIO.max_attempts()
cached_outgoing = WebmentionIO.get_cache_file_path "outgoing"
if File.exist?(cached_outgoing)
outgoing = WebmentionIO.load_yaml(cached_outgoing)
outgoing.each do |source, targets|
targets.each do |target, response|
next unless response == false or response.instance_of? Integer
next if target.index("//").zero?
escaped = URI::Parser.new.escape(target);
next unless WebmentionIO.uri_ok?(escaped)
response = (response || 0) + 1
if ! max_attempts.nil? and response > max_attempts
outgoing[source][target] = ""
WebmentionIO.log "msg", "Giving up sending from #{source} to #{target}."
next
else
outgoing[source][target] = response
end
endpoint = WebmentionIO.get_webmention_endpoint(escaped)
next unless endpoint
response = WebmentionIO.webmention(source, target)
next unless response
begin
response = JSON.parse response
rescue JSON::ParserError
response = ""
end
outgoing[source][target] = response
count += 1
end
end
WebmentionIO.dump_yaml(cached_outgoing, outgoing)
WebmentionIO.log "msg", "#{count} webmentions sent."
end end
|