From 1ac3dd93ddeaa0dadf7eb1faf4639bac1c53287d Mon Sep 17 00:00:00 2001 From: Enoc Date: Wed, 12 May 2021 16:37:19 -0600 Subject: [PATCH] Update nodejs to 16.1 and update previous version --- assets/stylesheets/pages/_node.scss | 4 +- lib/docs/filters/node/clean_html.rb | 15 ++++ lib/docs/filters/node/entries.rb | 90 ++++------------------- lib/docs/filters/node/old_entries.rb | 104 +++++++++++++++++++++++++++ lib/docs/scrapers/node.rb | 20 ++++-- 5 files changed, 147 insertions(+), 86 deletions(-) create mode 100644 lib/docs/filters/node/old_entries.rb diff --git a/assets/stylesheets/pages/_node.scss b/assets/stylesheets/pages/_node.scss index 5d0de4bb..de4a41c8 100644 --- a/assets/stylesheets/pages/_node.scss +++ b/assets/stylesheets/pages/_node.scss @@ -10,6 +10,9 @@ > h4 { @extend %block-label; } > h2 + h2, > h3 + h3 { margin-top: 0; } + h3 { @extend %block-label, %label-blue} + h4 { @extend %block-label } + p > code, li > code, .type { white-space: normal; @extend %label; @@ -24,4 +27,3 @@ .srclink { float: right; } details > table { margin: 0; } } - diff --git a/lib/docs/filters/node/clean_html.rb b/lib/docs/filters/node/clean_html.rb index 37c9ebb4..6c95139b 100644 --- a/lib/docs/filters/node/clean_html.rb +++ b/lib/docs/filters/node/clean_html.rb @@ -15,6 +15,8 @@ module Docs end css('pre').each do |node| + next unless node.at_css('code') + if lang = node.at_css('code')['class'] node['data-language'] = lang.remove(%r{lang(uage)?-}) end @@ -22,6 +24,19 @@ module Docs node.content = node.content end + css('h3 > code, h4 > code, h5 > code').each do |node| + tmp = node.content + has_parethesis = true if tmp =~ /\(/ + tmp.gsub!(/\(.*\)/, '') + + if has_parethesis + tmp << '()' + end + + node.parent['id'] = tmp + + end + doc end end diff --git a/lib/docs/filters/node/entries.rb b/lib/docs/filters/node/entries.rb index 361cfbeb..e725cc80 100644 --- a/lib/docs/filters/node/entries.rb +++ b/lib/docs/filters/node/entries.rb @@ -1,104 +1,38 @@ module Docs class Node class EntriesFilter < Docs::EntriesFilter - REPLACE_NAMES = { - 'addons' => 'C/C++ Addons', - 'debugger' => 'Debugger', - 'deprecations' => 'Deprecated APIs', - 'modules' => 'module' } - - REPLACE_TYPES = { - 'C++ Addons' => 'Miscellaneous', - 'C/C++ Addons' => 'Miscellaneous', - 'Debugger' => 'Miscellaneous', - 'Deprecated APIs' => 'Miscellaneous', - 'Tracing' => 'Miscellaneous', - 'os' => 'OS', - 'StringDecoder' => 'String Decoder', - 'TLS (SSL)' => 'TLS/SSL', - 'UDP / Datagram Sockets' => 'UDP/Datagram', - 'VM (Executing JavaScript)' => 'VM', - 'Executing JavaScript' => 'VM' } def get_name - REPLACE_NAMES[slug] || slug + type end def get_type - type = at_css('h1').content.strip - type.remove! %r{\[.*\]} - REPLACE_TYPES[type] || "#{type.first.upcase}#{type[1..-1]}" + at_css('h2').content.strip end def additional_entries - return [] if type == 'Miscellaneous' - - klass = nil entries = [] - css('> [id]').each do |node| - next if node.name == 'h1' - - klass = nil if node.name == 'h2' - name = node.content.strip - name.remove! %r{\s*\[src\]} - - # Skip constructors - if name.start_with? 'new ' - next - end - - # Ignore most global objects (found elsewhere) - if type == 'Global Objects' - entries << [name, node['id']] if name.start_with?('_') || name == 'global' - next - end + css('h3 > code, h4 > code, h5 > code').each do |node| - # Classes - if name.gsub! 'Class: ', '' - name.remove! 'events.' # EventEmitter - klass = name - entries << [name, node['id']] - next + case node.parent.child.content + when /Class/ + entries << ["Class #{node.parent['id']}", node.parent['id'], type] + when /Event/ + entries << ["Event #{node.parent['id']}", node.parent['id'], type] end - # Events - if name.sub! %r{\AEvent: '(.+)'\z}, '\1' - name << " event (#{klass || type})" - entries << [name, node['id']] + if node.parent.child.is_a?(Nokogiri::XML::Text) next + else + entries << [node.parent['id'], node.parent['id'], type] end - name.gsub! %r{\(.*?\);?}, '()' - name.gsub! %r{\[.+?\]}, '[]' - name.remove! 'assert(), ' # assert/assert.ok - - # Skip all that start with an uppercase letter ("Example") or include a space ("exports alias") - next unless (name.first.upcase! && !name.include?(' ')) || name.start_with?('Class Method') - - # Differentiate server classes (http, https, net, etc.) - name.sub!('server.') { "#{(klass || 'https').sub('.', '_').downcase}." } - # Differentiate socket classes (net, dgram, etc.) - name.sub!('socket.') { "#{klass.sub('.', '_').downcase}." } - - name.remove! 'Class Method:' - name.sub! 'buf.', 'buffer.' - name.sub! 'buf[', 'buffer[' - name.sub! 'child.', 'childprocess.' - name.sub! 'decoder.', 'stringdecoder.' - name.sub! 'emitter.', 'eventemitter.' - name.sub! %r{\Arl\.}, 'interface.' - name.sub! 'rs.', 'readstream.' - name.sub! 'ws.', 'writestream.' - - # Skip duplicates (listen, connect, etc.) - unless name == entries[-1].try(:first) || name == entries[-2].try(:first) - entries << [name, node['id']] - end end entries end + end end end diff --git a/lib/docs/filters/node/old_entries.rb b/lib/docs/filters/node/old_entries.rb new file mode 100644 index 00000000..e2878cb0 --- /dev/null +++ b/lib/docs/filters/node/old_entries.rb @@ -0,0 +1,104 @@ +module Docs + class Node + class OldEntriesFilter < Docs::EntriesFilter + REPLACE_NAMES = { + 'addons' => 'C/C++ Addons', + 'debugger' => 'Debugger', + 'deprecations' => 'Deprecated APIs', + 'modules' => 'module' } + + REPLACE_TYPES = { + 'C++ Addons' => 'Miscellaneous', + 'C/C++ Addons' => 'Miscellaneous', + 'Debugger' => 'Miscellaneous', + 'Deprecated APIs' => 'Miscellaneous', + 'Tracing' => 'Miscellaneous', + 'os' => 'OS', + 'StringDecoder' => 'String Decoder', + 'TLS (SSL)' => 'TLS/SSL', + 'UDP / Datagram Sockets' => 'UDP/Datagram', + 'VM (Executing JavaScript)' => 'VM', + 'Executing JavaScript' => 'VM' } + + def get_name + REPLACE_NAMES[slug] || slug + end + + def get_type + type = at_css('h1').content.strip + type.remove! %r{\[.*\]} + REPLACE_TYPES[type] || "#{type.first.upcase}#{type[1..-1]}" + end + + def additional_entries + return [] if type == 'Miscellaneous' + + klass = nil + entries = [] + + css('> [id]').each do |node| + next if node.name == 'h1' + + klass = nil if node.name == 'h2' + name = node.content.strip + name.remove! %r{\s*\[src\]} + + # Skip constructors + if name.start_with? 'new ' + next + end + + # Ignore most global objects (found elsewhere) + if type == 'Global Objects' + entries << [name, node['id']] if name.start_with?('_') || name == 'global' + next + end + + # Classes + if name.gsub! 'Class: ', '' + name.remove! 'events.' # EventEmitter + klass = name + entries << [name, node['id']] + next + end + + # Events + if name.sub! %r{\AEvent: '(.+)'\z}, '\1' + name << " event (#{klass || type})" + entries << [name, node['id']] + next + end + + name.gsub! %r{\(.*?\);?}, '()' + name.gsub! %r{\[.+?\]}, '[]' + name.remove! 'assert(), ' # assert/assert.ok + + # Skip all that start with an uppercase letter ("Example") or include a space ("exports alias") + next unless (name.first.upcase! && !name.include?(' ')) || name.start_with?('Class Method') + + # Differentiate server classes (http, https, net, etc.) + name.sub!('server.') { "#{(klass || 'https').sub('.', '_').downcase}." } + # Differentiate socket classes (net, dgram, etc.) + name.sub!('socket.') { "#{klass.sub('.', '_').downcase}." } + + name.remove! 'Class Method:' + name.sub! 'buf.', 'buffer.' + name.sub! 'buf[', 'buffer[' + name.sub! 'child.', 'childprocess.' + name.sub! 'decoder.', 'stringdecoder.' + name.sub! 'emitter.', 'eventemitter.' + name.sub! %r{\Arl\.}, 'interface.' + name.sub! 'rs.', 'readstream.' + name.sub! 'ws.', 'writestream.' + + # Skip duplicates (listen, connect, etc.) + unless name == entries[-1].try(:first) || name == entries[-2].try(:first) + entries << [name, node['id']] + end + end + + entries + end + end + end +end diff --git a/lib/docs/scrapers/node.rb b/lib/docs/scrapers/node.rb index 74b370cb..a39da5ad 100644 --- a/lib/docs/scrapers/node.rb +++ b/lib/docs/scrapers/node.rb @@ -14,6 +14,7 @@ module Docs options[:root_title] = 'Node.js' options[:container] = '#apicontent' options[:skip] = %w(index.html all.html documentation.html synopsis.html) + # options[:only] = ['addons.html'] options[:attribution] = <<-HTML © Joyent, Inc. and other Node contributors
@@ -23,38 +24,43 @@ module Docs HTML version do - self.release = '15.5.0' - self.base_url = 'https://nodejs.org/dist/latest-v15.x/docs/api/' + self.release = '16.1.0' + self.base_url = 'https://nodejs.org/api/' end version '14 LTS' do - self.release = '14.15.3' + self.release = '14.17.0' self.base_url = 'https://nodejs.org/dist/latest-v14.x/docs/api/' end version '12 LTS' do - self.release = '12.19.0' + self.release = '12.22.1' self.base_url = 'https://nodejs.org/dist/latest-v12.x/docs/api/' + html_filters.replace('node/entries', 'node/old_entries') end version '10 LTS' do - self.release = '10.16.3' + self.release = '10.24.1' self.base_url = 'https://nodejs.org/dist/latest-v10.x/docs/api/' + html_filters.replace('node/entries', 'node/old_entries') end version '8 LTS' do - self.release = '8.16.1' + self.release = '8.17.0' self.base_url = 'https://nodejs.org/dist/latest-v8.x/docs/api/' + html_filters.replace('node/entries', 'node/old_entries') end version '6 LTS' do - self.release = '6.14.4' + self.release = '6.17.1' self.base_url = 'https://nodejs.org/dist/latest-v6.x/docs/api/' + html_filters.replace('node/entries', 'node/old_entries') end version '4 LTS' do self.release = '4.9.1' self.base_url = 'https://nodejs.org/dist/latest-v4.x/docs/api/' + html_filters.replace('node/entries', 'node/old_entries') end def get_latest_version(opts)