threejs.rb 2.0 KB

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