1
0

rust.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. module Docs
  2. class Rust < UrlScraper
  3. self.type = 'rust'
  4. self.release = '1.24.0'
  5. self.base_url = 'https://doc.rust-lang.org/'
  6. self.root_path = 'book/first-edition/index.html'
  7. self.initial_paths = %w(
  8. reference/introduction.html
  9. collections/index.html
  10. std/index.html
  11. error-index.html)
  12. self.links = {
  13. home: 'https://www.rust-lang.org/',
  14. code: 'https://github.com/rust-lang/rust'
  15. }
  16. html_filters.push 'rust/entries', 'rust/clean_html'
  17. options[:only_patterns] = [
  18. /\Abook\/first-edition\//,
  19. /\Areference\//,
  20. /\Acollections\//,
  21. /\Astd\// ]
  22. options[:skip] = %w(book/first-edition/README.html)
  23. options[:skip_patterns] = [/(?<!\.html)\z/]
  24. options[:fix_urls] = ->(url) do
  25. url.sub! %r{(#{Rust.base_url}.+/)\z}, '\1index.html'
  26. url.sub! '/unicode/u_str', '/unicode/str/'
  27. url
  28. end
  29. options[:attribution] = <<-HTML
  30. &copy; 2010 The Rust Project Developers<br>
  31. Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
  32. HTML
  33. private
  34. REDIRECT_RGX = /http-equiv="refresh"/i
  35. NOT_FOUND_RGX = /<title>Not Found<\/title>/
  36. def process_response?(response)
  37. !(response.body =~ REDIRECT_RGX || response.body =~ NOT_FOUND_RGX || response.body.blank?)
  38. end
  39. end
  40. end