Skip to content

Commit b97cfa6

Browse files
j-f1Thibaut
authored andcommitted
Add Koa
1 parent b4cd5f1 commit b97cfa6

File tree

7 files changed

+118
-1
lines changed

7 files changed

+118
-1
lines changed

lib/docs/filters/github/clean_html.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def call
99

1010
css('.highlight > pre').each do |node|
1111
node['data-language'] = node.parent['class'][/highlight-source-(\w+)/, 1]
12-
node.content = node.content.strip_heredoc.gsub(' ', ' ')
12+
node.content = node.content.strip_heredoc
1313
node.parent.replace(node)
1414
end
1515

lib/docs/filters/koa/clean_html.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
module Docs
4+
class Koa
5+
class CleanHtmlFilter < Filter
6+
def call
7+
fix_homepage if slug.start_with? 'api/index'
8+
9+
css('[data-language=shell]').each do |node|
10+
node['data-language'] = 'bash'
11+
end
12+
13+
doc
14+
end
15+
16+
def fix_homepage
17+
# Shrink the headers
18+
for n in (1..5).to_a.reverse
19+
css("h#{n}").each do |header|
20+
header.name = "h#{n+1}"
21+
end
22+
end
23+
24+
# Add an introduction
25+
doc.children.before <<-HTML.strip_heredoc
26+
<h1>Koa</h1>
27+
<!-- https://github.com/koajs/koa/blob/841844e/Readme.md -->
28+
<h2 id="introduction">Introduction</h2>
29+
<p>
30+
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.
31+
</p>
32+
<p>
33+
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.
34+
</p>
35+
<p>
36+
Koa is not bundled with any middleware.
37+
</p>
38+
HTML
39+
end
40+
end
41+
end
42+
end

lib/docs/filters/koa/entries.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module Docs
2+
class Koa
3+
class EntriesFilter < Docs::EntriesFilter
4+
@root_type = 'Koa'
5+
def get_name
6+
at_css('h1').content
7+
end
8+
9+
def additional_entries
10+
return [] unless slug.match?(/^api/)
11+
type = get_name
12+
css('h2, h3').to_a
13+
.delete_if do |node|
14+
node.content == 'API' ||
15+
(slug.include?('index') && !node.content.include?('.'))
16+
end
17+
.map do |node|
18+
name = node.content.sub(/\(.*\)$/, '')
19+
type = 'API' if type == @root_type && name.include?('.')
20+
[name, node['id'], type]
21+
end
22+
end
23+
24+
def get_type
25+
case slug
26+
when /^api\/index/
27+
'API'
28+
when /^api/
29+
get_name
30+
else
31+
'Guides'
32+
end
33+
end
34+
end
35+
end
36+
end

lib/docs/scrapers/koa.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
module Docs
4+
class Koa < Github
5+
self.base_url = 'https://github.com/koajs/koa/blob/master/docs/'
6+
self.release = '2.4.1'
7+
8+
self.root_path = 'api/index.md'
9+
self.initial_paths = %w[
10+
error-handling
11+
faq
12+
guide
13+
koa-vs-express
14+
migration
15+
troubleshooting
16+
api/index
17+
api/context
18+
api/request
19+
api/response
20+
].map { |name| name + '.md' }
21+
22+
self.links = {
23+
home: 'https://koajs.com/',
24+
code: 'https://github.com/koajs/koa'
25+
}
26+
27+
html_filters.push 'koa/clean_html', 'koa/entries'
28+
29+
options[:skip] = %w[middleware.gif]
30+
options[:trailing_slash] = false
31+
options[:container] = '.markdown-body'
32+
33+
options[:attribution] = <<-HTML
34+
&copy; 2017 Koa contributors<br>
35+
Licensed under the MIT License.
36+
HTML
37+
end
38+
end

public/icons/docs/koa/16.png

847 Bytes
Loading
1.51 KB
Loading

public/icons/docs/koa/SOURCE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/github/explore/blob/db7f2f28385d413ba9e03a635009b3434c9710fc/topics/koa/koa.png

0 commit comments

Comments
 (0)