threejs.rb 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. module Docs
  2. class Threejs < FileScraper
  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.class_attribute :release
  37. version '171' do
  38. self.release = '171'
  39. self.base_url = "https://threejs.org/docs"
  40. end
  41. def get_latest_version(opts)
  42. get_latest_github_release('mrdoob', 'three.js', opts)
  43. end
  44. def initial_paths
  45. paths = []
  46. json_path = File.expand_path("docs/threejs~#{self.release}/list.json")
  47. json_content = File.read(json_path)
  48. json_data = JSON.parse(json_content)
  49. # Process both API and manual sections
  50. process_documentation(json_data['en'], paths)
  51. paths
  52. end
  53. private
  54. def process_documentation(data, paths, prefix = '')
  55. data.each do |category, items|
  56. if items.is_a?(Hash)
  57. if items.values.first.is_a?(String)
  58. # This is a leaf node with actual pages
  59. items.each do |name, path|
  60. paths << "#{path}.html"
  61. end
  62. else
  63. # This is a category with subcategories
  64. items.each do |subcategory, subitems|
  65. process_documentation(items, paths, "#{prefix}#{category}/")
  66. end
  67. end
  68. end
  69. end
  70. end
  71. end
  72. end