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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aec29b9c319f23f77ea68e3c4a6853a8d01f17e1
4
- data.tar.gz: b79fbe01941187bb9ee66d9cc809e3531d17147f
3
+ metadata.gz: 9690fa4573a7c0d2a45c5e86f9bd66ef28de2f9d
4
+ data.tar.gz: 0a9fab2e11ea1fe25f708cc6eb3f2ee7f4d3434f
5
5
  SHA512:
6
- metadata.gz: a0092774e964689fb79b54232bcf51418e1981a1beda3be024f52c4f939424a17d67e60224061d8f943406aaa77f8d329ab2eacde4acf2e462f3436a3922cf05
7
- data.tar.gz: 96ddc4cdb837916792d57058d62214a0ee1f9212e462207d29fadfb545e0456c184fdd6f8d969553697357a5331eb1c1134bef1971cbca78a31844b5b5bedd37
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
- # Gather the URLs
46
- targets = get_webmention_target_urls(site, post)
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module WebmentionIO
3
- VERSION = "2.6.4"
3
+ VERSION = "2.7.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-webmention_io
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.4
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Gustafson