Improve Express scraper

Closes #606.
pull/620/head
Thibaut Courouble 8 years ago
parent c35aaeffc7
commit 435488c6c2

@ -2,6 +2,13 @@ module Docs
class Express
class CleanHtmlFilter < Filter
def call
i = 1
n = at_css("#navmenu a[href='#{result[:path].split('/').last}']").parent
i += 1 while n && n = n.previous_element
at_css('h1')['data-level'] = i
@doc = at_css('#api-doc, .content')
css('section', 'div.highlighter-rouge').each do |node|
node.before(node.children).remove
end

@ -4,11 +4,14 @@ module Docs
TYPES_BY_PATH = {
'starter' => 'Getting started',
'guide' => 'Guide',
'advanced' => 'Guide'
'advanced' => 'Advanced topics'
}
def get_name
at_css('h1').content
node = at_css('h1')
name = node.content
name.prepend "#{node['data-level']}. " if type.in?(%w(Guide Getting\ started Advanced\ topics))
name
end
def get_type
@ -19,7 +22,7 @@ module Docs
return [] unless root_page?
type = 'Application'
doc.children.each_with_object [] do |node, entries|
at_css('#api-doc').children.each_with_object [] do |node, entries|
if node.name == 'h2'
type = node.content
entries << [type, node['id'], 'Application'] if type == 'Middleware'

@ -18,7 +18,6 @@ module Docs
options[:title] = false
options[:root_title] = 'Express'
options[:container] = ->(filter) { filter.root_page? ? '#api-doc' : '.content' }
options[:only_patterns] = [
/\Astarter/,

Loading…
Cancel
Save