Skip to content

Commit 693d051

Browse files
committed
feat(nushell): add book
1 parent 74c7f62 commit 693d051

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

lib/docs/filters/nushell/clean_html.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ module Docs
33
class Nushell
44
class CleanHtmlFilter < Filter
55
def call
6-
# css('header').remove
7-
# css('aside').remove
86
css('footer').remove
97
css('h1 a, h2 a').remove
108
doc

lib/docs/filters/nushell/entries.rb

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,26 @@ def include_default_entry?
2626
def additional_entries
2727
entries = []
2828
type = ""
29-
css("h1").each do |node|
30-
name = node.at_css("code") ?
31-
node.at_css("code").text : node.text
32-
type = node.children.length >= 3 ?
33-
node.children[2].text.sub(" for ", "").capitalize :
34-
node.text
35-
# id = type.downcase.gsub(" ", "-")
36-
id = "_"
37-
if name != "Command Reference"
29+
if "#{self.base_url}" == "https://www.nushell.sh/book/" && !self.root_page?
30+
active_items = css("a.sidebar-item.active")
31+
if active_items.length > 0
32+
type = active_items[0].text.strip()
33+
name = active_items[-1].text.strip()
34+
id = "_"
35+
entries << [name, id, type]
36+
end
37+
else
38+
css("h1").each do |node|
39+
name = node.at_css("code") ?
40+
node.at_css("code").text : node.text
41+
type = node.children.length >= 3 ?
42+
node.children[2].text.sub(" for ", "").capitalize :
43+
node.text
44+
# id = type.downcase.gsub(" ", "-")
45+
id = "_"
46+
if self.root_page?
47+
id = "#{self.base_url}".split('/')[-1]
48+
end
3849
entries << [name, id, type]
3950
end
4051
end

lib/docs/filters/nushell/fix_links.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ module Docs
33
class Nushell
44
class FixLinksFilter < Filter
55
def call
6+
css('header').remove
7+
css('aside').remove
68
css('a').each do |node|
7-
node["href"] = "#{node["href"]}#_"
9+
if !(node["href"].starts_with?("https://") || node["href"].starts_with?("http://"))
10+
node["href"] = "#{node["href"]}#_"
11+
end
812
end
913
doc
1014
end

lib/docs/scrapers/nushell.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Nushell < UrlScraper
1414

1515
html_filters.push "nushell/clean_html", "nushell/entries", "nushell/fix_links"
1616

17-
options[:container] = '.theme-default-content'
17+
options[:container] = '.theme-container'
1818
options[:follow_links] = true
1919
options[:title] = "Nushell"
2020
options[:attribution] = <<-HTML
@@ -26,7 +26,7 @@ class Nushell < UrlScraper
2626
version do
2727
self.release = "0.84.0"
2828
self.base_urls = [
29-
# "https://www.nushell.sh/book/",
29+
"https://www.nushell.sh/book/",
3030
"https://www.nushell.sh/commands/"
3131
]
3232
end

0 commit comments

Comments
 (0)