diff --git a/lib/docs/filters/github/clean_html.rb b/lib/docs/filters/github/clean_html.rb index 80c8ea99..4d6da240 100644 --- a/lib/docs/filters/github/clean_html.rb +++ b/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 diff --git a/lib/docs/filters/koa/clean_html.rb b/lib/docs/filters/koa/clean_html.rb new file mode 100644 index 00000000..7fbbdcfe --- /dev/null +++ b/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 +

Koa

+ +

Introduction

+

+ 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. +

+

+ 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. +

+

+ Koa is not bundled with any middleware. +

+ HTML + end + end + end +end diff --git a/lib/docs/filters/koa/entries.rb b/lib/docs/filters/koa/entries.rb new file mode 100644 index 00000000..83a03a56 --- /dev/null +++ b/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 diff --git a/lib/docs/scrapers/koa.rb b/lib/docs/scrapers/koa.rb new file mode 100644 index 00000000..92d48c36 --- /dev/null +++ b/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 + © 2017 Koa contributors
+ Licensed under the MIT License. + HTML + end +end diff --git a/public/icons/docs/koa/16.png b/public/icons/docs/koa/16.png new file mode 100644 index 00000000..a4280f69 Binary files /dev/null and b/public/icons/docs/koa/16.png differ diff --git a/public/icons/docs/koa/16@2x.png b/public/icons/docs/koa/16@2x.png new file mode 100644 index 00000000..66345abb Binary files /dev/null and b/public/icons/docs/koa/16@2x.png differ diff --git a/public/icons/docs/koa/SOURCE b/public/icons/docs/koa/SOURCE new file mode 100644 index 00000000..a018af7f --- /dev/null +++ b/public/icons/docs/koa/SOURCE @@ -0,0 +1 @@ +https://github.com/github/explore/blob/db7f2f28385d413ba9e03a635009b3434c9710fc/topics/koa/koa.png