react.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. module Docs
  2. class React < UrlScraper
  3. self.name = 'React'
  4. self.type = 'react'
  5. self.links = {
  6. home: 'https://react.dev/',
  7. code: 'https://github.com/facebook/react'
  8. }
  9. options[:attribution] = <<-HTML
  10. &copy; 2013&ndash;present Facebook Inc.<br>
  11. Licensed under the Creative Commons Attribution 4.0 International Public License.
  12. HTML
  13. version do
  14. self.release = '19'
  15. self.base_url = 'https://react.dev'
  16. self.initial_paths = %w(/reference/react /learn)
  17. html_filters.push 'react/entries_react_dev', 'react/clean_html_react_dev'
  18. options[:only_patterns] = [/\A\/learn/, /\A\/reference/]
  19. end
  20. version '18' do
  21. self.release = '18.3.1'
  22. self.base_url = 'https://18.react.dev'
  23. self.initial_paths = %w(/reference/react /learn)
  24. html_filters.push 'react/entries_react_dev', 'react/clean_html_react_dev'
  25. options[:only_patterns] = [/\A\/learn/, /\A\/reference/]
  26. end
  27. version '17' do
  28. self.release = '17.0.2'
  29. self.base_url = 'https://17.reactjs.org/docs/'
  30. self.root_path = 'hello-world.html'
  31. html_filters.push 'react/entries', 'react/clean_html'
  32. options[:skip] = %w(
  33. codebase-overview.html
  34. design-principles.html
  35. how-to-contribute.html
  36. implementation-notes.html
  37. )
  38. options[:replace_paths] = {
  39. 'more-about-refs.html' => 'refs-and-the-dom.html',
  40. 'interactivity-and-dynamic-uis.html' => 'state-and-lifecycle.html',
  41. 'working-with-the-browser.html' => 'refs-and-the-dom.html',
  42. 'top-level-api.html' => 'react-api.html',
  43. }
  44. end
  45. def get_latest_version(opts)
  46. doc = fetch_doc('https://react.dev/', opts)
  47. doc.at_css('a[href="/versions"]').content.strip[1..-1]
  48. end
  49. end
  50. end