jekyll-webmention_io 2.6.4 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll/generators/gather_webmentions.rb +15 -9
- data/lib/jekyll/webmention_io.rb +58 -1
- data/lib/jekyll/webmention_io/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9690fa4573a7c0d2a45c5e86f9bd66ef28de2f9d
|
4
|
+
data.tar.gz: 0a9fab2e11ea1fe25f708cc6eb3f2ee7f4d3434f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d5b8ddd87ac116a4575a1f6e03dd897d31d9f24197b039c39a14d05462e1e2c4ffa293fbcc637f1c0408585e7b716633f8e36c2ab8e1307553cf896c11b1037
|
7
|
+
data.tar.gz: 8da3ba2bc5ca88e6c500a5f7da8161c9b447b3f9f00ce1f7be3d54b47694aaf4a5d32111b8aebdc1aba7609d3dfaf0cfc22adf78ff75ed93f599dc5264c0bf93
|
@@ -42,18 +42,24 @@ module Jekyll
|
|
42
42
|
end
|
43
43
|
|
44
44
|
posts.each do |post|
|
45
|
-
#
|
46
|
-
|
45
|
+
# get the last webmention
|
46
|
+
last_webmention = @cached_webmentions.dig( post.url, @cached_webmentions.dig( post.url )&.keys&.last )
|
47
|
+
|
48
|
+
# should we throttle?
|
49
|
+
if last_webmention && Jekyll::WebmentionIO::post_should_be_throttled?( post, post.date, last_webmention.dig( 'raw', 'verified_date' ) )
|
50
|
+
# Jekyll::WebmentionIO::log 'info', "Throttling #{post.url}"
|
51
|
+
next
|
52
|
+
end
|
53
|
+
|
54
|
+
# past_webmentions.dig( past_webmentions&.keys&.last )
|
55
|
+
# past_webmentions[past_webmentions.keys.last]['raw']['verified_date']
|
47
56
|
|
48
57
|
# 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
|
-
if past_webmentions.dig( past_webmentions&.keys&.last )
|
53
|
-
since_id = past_webmentions[past_webmentions.keys.last]['raw']['id']
|
54
|
-
end
|
55
|
-
end
|
58
|
+
since_id = last_webmention ? last_webmention.dig( 'raw', 'id' ) : false
|
56
59
|
|
60
|
+
# Gather the URLs
|
61
|
+
targets = get_webmention_target_urls(site, post)
|
62
|
+
|
57
63
|
# execute the API
|
58
64
|
api_params = targets.collect { |v| "target[]=#{v}" }.join('&')
|
59
65
|
api_params << "&since_id=#{since_id}" if since_id
|
data/lib/jekyll/webmention_io.rb
CHANGED
@@ -101,7 +101,64 @@ module Jekyll
|
|
101
101
|
""
|
102
102
|
end
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
|
+
# allowed throttles: last_week, last_month, last_year, older
|
106
|
+
# allowed values: daily, weekly, monthly, yearly, every X days|weeks|months|years
|
107
|
+
def self.post_should_be_throttled?( post, item_date, last_webmention_date )
|
108
|
+
throttles = @config.dig( 'throttle_lookups' )
|
109
|
+
if throttles && item_date && last_webmention_date
|
110
|
+
age = get_timeframe_from_date( item_date )
|
111
|
+
throttle = throttles.dig( age )
|
112
|
+
if throttle && get_date_from_string( throttle ) >= Date.parse(last_webmention_date)
|
113
|
+
log 'info', "Throttling #{post.data['title']} (Only checking it #{throttle})"
|
114
|
+
return true
|
115
|
+
end
|
116
|
+
end
|
117
|
+
return false
|
118
|
+
end
|
119
|
+
def self.get_timeframe_from_date( time )
|
120
|
+
date = time.to_date
|
121
|
+
timeframes = {
|
122
|
+
'last_week' => 'weekly',
|
123
|
+
'last_month' => 'monthly',
|
124
|
+
'last_year' => 'yearly'
|
125
|
+
}
|
126
|
+
timeframe = nil
|
127
|
+
timeframes.each do |key, value|
|
128
|
+
if date.to_date > get_date_from_string( value )
|
129
|
+
timeframe = key
|
130
|
+
break
|
131
|
+
end
|
132
|
+
end
|
133
|
+
if ! timeframe
|
134
|
+
timeframe = 'older'
|
135
|
+
end
|
136
|
+
return timeframe
|
137
|
+
end
|
138
|
+
# supported: daily, weekly, monthly, yearly, every X days|weeks|months|years
|
139
|
+
def self.get_date_from_string( text )
|
140
|
+
today = Date.today
|
141
|
+
pattern = /every\s(?:(\d+)\s)?(day|week|month|year)s?/
|
142
|
+
matches = text.match( pattern )
|
143
|
+
if ! matches
|
144
|
+
if text == 'daily'
|
145
|
+
text = 'every 1 day'
|
146
|
+
else
|
147
|
+
text = 'every 1 ' + text.sub( 'ly', '' )
|
148
|
+
end
|
149
|
+
matches = text.match( pattern )
|
150
|
+
end
|
151
|
+
n = matches[1] ? matches[1].to_i : 1
|
152
|
+
unit = matches[2]
|
153
|
+
# weeks aren't natively supported in Ruby
|
154
|
+
if unit == 'week'
|
155
|
+
n = n * 7
|
156
|
+
unit = 'day'
|
157
|
+
end
|
158
|
+
# dynamic method call
|
159
|
+
return today.send "prev_#{unit}", n
|
160
|
+
end
|
161
|
+
|
105
162
|
def self.get_webmention_endpoint( uri )
|
106
163
|
# log 'info', "Looking for webmention endpoint at #{uri}"
|
107
164
|
begin
|