Closes #606.
Unified · Split
| @@ -2,6 +2,13 @@ module Docs · 1 unmodified line | |||
| 2 | class Express | 2 | class Express |
| 3 | class CleanHtmlFilter < Filter | 3 | class CleanHtmlFilter < Filter |
| 4 | def call | 4 | def call |
| 5 | i = 1 | ||
| 6 | n = at_css("#navmenu a[href='#{result[:path].split('/').last}']").parent | ||
| 7 | i += 1 while n && n = n.previous_element | ||
| 8 | at_css('h1')['data-level'] = i | ||
| 9 | |||
| 10 | @doc = at_css('#api-doc, .content') | ||
| 11 | |||
| 5 | css('section', 'div.highlighter-rouge').each do |node| | 12 | css('section', 'div.highlighter-rouge').each do |node| |
| 6 | node.before(node.children).remove | 13 | node.before(node.children).remove |
| 7 | end | 14 | end |
| @@ -4,11 +4,14 @@ module Docs · 3 unmodified lines | |||
| 4 | TYPES_BY_PATH = { | 4 | TYPES_BY_PATH = { |
| 5 | 'starter' => 'Getting started', | 5 | 'starter' => 'Getting started', |
| 6 | 'guide' => 'Guide', | 6 | 'guide' => 'Guide', |
| 7 | 'advanced' => 'Guide' | 7 | 'advanced' => 'Advanced topics' |
| 8 | } | 8 | } |
| 9 | 9 | ||
| 10 | def get_name | 10 | def get_name |
| 11 | at_css('h1').content | 11 | node = at_css('h1') |
| 12 | name = node.content | ||
| 13 | name.prepend "#{node['data-level']}. " if type.in?(%w(Guide Getting\ started Advanced\ topics)) | ||
| 14 | name | ||
| 12 | end | 15 | end |
| 13 | 16 | ||
| 14 | def get_type | 17 | def get_type |
| @@ -19,7 +22,7 @@ module Docs · 4 unmodified lines | |||
| 19 | return [] unless root_page? | 22 | return [] unless root_page? |
| 20 | type = 'Application' | 23 | type = 'Application' |
| 21 | 24 | ||
| 22 | doc.children.each_with_object [] do |node, entries| | 25 | at_css('#api-doc').children.each_with_object [] do |node, entries| |
| 23 | if node.name == 'h2' | 26 | if node.name == 'h2' |
| 24 | type = node.content | 27 | type = node.content |
| 25 | entries << [type, node['id'], 'Application'] if type == 'Middleware' | 28 | entries << [type, node['id'], 'Application'] if type == 'Middleware' |
| @@ -18,7 +18,6 @@ module Docs · 17 unmodified lines | |||
| 18 | 18 | ||
| 19 | options[:title] = false | 19 | options[:title] = false |
| 20 | options[:root_title] = 'Express' | 20 | options[:root_title] = 'Express' |
| 21 | options[:container] = ->(filter) { filter.root_page? ? '#api-doc' : '.content' } | ||
| 22 | 21 | ||
| 23 | options[:only_patterns] = [ | 22 | options[:only_patterns] = [ |
| 24 | /\Astarter/, | 23 | /\Astarter/, |