Jed Fox 7 years ago
parent
commit
b97cfa6693

+ 1 - 1
lib/docs/filters/github/clean_html.rb

@@ -9,7 +9,7 @@ module Docs
 
         css('.highlight > pre').each do |node|
           node['data-language'] = node.parent['class'][/highlight-source-(\w+)/, 1]
-          node.content = node.content.strip_heredoc.gsub('    ', '  ')
+          node.content = node.content.strip_heredoc
           node.parent.replace(node)
         end
 

+ 42 - 0
lib/docs/filters/koa/clean_html.rb

@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+module Docs
+  class Koa
+    class CleanHtmlFilter < Filter
+      def call
+        fix_homepage if slug.start_with? 'api/index'
+
+        css('[data-language=shell]').each do |node|
+          node['data-language'] = 'bash'
+        end
+
+        doc
+      end
+
+      def fix_homepage
+        # Shrink the headers
+        for n in (1..5).to_a.reverse
+          css("h#{n}").each do |header|
+            header.name = "h#{n+1}"
+          end
+        end
+
+        # Add an introduction
+        doc.children.before <<-HTML.strip_heredoc
+          <h1>Koa</h1>
+          <!-- https://github.com/koajs/koa/blob/841844e/Readme.md -->
+          <h2 id="introduction">Introduction</h2>
+          <p>
+            Expressive HTTP middleware framework for node.js to make web applications and APIs more enjoyable to write. Koa's middleware stack flows in a stack-like manner, allowing you to perform actions downstream then filter and manipulate the response upstream.
+          </p>
+          <p>
+            Only methods that are common to nearly all HTTP servers are integrated directly into Koa's small ~570 SLOC codebase. This includes things like content negotiation, normalization of node inconsistencies, redirection, and a few others.
+          </p>
+          <p>
+            Koa is not bundled with any middleware.
+          </p>
+        HTML
+      end
+    end
+  end
+end

+ 36 - 0
lib/docs/filters/koa/entries.rb

@@ -0,0 +1,36 @@
+module Docs
+  class Koa
+    class EntriesFilter < Docs::EntriesFilter
+      @root_type = 'Koa'
+      def get_name
+        at_css('h1').content
+      end
+
+      def additional_entries
+        return [] unless slug.match?(/^api/)
+        type = get_name
+        css('h2, h3').to_a
+          .delete_if do |node|
+            node.content == 'API' ||
+              (slug.include?('index') && !node.content.include?('.'))
+          end
+          .map do |node|
+            name = node.content.sub(/\(.*\)$/, '')
+            type = 'API' if type == @root_type && name.include?('.')
+            [name, node['id'], type]
+          end
+      end
+
+      def get_type
+        case slug
+        when /^api\/index/
+          'API'
+        when /^api/
+          get_name
+        else
+          'Guides'
+        end
+      end
+    end
+  end
+end

+ 38 - 0
lib/docs/scrapers/koa.rb

@@ -0,0 +1,38 @@
+# frozen_string_literal: true
+
+module Docs
+  class Koa < Github
+    self.base_url = 'https://github.com/koajs/koa/blob/master/docs/'
+    self.release = '2.4.1'
+
+    self.root_path = 'api/index.md'
+    self.initial_paths = %w[
+      error-handling
+      faq
+      guide
+      koa-vs-express
+      migration
+      troubleshooting
+      api/index
+      api/context
+      api/request
+      api/response
+    ].map { |name| name + '.md' }
+
+    self.links = {
+      home: 'https://koajs.com/',
+      code: 'https://github.com/koajs/koa'
+    }
+
+    html_filters.push 'koa/clean_html', 'koa/entries'
+
+    options[:skip] = %w[middleware.gif]
+    options[:trailing_slash] = false
+    options[:container] = '.markdown-body'
+
+    options[:attribution] = <<-HTML
+      &copy; 2017 Koa contributors<br>
+      Licensed under the MIT License.
+    HTML
+  end
+end

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


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


+ 1 - 0
public/icons/docs/koa/SOURCE

@@ -0,0 +1 @@
+https://github.com/github/explore/blob/db7f2f28385d413ba9e03a635009b3434c9710fc/topics/koa/koa.png