jekyll-webmention_io 3.1.0 → 3.2.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 +4 -4
- data/lib/jekyll/commands/webmention.rb +11 -8
- data/lib/jekyll/generators/compile_js.rb +5 -5
- data/lib/jekyll/generators/gather_webmentions.rb +120 -118
- data/lib/jekyll/generators/queue_webmentions.rb +67 -66
- data/lib/jekyll/tags/webmention.rb +18 -18
- data/lib/jekyll/tags/webmentions_head.rb +3 -2
- data/lib/jekyll/tags/webmentions_js.rb +1 -1
- data/lib/jekyll/webmention_io.rb +17 -13
- data/lib/jekyll/webmention_io/js_handler.rb +4 -4
- data/lib/jekyll/webmention_io/version.rb +1 -1
- data/lib/jekyll/webmention_io/webmention.rb +2 -8
- metadata +19 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9d0274bb949c53137ce51261e4c2ff534b85806
|
4
|
+
data.tar.gz: 94dc7afb53715fb5e6661b9fa7fad76cc225e2ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed77eae6a0645a492b91a3e7d75aedf006e684290735cee508ec6fd5385cadad0530e47f59b29450c1398bec096c202aa13c30ee4542a6cfd2c425c6b6fba640
|
7
|
+
data.tar.gz: 8b60976284215965fc4295c444a6059ab5f5409dfa4a6ffa650c03900322f8614d00ec53271d58e1bc5c7a7b98387809f9a7d850a3bd9a41433398cfad8c4871
|
@@ -15,23 +15,26 @@ module Jekyll
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def self.process(_args = [], _options = {})
|
18
|
-
if File.exist?
|
19
|
-
|
18
|
+
if File.exist? WebmentionIO.cache_file("sent.yml")
|
19
|
+
WebmentionIO.log "error", "Your outgoing webmentions queue needs to be upgraded. Please re-build your project."
|
20
20
|
end
|
21
21
|
count = 0
|
22
|
-
cached_outgoing =
|
22
|
+
cached_outgoing = WebmentionIO.get_cache_file_path "outgoing"
|
23
23
|
if File.exist?(cached_outgoing)
|
24
|
-
outgoing =
|
24
|
+
outgoing = 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
|
28
|
+
|
28
29
|
if target.index("//").zero?
|
29
30
|
target = "http:#{target}"
|
30
31
|
end
|
31
|
-
endpoint =
|
32
|
+
endpoint = WebmentionIO.get_webmention_endpoint(target)
|
32
33
|
next unless endpoint
|
33
|
-
|
34
|
+
|
35
|
+
response = WebmentionIO.webmention(source, target, endpoint)
|
34
36
|
next unless response
|
37
|
+
|
35
38
|
begin
|
36
39
|
response = JSON.parse response
|
37
40
|
rescue JSON::ParserError
|
@@ -42,9 +45,9 @@ module Jekyll
|
|
42
45
|
end
|
43
46
|
end
|
44
47
|
if count.positive?
|
45
|
-
|
48
|
+
WebmentionIO.dump_yaml(cached_outgoing, outgoing)
|
46
49
|
end
|
47
|
-
|
50
|
+
WebmentionIO.log "msg", "#{count} webmentions sent."
|
48
51
|
end # file exists (outgoing)
|
49
52
|
end # def process
|
50
53
|
end # WebmentionCommand
|
@@ -13,7 +13,7 @@ module Jekyll
|
|
13
13
|
module WebmentionIO
|
14
14
|
class JavaScriptFile < StaticFile
|
15
15
|
def destination_rel_dir
|
16
|
-
|
16
|
+
WebmentionIO.js_handler.destination
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -23,12 +23,12 @@ module Jekyll
|
|
23
23
|
priority :low
|
24
24
|
|
25
25
|
def generate(site)
|
26
|
-
handler =
|
26
|
+
handler = WebmentionIO.js_handler
|
27
27
|
@site = site
|
28
28
|
@file_name = handler.resource_name
|
29
29
|
|
30
30
|
if handler.disabled?
|
31
|
-
|
31
|
+
WebmentionIO.log "info", "Skipping JavaScript inclusion."
|
32
32
|
return
|
33
33
|
end
|
34
34
|
|
@@ -52,7 +52,7 @@ module Jekyll
|
|
52
52
|
|
53
53
|
def add_webmention_types
|
54
54
|
js_types = []
|
55
|
-
|
55
|
+
WebmentionIO.types.each do |type|
|
56
56
|
js_types.push "'#{type}': '#{type.to_singular}'"
|
57
57
|
end
|
58
58
|
types_js = <<-EOF
|
@@ -82,7 +82,7 @@ module Jekyll
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def deploy_js_file
|
85
|
-
js_file =
|
85
|
+
js_file = WebmentionIO::JavaScriptFile.new(@site, @source_file_destination, "", @file_name)
|
86
86
|
@site.static_files << js_file
|
87
87
|
end
|
88
88
|
end
|
@@ -10,155 +10,157 @@
|
|
10
10
|
require "time"
|
11
11
|
|
12
12
|
module Jekyll
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
def generate(site)
|
18
|
-
@site = site
|
19
|
-
|
20
|
-
if @site.config.dig("url").include? 'localhost'
|
21
|
-
Jekyll::WebmentionIO.log "msg", "Webmentions won’t be gathered on localhost."
|
22
|
-
return
|
23
|
-
end
|
13
|
+
module WebmentionIO
|
14
|
+
class GatherWebmentions < Generator
|
15
|
+
safe true
|
16
|
+
priority :high
|
24
17
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
18
|
+
def generate(site)
|
19
|
+
@site = site
|
20
|
+
@site_url = site.config["url"].to_s
|
29
21
|
|
30
|
-
|
22
|
+
if @site_url.include? "localhost"
|
23
|
+
Jekyll::WebmentionIO.log "msg", "Webmentions won’t be gathered on localhost."
|
24
|
+
return
|
25
|
+
end
|
31
26
|
|
32
|
-
|
33
|
-
|
34
|
-
|
27
|
+
if @site.config.dig("webmentions", "pause_lookups") == true
|
28
|
+
WebmentionIO.log "msg", "Webmention gathering is currently paused."
|
29
|
+
return
|
30
|
+
end
|
35
31
|
|
36
|
-
|
32
|
+
WebmentionIO.log "msg", "Beginning to gather webmentions of your posts. This may take a while."
|
37
33
|
|
38
|
-
|
34
|
+
WebmentionIO.api_path = "mentions"
|
35
|
+
# add an arbitrarily high perPage to trump pagination
|
36
|
+
WebmentionIO.api_suffix = "&perPage=9999"
|
39
37
|
|
40
|
-
|
41
|
-
posts.each do |post|
|
42
|
-
check_for_webmentions(post)
|
43
|
-
end
|
38
|
+
@cached_webmentions = WebmentionIO.read_cached_webmentions "incoming"
|
44
39
|
|
45
|
-
|
40
|
+
@lookups = WebmentionIO.read_lookup_dates
|
46
41
|
|
47
|
-
|
48
|
-
|
42
|
+
posts = WebmentionIO.gather_documents(@site)
|
43
|
+
posts.each do |post|
|
44
|
+
check_for_webmentions(post)
|
45
|
+
end
|
49
46
|
|
50
|
-
|
47
|
+
WebmentionIO.cache_lookup_dates @lookups
|
51
48
|
|
52
|
-
|
53
|
-
|
49
|
+
WebmentionIO.cache_webmentions "incoming", @cached_webmentions
|
50
|
+
end # generate
|
54
51
|
|
55
|
-
|
52
|
+
private
|
56
53
|
|
57
|
-
|
58
|
-
|
59
|
-
@lookups[post.url]
|
60
|
-
elsif last_webmention
|
61
|
-
Date.parse last_webmention.dig("raw", "verified_date")
|
62
|
-
end
|
54
|
+
def check_for_webmentions(post)
|
55
|
+
WebmentionIO.log "info", "Checking for webmentions of #{post.url}."
|
63
56
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
57
|
+
last_webmention = @cached_webmentions.dig(post.url, @cached_webmentions.dig(post.url)&.keys&.last)
|
58
|
+
|
59
|
+
# get the last webmention
|
60
|
+
last_lookup = if @lookups[post.url]
|
61
|
+
@lookups[post.url]
|
62
|
+
elsif last_webmention
|
63
|
+
Date.parse last_webmention.dig("raw", "verified_date")
|
64
|
+
end
|
65
|
+
|
66
|
+
# should we throttle?
|
67
|
+
if post.respond_to? "date" # Some docs have no date
|
68
|
+
if last_lookup && WebmentionIO.post_should_be_throttled?(post, post.date, last_lookup)
|
69
|
+
WebmentionIO.log "info", "Throttling this post."
|
70
|
+
return
|
71
|
+
end
|
69
72
|
end
|
70
|
-
end
|
71
73
|
|
72
|
-
|
73
|
-
|
74
|
+
# Get the last id we have in the hash
|
75
|
+
since_id = last_webmention ? last_webmention.dig("raw", "id") : false
|
74
76
|
|
75
|
-
|
76
|
-
|
77
|
+
# Gather the URLs
|
78
|
+
targets = get_webmention_target_urls(post)
|
77
79
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
80
|
+
# execute the API
|
81
|
+
response = WebmentionIO.get_response assemble_api_params(targets, since_id)
|
82
|
+
webmentions = response.dig("links")
|
83
|
+
if webmentions && !webmentions.empty?
|
84
|
+
WebmentionIO.log "info", "Here’s what we got back:\n\n#{response.inspect}\n\n"
|
85
|
+
else
|
86
|
+
WebmentionIO.log "info", "No webmentions found."
|
87
|
+
end
|
86
88
|
|
87
|
-
|
88
|
-
|
89
|
-
|
89
|
+
@lookups[post.url] = Date.today
|
90
|
+
cache_new_webmentions(post.url, response)
|
91
|
+
end
|
90
92
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
targets.push(uri)
|
93
|
+
def get_webmention_target_urls(post)
|
94
|
+
targets = []
|
95
|
+
uri = File.join(@site_url, post.url)
|
96
|
+
targets.push(uri)
|
96
97
|
|
97
|
-
|
98
|
-
|
98
|
+
# Redirection?
|
99
|
+
gather_redirected_targets(post, uri, targets)
|
99
100
|
|
100
|
-
|
101
|
-
|
101
|
+
# Domain changed?
|
102
|
+
gather_legacy_targets(uri, targets)
|
102
103
|
|
103
|
-
|
104
|
-
|
104
|
+
targets
|
105
|
+
end
|
105
106
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
targets.push(redirected)
|
112
|
-
elsif post.data["redirect_from"].is_a? Array
|
113
|
-
post.data["redirect_from"].each do |redirect|
|
114
|
-
redirected = uri.sub post.url, redirect
|
107
|
+
def gather_redirected_targets(post, uri, targets)
|
108
|
+
redirected = false
|
109
|
+
if post.data.key? "redirect_from"
|
110
|
+
if post.data["redirect_from"].is_a? String
|
111
|
+
redirected = uri.sub post.url, post.data["redirect_from"]
|
115
112
|
targets.push(redirected)
|
113
|
+
elsif post.data["redirect_from"].is_a? Array
|
114
|
+
post.data["redirect_from"].each do |redirect|
|
115
|
+
redirected = uri.sub post.url, redirect
|
116
|
+
targets.push(redirected)
|
117
|
+
end
|
116
118
|
end
|
117
119
|
end
|
118
120
|
end
|
119
|
-
end
|
120
121
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
122
|
+
def gather_legacy_targets(uri, targets)
|
123
|
+
if WebmentionIO.config.key? "legacy_domains"
|
124
|
+
WebmentionIO.log "info", "adding legacy URIs"
|
125
|
+
WebmentionIO.config["legacy_domains"].each do |domain|
|
126
|
+
legacy = uri.sub(@site_url, domain)
|
127
|
+
WebmentionIO.log "info", "adding URI #{legacy}"
|
128
|
+
targets.push(legacy)
|
129
|
+
end
|
128
130
|
end
|
129
131
|
end
|
130
|
-
end
|
131
|
-
|
132
|
-
def assemble_api_params(targets, since_id)
|
133
|
-
api_params = targets.collect { |v| "target[]=#{v}" }.join("&")
|
134
|
-
api_params << "&since_id=#{since_id}" if since_id
|
135
|
-
api_params << "&sort-by=published"
|
136
|
-
api_params
|
137
|
-
end
|
138
132
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
end
|
146
|
-
|
147
|
-
if response && response["links"]
|
148
|
-
response["links"].reverse_each do |link|
|
149
|
-
webmention = Jekyll::WebmentionIO::Webmention.new(link, @site)
|
150
|
-
|
151
|
-
# Do we already have it?
|
152
|
-
if webmentions.key? webmention.id
|
153
|
-
next
|
154
|
-
end
|
133
|
+
def assemble_api_params(targets, since_id)
|
134
|
+
api_params = targets.collect { |v| "target[]=#{v}" }.join("&")
|
135
|
+
api_params << "&since_id=#{since_id}" if since_id
|
136
|
+
api_params << "&sort-by=published"
|
137
|
+
api_params
|
138
|
+
end
|
155
139
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
140
|
+
def cache_new_webmentions(post_uri, response)
|
141
|
+
# Get cached webmentions
|
142
|
+
webmentions = if @cached_webmentions.key? post_uri
|
143
|
+
@cached_webmentions[post_uri]
|
144
|
+
else
|
145
|
+
{}
|
146
|
+
end
|
147
|
+
|
148
|
+
if response && response["links"]
|
149
|
+
response["links"].reverse_each do |link|
|
150
|
+
webmention = WebmentionIO::Webmention.new(link, @site)
|
151
|
+
|
152
|
+
# Do we already have it?
|
153
|
+
if webmentions.key? webmention.id
|
154
|
+
next
|
155
|
+
end
|
156
|
+
|
157
|
+
# Add it to the list
|
158
|
+
WebmentionIO.log "info", webmention.to_hash.inspect
|
159
|
+
webmentions[webmention.id] = webmention.to_hash
|
160
|
+
end # each link
|
161
|
+
end # if response
|
162
|
+
@cached_webmentions[post_uri] = webmentions
|
163
|
+
end # process_webmentions
|
164
|
+
end
|
163
165
|
end
|
164
166
|
end
|
@@ -8,92 +8,93 @@
|
|
8
8
|
#
|
9
9
|
|
10
10
|
module Jekyll
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
module WebmentionIO
|
12
|
+
class QueueWebmentions < Generator
|
13
|
+
safe true
|
14
|
+
priority :low
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
def generate(site)
|
17
|
+
@site = site
|
18
|
+
@site_url = site.config["url"].to_s
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
if @site.config.dig("webmentions", "pause_lookups")
|
24
|
-
Jekyll::WebmentionIO.log "info", "Webmention lookups are currently paused."
|
25
|
-
return
|
26
|
-
end
|
20
|
+
if @site_url.include? "localhost"
|
21
|
+
WebmentionIO.log "msg", "Webmentions lookups are not run on localhost."
|
22
|
+
return
|
23
|
+
end
|
27
24
|
|
28
|
-
|
25
|
+
if @site.config.dig("webmentions", "pause_lookups")
|
26
|
+
WebmentionIO.log "info", "Webmention lookups are currently paused."
|
27
|
+
return
|
28
|
+
end
|
29
29
|
|
30
|
-
|
30
|
+
WebmentionIO.log "msg", "Beginning to gather webmentions you’ve made. This may take a while."
|
31
31
|
|
32
|
-
|
32
|
+
upgrade_outgoing_webmention_cache
|
33
33
|
|
34
|
-
|
35
|
-
end
|
34
|
+
posts = WebmentionIO.gather_documents(@site)
|
36
35
|
|
37
|
-
|
36
|
+
gather_webmentions(posts)
|
37
|
+
end
|
38
38
|
|
39
|
-
|
40
|
-
webmentions = Jekyll::WebmentionIO.read_cached_webmentions "outgoing"
|
39
|
+
private
|
41
40
|
|
42
|
-
|
41
|
+
def gather_webmentions(posts)
|
42
|
+
webmentions = WebmentionIO.read_cached_webmentions "outgoing"
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
44
|
+
posts.each do |post|
|
45
|
+
uri = File.join(@site_url, post.url)
|
46
|
+
mentions = get_mentioned_uris(post)
|
47
|
+
if webmentions.key? uri
|
48
|
+
mentions.each do |mentioned_uri, response|
|
49
|
+
unless webmentions[uri].key? mentioned_uri
|
50
|
+
webmentions[uri][mentioned_uri] = response
|
51
|
+
end
|
51
52
|
end
|
53
|
+
else
|
54
|
+
webmentions[uri] = mentions
|
52
55
|
end
|
53
|
-
else
|
54
|
-
webmentions[uri] = mentions
|
55
56
|
end
|
56
|
-
end
|
57
|
-
|
58
|
-
Jekyll::WebmentionIO.cache_webmentions "outgoing", webmentions
|
59
|
-
end
|
60
57
|
|
61
|
-
|
62
|
-
uris = {}
|
63
|
-
if post.data["in_reply_to"]
|
64
|
-
uris[post.data["in_reply_to"]] = false
|
58
|
+
WebmentionIO.cache_webmentions "outgoing", webmentions
|
65
59
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
60
|
+
|
61
|
+
def get_mentioned_uris(post)
|
62
|
+
uris = {}
|
63
|
+
if post.data["in_reply_to"]
|
64
|
+
uris[post.data["in_reply_to"]] = false
|
65
|
+
end
|
66
|
+
post.content.scan(/(?:https?:)?\/\/[^\s)#"]+/) do |match|
|
67
|
+
unless uris.key? match
|
68
|
+
uris[match] = false
|
69
|
+
end
|
69
70
|
end
|
71
|
+
return uris
|
70
72
|
end
|
71
|
-
return uris
|
72
|
-
end
|
73
73
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
74
|
+
def upgrade_outgoing_webmention_cache
|
75
|
+
old_sent_file = WebmentionIO.cache_file("sent.yml")
|
76
|
+
old_outgoing_file = WebmentionIO.cache_file("queued.yml")
|
77
|
+
unless File.exist? old_sent_file
|
78
|
+
return
|
79
|
+
end
|
80
|
+
sent_webmentions = WebmentionIO.load_yaml(old_sent_file)
|
81
|
+
outgoing_webmentions = WebmentionIO.load_yaml(old_outgoing_file)
|
82
|
+
merged = {}
|
83
|
+
outgoing_webmentions.each do |source_url, webmentions|
|
84
|
+
collection = {}
|
85
|
+
webmentions.each do |target_url|
|
86
|
+
collection[target_url] = if sent_webmentions.dig(source_url, target_url)
|
87
|
+
""
|
88
|
+
else
|
89
|
+
false
|
90
|
+
end
|
91
|
+
end
|
92
|
+
merged[source_url] = collection
|
91
93
|
end
|
92
|
-
|
94
|
+
WebmentionIO.cache_webmentions "outgoing", merged
|
95
|
+
File.delete old_sent_file, old_outgoing_file
|
96
|
+
WebmentionIO.log "msg", "Upgraded your sent webmentions cache."
|
93
97
|
end
|
94
|
-
Jekyll::WebmentionIO.cache_webmentions "outgoing", merged
|
95
|
-
File.delete old_sent_file, old_outgoing_file
|
96
|
-
Jekyll::WebmentionIO.log "msg", "Upgraded your sent webmentions cache."
|
97
98
|
end
|
98
99
|
end
|
99
100
|
end
|
@@ -15,9 +15,9 @@ module Jekyll
|
|
15
15
|
class WebmentionTag < Liquid::Tag
|
16
16
|
def initialize(tag_name, text, tokens)
|
17
17
|
super
|
18
|
-
cache_file =
|
18
|
+
cache_file = WebmentionIO.get_cache_file_path "incoming"
|
19
19
|
@cached_webmentions = if File.exist? cache_file
|
20
|
-
|
20
|
+
WebmentionIO.load_yaml(cache_file)
|
21
21
|
else
|
22
22
|
{}
|
23
23
|
end
|
@@ -32,12 +32,12 @@ module Jekyll
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def template=(template)
|
35
|
-
unless
|
36
|
-
|
35
|
+
unless WebmentionIO.supported_templates.include? template
|
36
|
+
WebmentionIO.log "error", "#{template.capitalize} is not supported"
|
37
37
|
end
|
38
38
|
@template_name = template
|
39
|
-
@template =
|
40
|
-
|
39
|
+
@template = WebmentionIO.get_template_contents(template)
|
40
|
+
WebmentionIO.log "info", "#{template.capitalize} template:\n\n#{@template}\n\n"
|
41
41
|
end
|
42
42
|
|
43
43
|
def set_data(data, types)
|
@@ -45,13 +45,13 @@ module Jekyll
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def extract_type(type, webmentions)
|
48
|
-
|
48
|
+
WebmentionIO.log "info", "Looking for #{type}"
|
49
49
|
keep = {}
|
50
|
-
if !
|
51
|
-
|
50
|
+
if !WebmentionIO.types.include? type
|
51
|
+
WebmentionIO.log "warn", "#{type} are not extractable"
|
52
52
|
else
|
53
53
|
type = type.to_singular
|
54
|
-
|
54
|
+
WebmentionIO.log "info", "Searching #{webmentions.length} webmentions for type==#{type}"
|
55
55
|
if webmentions.is_a? Hash
|
56
56
|
webmentions = webmentions.values
|
57
57
|
end
|
@@ -73,19 +73,19 @@ module Jekyll
|
|
73
73
|
|
74
74
|
if @cached_webmentions.key? uri
|
75
75
|
all_webmentions = @cached_webmentions[uri].clone
|
76
|
-
|
76
|
+
WebmentionIO.log "info", "#{all_webmentions.length} total webmentions for #{uri}"
|
77
77
|
|
78
78
|
if args.length.positive?
|
79
|
-
|
79
|
+
WebmentionIO.log "info", "Requesting only #{args.inspect}"
|
80
80
|
webmentions = {}
|
81
81
|
args.each do |type|
|
82
82
|
types.push type
|
83
83
|
extracted = extract_type(type, all_webmentions)
|
84
|
-
|
84
|
+
WebmentionIO.log "info", "Merging in #{extracted.length} #{type}"
|
85
85
|
webmentions = webmentions.merge(extracted)
|
86
86
|
end
|
87
87
|
else
|
88
|
-
|
88
|
+
WebmentionIO.log "info", "Grabbing all webmentions"
|
89
89
|
webmentions = all_webmentions
|
90
90
|
end
|
91
91
|
|
@@ -104,20 +104,20 @@ module Jekyll
|
|
104
104
|
|
105
105
|
def render_into_template(context_registry)
|
106
106
|
if @template && @data
|
107
|
-
|
107
|
+
WebmentionIO.log "info", "Preparing to render webmention info into the #{@template_name} template."
|
108
108
|
template = Liquid::Template.parse(@template, :error_mode => :strict)
|
109
109
|
html = template.render!(@data, :registers => context_registry, :strict_variables => false, :strict_filters => true)
|
110
110
|
template.errors.each do |error|
|
111
|
-
|
111
|
+
WebmentionIO.log "error", error
|
112
112
|
end
|
113
113
|
# Clean up the output
|
114
114
|
HtmlBeautifier.beautify html.each_line.reject { |x| x.strip == "" }.join
|
115
115
|
else
|
116
116
|
unless @template
|
117
|
-
|
117
|
+
WebmentionIO.log "warn", "#{self.class} No template provided"
|
118
118
|
end
|
119
119
|
unless @data
|
120
|
-
|
120
|
+
WebmentionIO.log "warn", "#{self.class} No data provided"
|
121
121
|
end
|
122
122
|
""
|
123
123
|
end
|
@@ -18,11 +18,12 @@ module Jekyll
|
|
18
18
|
|
19
19
|
page = context["page"]
|
20
20
|
site = context.registers[:site]
|
21
|
+
site_url = site.config["url"].to_s
|
21
22
|
if page["redirect_from"]
|
22
23
|
if page["redirect_from"].is_a? String
|
23
|
-
redirect =
|
24
|
+
redirect = site_url + page["redirect_from"]
|
24
25
|
elsif page["redirect_from"].is_a? Array
|
25
|
-
redirect =
|
26
|
+
redirect = site_url + page["redirect_from"].join(",#{site_url}")
|
26
27
|
end
|
27
28
|
head << "<meta property=\"webmention:redirected_from\" content=\"#{redirect}\">"
|
28
29
|
end
|
data/lib/jekyll/webmention_io.rb
CHANGED
@@ -38,6 +38,7 @@ module Jekyll
|
|
38
38
|
|
39
39
|
@template_file_cache = {}
|
40
40
|
@template_content_cache = {}
|
41
|
+
@webmention_data_cache = {}
|
41
42
|
|
42
43
|
EXCEPTIONS = [
|
43
44
|
SocketError, Timeout::Error,
|
@@ -66,7 +67,7 @@ module Jekyll
|
|
66
67
|
dump_yaml(file) unless File.exist?(file)
|
67
68
|
end
|
68
69
|
|
69
|
-
@js_handler =
|
70
|
+
@js_handler = WebmentionIO::JSHandler.new(site)
|
70
71
|
end
|
71
72
|
|
72
73
|
# Setter
|
@@ -100,11 +101,7 @@ module Jekyll
|
|
100
101
|
end
|
101
102
|
|
102
103
|
def self.gather_documents(site)
|
103
|
-
documents =
|
104
|
-
site.posts.docs.clone
|
105
|
-
else
|
106
|
-
site.posts.clone
|
107
|
-
end
|
104
|
+
documents = site.posts.docs.clone
|
108
105
|
|
109
106
|
if @config.dig("pages") == true
|
110
107
|
log "info", "Including site pages."
|
@@ -139,7 +136,7 @@ module Jekyll
|
|
139
136
|
end
|
140
137
|
end
|
141
138
|
|
142
|
-
def self.read_lookup_dates
|
139
|
+
def self.read_lookup_dates
|
143
140
|
cache_file = get_cache_file_path "lookups"
|
144
141
|
load_yaml(cache_file)
|
145
142
|
end
|
@@ -180,7 +177,7 @@ module Jekyll
|
|
180
177
|
break
|
181
178
|
end
|
182
179
|
end
|
183
|
-
timeframe
|
180
|
+
timeframe ||= "older"
|
184
181
|
return timeframe
|
185
182
|
end
|
186
183
|
|
@@ -213,7 +210,7 @@ module Jekyll
|
|
213
210
|
begin
|
214
211
|
endpoint = Webmention::Client.supports_webmention?(uri)
|
215
212
|
log("info", "Could not find a webmention endpoint at #{uri}") unless endpoint
|
216
|
-
rescue => e
|
213
|
+
rescue StandardError => e
|
217
214
|
log "info", "Endpoint lookup failed for #{uri}: #{e.message}"
|
218
215
|
endpoint = false
|
219
216
|
end
|
@@ -300,22 +297,25 @@ module Jekyll
|
|
300
297
|
end
|
301
298
|
|
302
299
|
# Utility Method
|
303
|
-
#
|
300
|
+
# Caches given +data+ to memory and then proceeds to write +data+
|
301
|
+
# as YAML string into +file+ path.
|
304
302
|
#
|
305
303
|
# Returns nothing.
|
306
304
|
def self.dump_yaml(file, data = {})
|
305
|
+
@webmention_data_cache[file] = data
|
307
306
|
File.open(file, "wb") { |f| f.puts YAML.dump(data) }
|
308
307
|
end
|
309
308
|
|
310
309
|
# Utility Method
|
311
|
-
#
|
310
|
+
# Attempts to first load data cached in memory and then proceeds to
|
311
|
+
# safely parse given YAML +file+ path and return data.
|
312
312
|
#
|
313
313
|
# Returns empty hash if parsing fails to return data
|
314
314
|
def self.load_yaml(file)
|
315
|
-
SafeYAML.load_file(file) || {}
|
315
|
+
@webmention_data_cache[file] || SafeYAML.load_file(file) || {}
|
316
316
|
end
|
317
317
|
|
318
|
-
|
318
|
+
# Private Methods
|
319
319
|
|
320
320
|
def self.get_http_response(uri)
|
321
321
|
uri = URI.parse(URI.encode(uri))
|
@@ -341,8 +341,10 @@ module Jekyll
|
|
341
341
|
|
342
342
|
# Cache bad URLs for a bit
|
343
343
|
def self.uri_is_not_ok(uri)
|
344
|
+
uri = URI.parse(URI.encode(uri))
|
344
345
|
# Never cache webmention.io in here
|
345
346
|
return if uri.host == "webmention.io"
|
347
|
+
|
346
348
|
cache_file = @cache_files["bad_uris"]
|
347
349
|
bad_uris = load_yaml(cache_file)
|
348
350
|
bad_uris[uri.host] = Time.now.to_s
|
@@ -361,6 +363,8 @@ module Jekyll
|
|
361
363
|
end
|
362
364
|
return true
|
363
365
|
end
|
366
|
+
|
367
|
+
private_class_method :get_http_response, :uri_is_not_ok, :uri_ok?
|
364
368
|
end
|
365
369
|
end
|
366
370
|
|
@@ -28,7 +28,7 @@ module Jekyll
|
|
28
28
|
@deploy, @uglify, @source, @destination = js_config.values_at("deploy", "uglify", "source", "destination")
|
29
29
|
@resource_name = "JekyllWebmentionIO.js"
|
30
30
|
@resource_url = File.join(
|
31
|
-
"", site.config["baseurl"], @destination, @resource_name
|
31
|
+
"", site.config["baseurl"].to_s, @destination, @resource_name
|
32
32
|
)
|
33
33
|
end
|
34
34
|
|
@@ -50,15 +50,15 @@ module Jekyll
|
|
50
50
|
|
51
51
|
def render
|
52
52
|
if disabled?
|
53
|
-
|
53
|
+
WebmentionIO.log "info",
|
54
54
|
"JavaScript output is disabled, so the {% webmentions_js %} tag is being skipped"
|
55
55
|
return ""
|
56
56
|
end
|
57
57
|
|
58
58
|
js_file = deploy? ? "<script src=\"#@resource_url\" async></script>" : ""
|
59
59
|
|
60
|
-
|
61
|
-
"#{js_file}\n#{
|
60
|
+
WebmentionIO.log "info", "Gathering templates for JavaScript."
|
61
|
+
"#{js_file}\n#{WebmentionIO.html_templates}"
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -51,13 +51,7 @@ module Jekyll
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def markdownify(string)
|
54
|
-
|
55
|
-
@converter = if defined? @site.find_converter_instance
|
56
|
-
@site.find_converter_instance(::Jekyll::Converters::Markdown)
|
57
|
-
else
|
58
|
-
@site.getConverterImpl(::Jekyll::Converters::Markdown)
|
59
|
-
end
|
60
|
-
end
|
54
|
+
@converter ||= @site.find_converter_instance(Jekyll::Converters::Markdown)
|
61
55
|
|
62
56
|
if string
|
63
57
|
string = @converter.convert(string.to_s)
|
@@ -134,7 +128,7 @@ module Jekyll
|
|
134
128
|
|
135
129
|
if @type == "post"
|
136
130
|
|
137
|
-
html_source =
|
131
|
+
html_source = WebmentionIO.get_uri_source(@uri)
|
138
132
|
unless html_source
|
139
133
|
return title
|
140
134
|
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: 3.
|
4
|
+
version: 3.2.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-
|
11
|
+
date: 2018-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.2.0
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '4.0'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 3.2.0
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '4.0'
|
@@ -44,20 +44,6 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '2.0'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: http
|
49
|
-
requirement: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
51
|
-
- - "~>"
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '2.0'
|
54
|
-
type: :runtime
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
requirements:
|
58
|
-
- - "~>"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '2.0'
|
61
47
|
- !ruby/object:Gem::Dependency
|
62
48
|
name: openssl
|
63
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,6 +128,20 @@ dependencies:
|
|
142
128
|
- - "~>"
|
143
129
|
- !ruby/object:Gem::Version
|
144
130
|
version: '1.14'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: cucumber
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - "~>"
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '3.1'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - "~>"
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '3.1'
|
145
145
|
- !ruby/object:Gem::Dependency
|
146
146
|
name: rake
|
147
147
|
requirement: !ruby/object:Gem::Requirement
|
@@ -270,7 +270,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
270
270
|
requirements:
|
271
271
|
- - ">="
|
272
272
|
- !ruby/object:Gem::Version
|
273
|
-
version:
|
273
|
+
version: 2.3.0
|
274
274
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
275
275
|
requirements:
|
276
276
|
- - ">="
|