History

Change where GitHub scraper gets its JSON. Fix Koa, Q, Sanctuary, and Lua/nginx imports

spamguy committed 1 year ago

Commit 3794bf61 parent b661f689 files · +30 −20Browse files

Unified · Split

9 files
  1. lib/docs/filters/github/clean_html.rb +5 −0
  2. lib/docs/filters/nginx_lua_module/entries.rb +2 −2
  3. lib/docs/filters/sanctuary_def/entries.rb +3 −1
  4. lib/docs/filters/sanctuary_type_classes/clean_html.rb +0 −5
  5. lib/docs/filters/sanctuary_type_classes/entries.rb +2 −2
  6. lib/docs/scrapers/github.rb +7 −1
  7. lib/docs/scrapers/koa.rb +2 −2
  8. lib/docs/scrapers/nginx_lua_module.rb +7 −5
  9. lib/docs/scrapers/q.rb +2 −2
lib/docs/filters/github/clean_html.rb+5−0
@@ -2,6 +2,11 @@ module Docs · 1 unmodified line
22 class Github
33 class CleanHtmlFilter < Filter
44 def call
5+ # Remove h1 wrapper to render it correctly.
6+ css('.markdown-heading h1').each do |node|
7+ node.parent.replace(node)
8+ end
9+
510 css('.anchor').each do |node|
611 node.parent['id'] = node['href'].remove('#')
712 node.remove
lib/docs/filters/nginx_lua_module/entries.rb+2−2
@@ -4,11 +4,11 @@ module Docs · 3 unmodified lines
44 def additional_entries
55 entries = []
66
7− css('#directives + ul > li > a').each do |node|
7+ css('h2:contains("Directives") + ul > li > a').each do |node|
88 entries << [node.content, node['href'].remove('#'), 'Directives']
99 end
1010
11− css('#nginx-api-for-lua + ul > li > a').each do |node|
11+ css('h2:contains("Nginx API for Lua") + ul > li > a').each do |node|
1212 next if node.content == 'Introduction'
1313 entries << [node.content, node['href'].remove('#'), 'Nginx API for Lua']
1414 end
lib/docs/filters/sanctuary_def/entries.rb+3−1
@@ -39,8 +39,10 @@ module Docs · 38 unmodified lines
3939 when "h3"
4040 type = node.text
4141 when "h4"
42+ # Parent <div>'s ID set in github/clean_html.
43+ id = node.parent.attributes["id"].value
4244 name = node.text.split(' :: ')[0]
43− id = node.attributes["id"].value
45+
4446 entries << [name, id, type]
4547 end
4648 end
lib/docs/filters/sanctuary_type_classes/clean_html.rb+0−5
@@ -8,11 +8,6 @@ module Docs · 7 unmodified lines
88 node.name = 'h3'
99 }
1010
11− # correct and unify link ids
12− css('h3').each { |node|
13− node.attributes["id"].value = node.text.split(' :: ')[0]
14− }
15−
1611 doc
1712 end
1813 end
lib/docs/filters/sanctuary_type_classes/entries.rb+2−2
@@ -38,9 +38,9 @@ module Docs · 37 unmodified lines
3838 case node.name
3939 when "h2"
4040 type = node.text
41− if node.attributes["id"].value == "type-class-hierarchy"
41+ if node.parent.attributes["id"]&.value == "type-class-hierarchy"
4242 name = node.text
43− id = node.attributes["id"].value
43+ id = node.parent.attributes["id"].value
4444 entries << [name, id, type]
4545 end
4646 when "h4"
lib/docs/scrapers/github.rb+7−1
@@ -16,7 +16,13 @@ module Docs · 15 unmodified lines
1616 end
1717
1818 def parse(response)
19− parsed = JSON.parse(response.response_body)
19+ embedded_json = response
20+ .response_body
21+ .match(/react-app\.embeddedData">(.+?)<\/script>/)
22+ &.captures
23+ &.first
24+ parsed = JSON.parse(embedded_json)
25+
2026 [parsed['payload']['blob']['richText'], parsed['title']]
2127 end
2228 end
lib/docs/scrapers/koa.rb+2−2
@@ -2,7 +2,7 @@ · 1 unmodified line
22
33 module Docs
44 class Koa < Github
5− self.base_url = 'https://github.com/koajs/koa/tree/master/docs'
5+ self.base_url = 'https://github.com/koajs/koa/blob/master/docs'
66 self.release = '2.15.0'
77
88 self.root_path = 'api/index.md'
@@ -26,7 +26,7 @@ module Docs · 17 unmodified lines
2626
2727 html_filters.push 'koa/clean_html', 'koa/entries'
2828
29− options[:skip] = %w[middleware.gif]
29+ options[:skip_patterns] = [/\.gif/]
3030 options[:trailing_slash] = false
3131 options[:container] = '.markdown-body'
3232
lib/docs/scrapers/nginx_lua_module.rb+7−5
@@ -2,8 +2,9 @@ module Docs · 1 unmodified line
22 class NginxLuaModule < Github
33 self.name = 'nginx / Lua Module'
44 self.slug = 'nginx_lua_module'
5− self.release = '0.10.13'
6− self.base_url = "https://github.com/openresty/lua-nginx-module/tree/v#{self.release}/"
5+ self.release = '0.10.28'
6+ self.base_url = "https://github.com/openresty/lua-nginx-module/blob/v#{self.release}/"
7+ self.root_path = 'README.markdown'
78 self.links = {
89 code: 'https://github.com/openresty/lua-nginx-module'
910 }
@@ -11,13 +12,14 @@ module Docs · 1 unmodified line
1112 html_filters.push 'nginx_lua_module/clean_html', 'nginx_lua_module/entries', 'title'
1213
1314 options[:root_title] = 'ngx_http_lua_module'
14− options[:container] = '#readme > article'
15−
15+ options[:container] = '.markdown-body'
16+ options[:max_image_size] = 256_000
1617 options[:attribution] = <<-HTML
1718 &copy; 2009&ndash;2017 Xiaozhe Wang (chaoslawful)<br>
18− &copy; 2009&ndash;2018 Yichun "agentzh" Zhang (章亦春), OpenResty Inc.<br>
19+ &copy; 2009&ndash;2019 Yichun "agentzh" Zhang (章亦春), OpenResty Inc.<br>
1920 Licensed under the BSD License.
2021 HTML
22+ options[:skip_patterns] = [/\.png/]
2123
2224 def get_latest_version(opts)
2325 tags = get_github_tags('openresty', 'lua-nginx-module', opts)
lib/docs/scrapers/q.rb+2−2
@@ -1,5 +1,5 @@
11 module Docs
2− class Q < Github
2+ class Q < UrlScraper
33 self.name = 'Q'
44 self.release = '1.5.1'
55 self.base_url = 'https://github.com/kriskowal/q/wiki/'
@@ -16,7 +16,7 @@ module Docs · 10 unmodified lines
1616 options[:skip_links] = true
1717
1818 options[:attribution] = <<-HTML
19− &copy; 2009&ndash;2017 Kristopher Michael Kowal<br>
19+ &copy; 2009&ndash;2018 Kristopher Michael Kowal<br>
2020 Licensed under the MIT License.
2121 HTML
2222