mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
Add Koa
This commit is contained in:
parent
b4cd5f1802
commit
b97cfa6693
7 changed files with 118 additions and 1 deletions
|
@ -9,7 +9,7 @@ module Docs
|
||||||
|
|
||||||
css('.highlight > pre').each do |node|
|
css('.highlight > pre').each do |node|
|
||||||
node['data-language'] = node.parent['class'][/highlight-source-(\w+)/, 1]
|
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)
|
node.parent.replace(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
42
lib/docs/filters/koa/clean_html.rb
Normal file
42
lib/docs/filters/koa/clean_html.rb
Normal file
|
@ -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
lib/docs/filters/koa/entries.rb
Normal file
36
lib/docs/filters/koa/entries.rb
Normal file
|
@ -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
lib/docs/scrapers/koa.rb
Normal file
38
lib/docs/scrapers/koa.rb
Normal file
|
@ -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<br>
|
||||||
|
Licensed under the MIT License.
|
||||||
|
HTML
|
||||||
|
end
|
||||||
|
end
|
BIN
public/icons/docs/koa/16.png
Normal file
BIN
public/icons/docs/koa/16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 847 B |
BIN
public/icons/docs/koa/16@2x.png
Normal file
BIN
public/icons/docs/koa/16@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.5 KiB |
1
public/icons/docs/koa/SOURCE
Normal file
1
public/icons/docs/koa/SOURCE
Normal file
|
@ -0,0 +1 @@
|
||||||
|
https://github.com/github/explore/blob/db7f2f28385d413ba9e03a635009b3434c9710fc/topics/koa/koa.png
|
Loading…
Reference in a new issue