History

crystal: /docs -> /reference

Simon Legner committed 5 years ago

Commit eb306171 parent 457924b3 files · +15 −11Browse files

Unified · Split

3 files
  1. lib/docs/filters/crystal/clean_html.rb +5 −2
  2. lib/docs/filters/crystal/entries.rb +6 −5
  3. lib/docs/scrapers/crystal.rb +4 −4
lib/docs/filters/crystal/clean_html.rb+5−2
@@ -2,14 +2,17 @@ module Docs · 1 unmodified line
2 class Crystal2 class Crystal
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 slug.start_with?('docs') ? book : api5 slug.start_with?('reference') ? book : api
6 doc6 doc
7 end7 end
8 8
9 def book9 def book
10 @doc = at_css('.page-inner section')10 @doc = at_css('main article')
11
12 css('.headerlink').remove
11 13
12 css('pre > code').each do |node|14 css('pre > code').each do |node|
15 node.parent['data-language'] = 'crystal'
13 node.parent['data-language'] = node['class'][/lang-(\w+)/, 1] if node['class']16 node.parent['data-language'] = node['class'][/lang-(\w+)/, 1] if node['class']
14 node.parent.content = node.parent.content17 node.parent.content = node.parent.content
15 end18 end
lib/docs/filters/crystal/entries.rb+6−5
@@ -2,10 +2,11 @@ module Docs · 1 unmodified line
2 class Crystal2 class Crystal
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 def get_name4 def get_name
5 if slug.start_with?('docs/')5 if slug.start_with?('reference/')
6 name = at_css('.page-inner h1').content.strip6 name = at_css('main h1').content.strip
7 name.remove! '¶'
7 8
8 if slug.start_with?('docs/syntax_and_semantics')9 if slug.start_with?('reference/syntax_and_semantics')
9 name.prepend "#{slug.split('/')[2].titleize}: " if slug.split('/').length > 310 name.prepend "#{slug.split('/')[2].titleize}: " if slug.split('/').length > 3
10 elsif slug.split('/').length > 111 elsif slug.split('/').length > 1
11 chapter = slug.split('/')[1].titleize.capitalize12 chapter = slug.split('/')[1].titleize.capitalize
@@ -23,9 +24,9 @@ module Docs · 11 unmodified lines
23 def get_type24 def get_type
24 return if root_page?25 return if root_page?
25 26
26 if slug.start_with?('docs/syntax_and_semantics')27 if slug.start_with?('reference/syntax_and_semantics')
27 'Book: Language'28 'Book: Language'
28 elsif slug.start_with?('docs/')29 elsif slug.start_with?('reference/')
29 'Book'30 'Book'
30 else31 else
31 hierarchy = at_css('.superclass-hierarchy')32 hierarchy = at_css('.superclass-hierarchy')
lib/docs/scrapers/crystal.rb+4−4
@@ -2,7 +2,7 @@ module Docs · 1 unmodified line
2 class Crystal < UrlScraper2 class Crystal < UrlScraper
3 self.type = 'crystal'3 self.type = 'crystal'
4 self.base_url = 'https://crystal-lang.org/'4 self.base_url = 'https://crystal-lang.org/'
5 self.initial_paths = %w(docs/index.html)5 self.initial_paths = %w(reference/index.html)
6 self.links = {6 self.links = {
7 home: 'https://crystal-lang.org/',7 home: 'https://crystal-lang.org/',
8 code: 'https://github.com/crystal-lang/crystal'8 code: 'https://github.com/crystal-lang/crystal'
@@ -11,7 +11,7 @@ module Docs · 2 unmodified lines
11 html_filters.push 'crystal/entries', 'crystal/clean_html'11 html_filters.push 'crystal/entries', 'crystal/clean_html'
12 12
13 options[:attribution] = ->(filter) {13 options[:attribution] = ->(filter) {
14 if filter.slug.start_with?('docs')14 if filter.slug.start_with?('reference')
15 <<-HTML15 <<-HTML
16 To the extent possible under law, the persons who contributed to this work16 To the extent possible under law, the persons who contributed to this work
17 have waived<br>all copyright and related or neighboring rights to this work17 have waived<br>all copyright and related or neighboring rights to this work
@@ -29,12 +29,12 @@ module Docs · 11 unmodified lines
29 self.release = '0.36.1'29 self.release = '0.36.1'
30 self.root_path = "api/#{release}/index.html"30 self.root_path = "api/#{release}/index.html"
31 31
32 options[:only_patterns] = [/\Adocs\//, /\Aapi\/#{release}\//]32 options[:only_patterns] = [/\Aapi\/#{release}\//, /\Areference\//]
33 options[:skip_patterns] = [/debug/i]33 options[:skip_patterns] = [/debug/i]
34 34
35 options[:replace_paths] = {35 options[:replace_paths] = {
36 "api/#{release}/" => "api/#{release}/index.html",36 "api/#{release}/" => "api/#{release}/index.html",
37 'docs/' => 'docs/index.html'37 'reference/' => 'reference/index.html'
38 }38 }
39 end39 end
40 40