react.rb 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.release = '19.2'
  16. self.base_url = 'https://react.dev'
  17. self.initial_paths = %w(/reference/react /learn)
  18. html_filters.push 'react/entries_react_dev', 'react/clean_html_react_dev'
  19. options[:only_patterns] = [/\A\/learn/, /\A\/reference/]
  20. end
  21. version '18' do
  22. self.release = '18.3.1'
  23. self.base_url = 'https://18.react.dev'
  24. self.initial_paths = %w(/reference/react /learn)
  25. html_filters.push 'react/entries_react_dev', 'react/clean_html_react_dev'
  26. options[:only_patterns] = [/\A\/learn/, /\A\/reference/]
  27. end
  28. version '17' do
  29. self.release = '17.0.2'
  30. self.base_url = 'https://17.reactjs.org/docs/'
  31. self.root_path = 'hello-world.html'
  32. html_filters.push 'react/entries', 'react/clean_html'
  33. options[:skip] = %w(
  34. codebase-overview.html
  35. design-principles.html
  36. how-to-contribute.html
  37. implementation-notes.html
  38. )
  39. options[:replace_paths] = {
  40. 'more-about-refs.html' => 'refs-and-the-dom.html',
  41. 'interactivity-and-dynamic-uis.html' => 'state-and-lifecycle.html',
  42. 'working-with-the-browser.html' => 'refs-and-the-dom.html',
  43. 'top-level-api.html' => 'react-api.html',
  44. }
  45. end
  46. def get_latest_version(opts)
  47. doc = fetch_doc('https://react.dev/', opts)
  48. doc.at_css('a[href="/versions"]').content.strip[1..-1]
  49. end
  50. end
  51. end