forked from freeCodeCamp/devdocs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdn.rb
More file actions
35 lines (27 loc) · 1.01 KB
/
mdn.rb
File metadata and controls
35 lines (27 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module Docs
class Mdn < UrlScraper
self.abstract = true
self.type = 'mdn'
params[:raw] = 1
params[:macros] = 1
html_filters.push 'mdn/clean_html'
text_filters.insert_before 'attribution', 'mdn/contribute_link'
options[:rate_limit] = 200
options[:trailing_slash] = false
options[:skip_link] = ->(link) {
link['title'].try(:include?, 'not yet been written'.freeze) && !link['href'].try(:include?, 'transform-function'.freeze)
}
options[:attribution] = <<-HTML
© 2005–2018 Mozilla Developer Network and individual contributors.<br>
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
HTML
def get_latest_version(opts)
json = fetch_json("https://developer.mozilla.org/en-US/docs/feeds/json/tag/#{options[:mdn_tag]}", opts)
DateTime.parse(json[0]['pubdate']).to_time.to_i
end
private
def process_response?(response)
super && response.effective_url.query == 'raw=1¯os=1'
end
end
end