Browse Source

Add vertx docs

dorimon 6 months ago
parent
commit
ade1961b72

+ 40 - 0
lib/docs/filters/vertx/clean_html.rb

@@ -0,0 +1,40 @@
+module Docs
+  class Vertx
+    class CleanHtmlFilter < Filter
+      def call
+        css('hr', 'header', 'nav', '.navbar', '.topbar').remove
+        xpath('//*[@id="docs-layout"]/div/div[3]').remove
+        xpath('//*[@id="docs-layout"]/div/div[1]').remove
+        xpath('//main/div[last()]').remove
+        xpath('//main/div[1]').remove
+        xpath('//footer').remove
+        css('#changelog').remove if root_page?
+
+        # Set id attributes on <h3> instead of an empty <a>
+        css('h3').each do |node|
+          anchor = node.at_css('a')
+          node['id'] = anchor['id'] if anchor && anchor['id']
+        end
+
+        # Make proper table headers
+        css('td.header').each do |node|
+          node.name = 'th'
+        end
+
+        # Remove code highlighting
+        css('pre').each do |node|
+          node.content = node.content
+        end
+
+        # ❗ Skip <img> tags with data: URIs
+        css('img').each do |img|
+          src = img['src']
+          img.remove if src&.start_with?('data:')
+        end
+
+        doc
+      end
+    end
+  end
+end
+

+ 43 - 0
lib/docs/filters/vertx/entries.rb

@@ -0,0 +1,43 @@
+module Docs
+  class Vertx
+    class EntriesFilter < Docs::EntriesFilter
+      # Determines the default name of the page entry
+      def get_name
+        node = at_css('h1')
+        return nil unless node
+
+        result = node.content.strip
+        result = "v5.0.0 - #{result}" if slug.include?('5.0.0')
+        result << ' event' if type == 'Events'
+        result << '()' if node['class'].to_s.include?('function')
+        result
+      end
+
+      # Determines the type of the default entry (used for sidebar grouping)
+      def get_type
+        return nil if root_page?
+
+        node = at_xpath('/html/body/div/div/div[2]/main/div[1]/div[1]')
+        node ? node.text.strip : 'Miscellaneous'
+      end
+
+      # Returns additional entries from subheadings (usually <h2>)
+      def additional_entries
+        # return [] if root_page?
+        #
+        # css('h2').map do |node|
+        #   name = node.content.strip
+        #   id = node['id']
+        #   [name, id, type]
+        # end
+        []
+      end
+
+      # Determines whether to include the default entry for the page
+      def include_default_entry?
+        !at_css('.obsolete')
+      end
+    end
+  end
+end
+

+ 25 - 0
lib/docs/scrapers/vertx.rb

@@ -0,0 +1,25 @@
+
+module Docs
+  class Vertx < UrlScraper
+    self.type = 'vertx'
+    self.links = {
+      home: 'http://vertx.io',
+      code: 'https://github.com/eclipse-vertx/vert.x'
+    }
+
+    html_filters.push 'vertx/entries', 'vertx/clean_html'
+
+    self.base_url = 'https://vertx.io/'
+    self.root_path = 'docs'
+    options[:attribution] = <<-HTML
+      by Dor Sahar :)
+    HTML
+
+    options[:skip_patterns] = [
+      /api/,
+      /apidocs/,
+      /blog/,
+    ]
+
+  end
+end

BIN
public/icons/docs/vertx/16.png


BIN
public/icons/docs/vertx/16@2x.png