Improve Mongoose docs

sphinx-allow-dt-styles
Jed Fox 5 years ago
parent 142738e704
commit 92a0d28e48

@ -4,28 +4,12 @@ module Docs
def call
css('hr', '.showcode', '.sourcecode').remove
if slug == 'api'
at_css('.controls').after('<h1>Mongoose API</h1>')
css('.private', '.controls').remove
css('a + .method').each do |node|
node.previous_element.replace("<h2>#{node.previous_element.to_html}</h2>")
end
else
css('h2:empty + p').each do |node| # /customschematypes.html
node.previous_element.content = node.content
node.remove
end
at_css('h2').name = 'h1'
css('h3').each do |node|
node.name = 'h2'
end
end
css('pre > code', 'h1 + ul', '.module', '.item', 'h3 > a', 'h3 code').each do |node|
css('pre > code', 'h1 + ul', '.module', '.item', 'h1 > a', 'h2 > a', 'h3 > a', 'h3 code').each do |node|
node.before(node.children).remove
end
@ -33,6 +17,21 @@ module Docs
node['data-language'] = 'javascript'
end
css('.native-inline', '.api-nav', '.toc', '.api-content ul:first-child').remove
if !at_css('h1')
if css('h2').count > 1
# Mongoose vX.Y.Z: [title here]
title = doc.document.at_css('title').content.split(': ')[1]
doc.prepend_child("<h1>#{title}</title>")
else
at_css('h2').name = 'h1'
css('h3').each do |el|
el.name = 'h2'
end
end
end
doc
end
end

@ -2,23 +2,30 @@ module Docs
class Mongoose
class EntriesFilter < Docs::EntriesFilter
def get_name
if slug == 'api'
'Mongoose'
else
at_css('h1').content
end
end
def get_type
if slug == 'api'
'Mongoose'
else
if slug.start_with? 'api'
for heading in css('h3[id]')
type = get_type_from heading
return type if type
end
end
'Guides'
end
def get_type_from node
name = node.content.strip
type = name.split(/[#\.\(]/).first
if type.empty? || name.include?(' ')
nil
else
type
end
end
def additional_entries
return [] unless slug == 'api'
entries = []
css('h3[id]').each do |node|
@ -32,8 +39,8 @@ module Docs
name.sub! %r{\(.+\)}, '()'
next if name.include?(' ')
type = name.split(/[#\.\(]/).first
next if type.empty?
type = get_type_from node
next if type.nil?
entries << [name, id, type]
end

@ -5,7 +5,7 @@ module Docs
self.release = '5.7.7'
self.base_url = 'https://mongoosejs.com/docs/'
self.root_path = 'index.html'
self.initial_paths = %w(guide.html api.html)
self.initial_paths = %w(guide.html)
self.force_gzip = true
self.links = {
home: 'http://mongoosejs.com/',
@ -17,6 +17,7 @@ module Docs
options[:container] = '#content'
options[:skip] = %w(
api.html
faq.html
prior.html
migration.html

Loading…
Cancel
Save