Update Immutable.js documentation (4.0.0)

pull/1663/head
Simon Legner 3 years ago
parent 148c9e55d4
commit 5c3b7d14b4

@ -388,9 +388,9 @@ credits = [
'https://raw.githubusercontent.com/Homebrew/brew/master/LICENSE.txt' 'https://raw.githubusercontent.com/Homebrew/brew/master/LICENSE.txt'
], [ ], [
'Immutable.js', 'Immutable.js',
'2014-2016 Facebook, Inc.', '2014present Lee Byron and other contributors',
'BSD', 'BSD',
'https://raw.githubusercontent.com/facebook/immutable-js/master/LICENSE' 'https://github.com/immutable-js/immutable-js/blob/main/LICENSE'
], [ ], [
'InfluxData', 'InfluxData',
'2015 InfluxData, Inc.', '2015 InfluxData, Inc.',

@ -2,6 +2,9 @@ module Docs
class Immutable class Immutable
class CleanHtmlFilter < Filter class CleanHtmlFilter < Filter
def call def call
@doc = at_css('div')
css('#algolia-autocomplete', '#algolia-docsearch').remove
css('section', 'span', 'div[data-reactid]').each do |node| css('section', 'span', 'div[data-reactid]').each do |node|
node.before(node.children).remove node.before(node.children).remove
end end
@ -9,36 +12,11 @@ module Docs
css('.codeBlock').each do |node| css('.codeBlock').each do |node|
node.name = 'pre' node.name = 'pre'
node.content = node.content node.content = node.content
node['data-language'] = 'js' node['data-language'] = 'ts'
end end
css('*[data-reactid]').remove_attr('data-reactid') css('*[data-reactid]').remove_attr('data-reactid')
css('a[target]').remove_attr('target') css('a[target]').remove_attr('target')
css('a[href^="#"]').each do |node|
node['href'] = node['href'].sub(/\A#\//, '#').gsub('/', '.').downcase
end
type = type_id = nil
css('*').each do |node|
if node.name == 'h1'
node['id'] = type_id = node.content.strip.downcase
type = node.content.strip
elsif node.name == 'h3'
node['id'] = node.content.strip.downcase
node['id'] = node['id'].remove('()') unless node['id'] == "#{type_id}()"
unless node['id'].start_with?(type_id)
node.content = "#{type}##{node.content}"
node['id'] = "#{type_id}.#{node['id']}" unless node['id'].start_with?("#{type_id}.")
end
end
end
css('h4.groupTitle').each do |node|
node.name = 'h2'
end
css('*[class]').remove_attr('class') css('*[class]').remove_attr('class')
doc doc

@ -1,21 +1,24 @@
module Docs module Docs
class Immutable class Immutable
class EntriesFilter < Docs::EntriesFilter class EntriesFilter < Docs::EntriesFilter
def get_name
at_css('h1').content
end
def get_type
return 'Util' if slug.match?(/^([a-z]|Range|Repeat)/)
at_css('h1').content
end
def additional_entries def additional_entries
return [] if root_page?
entries = [] entries = []
type = nil css('h2, h3, h4').each do |node|
css('*').each do |node|
if node.name == 'h1'
name = node.content
type = node.content.split('.').first
entries << [name, node['id'], type]
elsif node.name == 'h3'
name = node.content name = node.content
entries << [name, node['id'], type] id = node.parent['id']
next unless id
entries << ["#{type}.#{name}", id, type]
end end
end
entries entries
end end
end end

@ -3,58 +3,31 @@ module Docs
self.name = 'Immutable.js' self.name = 'Immutable.js'
self.slug = 'immutable' self.slug = 'immutable'
self.type = 'simple' self.type = 'simple'
self.release = '3.8.1' self.release = '4.0.0'
self.base_url = 'https://facebook.github.io/immutable-js/docs/' self.base_url = 'https://immutable-js.com/docs/v4.0.0/'
self.links = { self.links = {
home: 'https://facebook.github.io/immutable-js/', home: 'https://immutable-js.com/',
code: 'https://github.com/facebook/immutable-js' code: 'https://github.com/facebook/immutable-js'
} }
html_filters.push 'immutable/clean_html', 'immutable/entries', 'title' html_filters.push 'immutable/clean_html', 'immutable/entries'
options[:skip_links] = true
options[:container] = '.docContents' options[:container] = '.docContents'
options[:root_title] = 'Immutable.js' options[:root_title] = 'Immutable.js'
options[:trailing_slash] = true
options[:fix_urls] = ->(url) do
url.sub! '/index.html', ''
url.sub! '/index', ''
url
end
options[:attribution] = <<-HTML options[:attribution] = <<-HTML
&copy; 2014&ndash;2015 Facebook, Inc.<br> &copy; 2014present, Lee Byron and other contributors<br>
Licensed under the 3-clause BSD License. Licensed under the 3-clause BSD License.
HTML HTML
stub '' do
capybara = load_capybara_selenium
capybara.app_host = 'https://facebook.github.io'
capybara.visit(URL.parse(self.base_url).path)
capybara.execute_script <<-JS
var content, event, links, link;
event = document.createEvent('Event');
event.initEvent('hashchange', false, false);
content = document.querySelector('.docContents section').cloneNode(true);
links = Array.prototype.slice.call(document.querySelectorAll('.sideBar .scrollContent a'));
while (link = links.shift()) {
if (!document.body.contains(link)) {
document.body.appendChild(link);
}
link.click();
dispatchEvent(event);
content.innerHTML += document.querySelector('.docContents').innerHTML;
document.querySelectorAll('.sideBar .scrollContent .groupTitle').forEach(function(el) {
if (el.textContent == 'Types') {
Array.prototype.unshift.apply(links, Array.prototype.slice.call(el.parentNode.querySelectorAll('a')));
}
});
}
document.querySelector('.docContents').innerHTML = content.innerHTML;
JS
capybara.html
end
def get_latest_version(opts) def get_latest_version(opts)
get_npm_version('immutable', opts) get_npm_version('immutable', opts)
end end

Loading…
Cancel
Save