Browse Source

Add Bun documentation (1.3.0)

Simon Legner 1 tháng trước cách đây
mục cha
commit
55214c5288

+ 43 - 0
lib/docs/filters/bun/clean_html.rb

@@ -0,0 +1,43 @@
+module Docs
+  class Bun
+    class CleanHtmlFilter < Filter
+      def call
+        @doc = at_css('section > .w-full')
+
+        header = at_css('header:has(h1)')
+        if header
+          header.content = header.at_css('h1').content
+          header.name = 'h1'
+        end
+
+        css('.CodeBlockTab').remove
+        css('.CopyIcon').remove
+        css('svg').remove
+        css('a:contains("Edit on GitHub")').remove
+        css('a:contains("Previous")').remove
+        css('a:contains("Next")').remove
+
+        css('pre').each do |node|
+          node.content = node.content
+          node['data-language'] = 'typescript'
+          node.remove_attribute('style')
+        end
+
+        css('.font-mono').each do |node|
+          node.name = 'code'
+        end
+
+        css('.font-mono.text-blue-600').each do |node|
+          node[:class] = 'token keyword'
+        end
+
+        css('*[class]').each do |node|
+          next if node.name == 'code'
+          node.remove_attribute('class')
+        end
+
+        doc
+      end
+    end
+  end
+end

+ 30 - 0
lib/docs/filters/bun/entries.rb

@@ -0,0 +1,30 @@
+module Docs
+  class Bun
+    class EntriesFilter < Docs::EntriesFilter
+      def get_name
+        name = at_css('h1') ? at_css('h1').content : at_css('h2').content
+        name
+      end
+
+      def get_type
+        slug.split('/').first
+      end
+
+      def additional_entries
+        if slug.start_with?('cli')
+          css('h2[id]').each_with_object [] do |node, entries|
+            name = get_name + " " + node.content.strip
+            entries << [name, node['id']]
+          end
+        elsif slug.start_with?('api')
+          css('h2[id]').each_with_object [] do |node, entries|
+            name = get_name + ": " + node.content.strip
+            entries << [name, node['id']]
+          end
+        else
+          []
+        end
+      end
+    end
+  end
+end

+ 1 - 0
lib/docs/filters/core/images.rb

@@ -31,6 +31,7 @@ module Docs
 
         self.class.cache[src] = false
 
+        next if src.start_with? 'data:image/'
         url = Docs::URL.parse(src)
         url.scheme = 'https' if url.scheme.nil?
         next unless url.scheme == 'http' || url.scheme == 'https'

+ 32 - 0
lib/docs/scrapers/bun.rb

@@ -0,0 +1,32 @@
+module Docs
+  class Bun < UrlScraper
+    self.name = 'Bun'
+    self.type = 'simple'
+    self.slug = 'bun'
+    self.links = {
+      home: 'https://leafletjs.com/',
+      code: 'https://github.com/oven-sh/bun'
+    }
+    self.release = '1.3.0'
+    self.base_url = "https://bun.com/docs/"
+    self.root_path = 'installation'
+
+    html_filters.push 'bun/clean_html', 'bun/entries'
+
+    # https://bun.com/docs/project/licensing
+    options[:attribution] = <<-HTML
+      &copy; bun.com, oven-sh, Jarred Sumner<br>
+      Licensed under the MIT License.
+    HTML
+
+    options[:skip_patterns] = [/^project/]
+    options[:fix_urls] = ->(url) do
+      url.sub! %r{.md$}, ''
+      url
+    end
+
+    def get_latest_version(opts)
+      tags = get_github_tags('oven-sh', 'bun', opts)
+    end
+  end
+end

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


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


+ 2 - 0
public/icons/docs/bun/SOURCE

@@ -0,0 +1,2 @@
+https://bun.com/icons/favicon-16x16.png
+https://bun.com/icons/favicon-32x32.png