mdn.rb 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. module Docs
  2. class Mdn < UrlScraper
  3. self.abstract = true
  4. self.type = 'mdn'
  5. params[:raw] = 1
  6. params[:macros] = 1
  7. html_filters.push 'mdn/clean_html'
  8. text_filters.insert_before 'attribution', 'mdn/contribute_link'
  9. options[:rate_limit] = 200
  10. options[:trailing_slash] = false
  11. options[:skip_link] = ->(link) {
  12. link['title'].try(:include?, 'not yet been written'.freeze) && !link['href'].try(:include?, 'transform-function'.freeze)
  13. }
  14. options[:attribution] = <<-HTML
  15. &copy; 2005&ndash;2020 Mozilla and individual contributors.<br>
  16. Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
  17. HTML
  18. def get_latest_version(opts)
  19. json = fetch_json("https://developer.mozilla.org/en-US/docs/feeds/json/tag/#{options[:mdn_tag]}", opts)
  20. dates = json.map { |i| i['pubdate'] }
  21. DateTime.parse(dates.max).to_time.to_i
  22. end
  23. private
  24. def process_response?(response)
  25. response.effective_url.host = 'developer.mozilla.org' if response.effective_url.host == 'wiki.developer.mozilla.org'
  26. super && response.effective_url.query == 'raw=1&macros=1'
  27. end
  28. end
  29. end