threejs.rb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. module Docs
  2. class Threejs < UrlScraper
  3. self.name = 'Three.js'
  4. self.type = 'simple'
  5. self.slug = 'threejs'
  6. self.links = {
  7. home: 'https://threejs.org/',
  8. code: 'https://github.com/mrdoob/three.js'
  9. }
  10. html_filters.push 'threejs/entries', 'threejs/clean_html'
  11. # The content is directly in the body
  12. options[:container] = 'body'
  13. options[:skip] = %w(
  14. prettify.js
  15. lesson.js
  16. lang.css
  17. lesson.css
  18. editor.html
  19. list.js
  20. page.js
  21. )
  22. options[:only_patterns] = [
  23. /\Aapi\/en\/.+\.html/, # API documentation
  24. /\Amanual\/en\/.+\.html/ # Manual pages
  25. ]
  26. options[:skip_patterns] = [
  27. /examples/,
  28. /\A_/,
  29. /\Aresources\//,
  30. /\Ascenes\//
  31. ]
  32. options[:attribution] = <<-HTML
  33. &copy; 2010&ndash;#{Time.current.year} Three.js Authors<br>
  34. Licensed under the MIT License.
  35. HTML
  36. self.release = '173'
  37. self.base_url = "https://threejs.org/docs"
  38. def get_latest_version(opts)
  39. get_latest_github_release('mrdoob', 'three.js', opts)[1..]
  40. end
  41. def initial_paths
  42. paths = []
  43. url = 'https://threejs.org/docs/list.json'
  44. response = Request.run(url)
  45. json_data = JSON.parse(response.body)
  46. # Process both API and manual sections
  47. process_documentation(json_data['en'], paths)
  48. paths
  49. end
  50. private
  51. def process_documentation(data, paths, prefix = '')
  52. data.each do |category, items|
  53. if items.is_a?(Hash)
  54. if items.values.first.is_a?(String)
  55. # This is a leaf node with actual pages
  56. items.each do |name, path|
  57. paths << "#{path}.html"
  58. end
  59. else
  60. # This is a category with subcategories
  61. items.each do |subcategory, subitems|
  62. process_documentation(items, paths, "#{prefix}#{category}/")
  63. end
  64. end
  65. end
  66. end
  67. end
  68. end
  69. end