From 693d051c8f79b1d36c2694252c8e0215e3237abb Mon Sep 17 00:00:00 2001 From: Jan Christoph Ebersbach Date: Thu, 7 Sep 2023 08:36:41 +0200 Subject: [PATCH] feat(nushell): add book --- lib/docs/filters/nushell/clean_html.rb | 2 -- lib/docs/filters/nushell/entries.rb | 29 ++++++++++++++++++-------- lib/docs/filters/nushell/fix_links.rb | 6 +++++- lib/docs/scrapers/nushell.rb | 4 ++-- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/lib/docs/filters/nushell/clean_html.rb b/lib/docs/filters/nushell/clean_html.rb index 8aa9b156..b9453c6a 100644 --- a/lib/docs/filters/nushell/clean_html.rb +++ b/lib/docs/filters/nushell/clean_html.rb @@ -3,8 +3,6 @@ module Docs class Nushell class CleanHtmlFilter < Filter def call - # css('header').remove - # css('aside').remove css('footer').remove css('h1 a, h2 a').remove doc diff --git a/lib/docs/filters/nushell/entries.rb b/lib/docs/filters/nushell/entries.rb index c99563a7..6e922419 100644 --- a/lib/docs/filters/nushell/entries.rb +++ b/lib/docs/filters/nushell/entries.rb @@ -26,15 +26,26 @@ module Docs def additional_entries entries = [] type = "" - css("h1").each do |node| - name = node.at_css("code") ? - node.at_css("code").text : node.text - type = node.children.length >= 3 ? - node.children[2].text.sub(" for ", "").capitalize : - node.text - # id = type.downcase.gsub(" ", "-") - id = "_" - if name != "Command Reference" + if "#{self.base_url}" == "https://www.nushell.sh/book/" && !self.root_page? + active_items = css("a.sidebar-item.active") + if active_items.length > 0 + type = active_items[0].text.strip() + name = active_items[-1].text.strip() + id = "_" + entries << [name, id, type] + end + else + css("h1").each do |node| + name = node.at_css("code") ? + node.at_css("code").text : node.text + type = node.children.length >= 3 ? + node.children[2].text.sub(" for ", "").capitalize : + node.text + # id = type.downcase.gsub(" ", "-") + id = "_" + if self.root_page? + id = "#{self.base_url}".split('/')[-1] + end entries << [name, id, type] end end diff --git a/lib/docs/filters/nushell/fix_links.rb b/lib/docs/filters/nushell/fix_links.rb index 4f7cfc94..0868eceb 100644 --- a/lib/docs/filters/nushell/fix_links.rb +++ b/lib/docs/filters/nushell/fix_links.rb @@ -3,8 +3,12 @@ module Docs class Nushell class FixLinksFilter < Filter def call + css('header').remove + css('aside').remove css('a').each do |node| - node["href"] = "#{node["href"]}#_" + if !(node["href"].starts_with?("https://") || node["href"].starts_with?("http://")) + node["href"] = "#{node["href"]}#_" + end end doc end diff --git a/lib/docs/scrapers/nushell.rb b/lib/docs/scrapers/nushell.rb index 40200d22..ff078c23 100644 --- a/lib/docs/scrapers/nushell.rb +++ b/lib/docs/scrapers/nushell.rb @@ -14,7 +14,7 @@ module Docs html_filters.push "nushell/clean_html", "nushell/entries", "nushell/fix_links" - options[:container] = '.theme-default-content' + options[:container] = '.theme-container' options[:follow_links] = true options[:title] = "Nushell" options[:attribution] = <<-HTML @@ -26,7 +26,7 @@ module Docs version do self.release = "0.84.0" self.base_urls = [ - # "https://www.nushell.sh/book/", + "https://www.nushell.sh/book/", "https://www.nushell.sh/commands/" ] end