Skip to content

Commit e1e9f8b

Browse files
committed
Update rustc error codes URL, and improve Rust logic for page names
Fixes #2568
1 parent d877a45 commit e1e9f8b

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

lib/docs/filters/rust/clean_html.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ module Docs
44
class Rust
55
class CleanHtmlFilter < Filter
66
def call
7-
if slug.start_with?('book') || slug.start_with?('reference')
7+
if slug.start_with?('book') || slug.start_with?('reference') || slug.start_with?('error_codes')
88
@doc = at_css('#content main')
9-
elsif slug == 'error-index'
9+
elsif slug.start_with?('error_codes')
1010
css('.error-undescribed').remove
1111

1212
css('.error-described').each do |node|

lib/docs/filters/rust/entries.rb

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@ class Rust
33
class EntriesFilter < Docs::EntriesFilter
44

55
def get_name
6-
if slug.start_with?('book') || slug.start_with?('reference')
7-
name = at_css("h2", "h1")
8-
ch1 = slug[/ch(\d+)-(\d+)/, 1]
9-
ch2 = slug[/ch(\d+)-(\d+)/, 2]
6+
if slug.start_with?('book')
7+
name = at_css('main h1', 'main h2')
8+
9+
if slug.start_with?('book/appendix')
10+
return name ? name.content : 'Appendix'
11+
end
12+
13+
ch1 = slug[/ch(\d+)-(\d+)/, 1] || '00'
14+
ch2 = slug[/ch(\d+)-(\d+)/, 2] || '00'
1015
name ? "#{ch1}.#{ch2}. #{name.content}" : 'Introduction'
11-
elsif slug == 'error-index'
16+
elsif slug.start_with?('reference')
17+
at_css('main h1').content
18+
elsif slug == 'error_codes/error-index'
1219
'Compiler Errors'
20+
elsif slug.start_with?('error_codes')
21+
slug.split('/').last.upcase
1322
else
1423
at_css('main h1').at_css('button')&.remove
1524
name = at_css('main h1').content.remove(/\A.+\s/).remove('⎘')
@@ -26,7 +35,7 @@ def get_type
2635
'Guide'
2736
elsif slug.start_with?('reference')
2837
'Reference'
29-
elsif slug == 'error-index'
38+
elsif slug.start_with?('error_codes')
3039
'Compiler Errors'
3140
else
3241
path = name.split('::')
@@ -40,12 +49,8 @@ def get_type
4049
end
4150

4251
def additional_entries
43-
if slug.start_with?('book') || slug.start_with?('reference')
52+
if slug.start_with?('book') || slug.start_with?('reference') || slug.start_with?('error_codes')
4453
[]
45-
elsif slug == 'error-index'
46-
css('.error-described h2.section-header').each_with_object [] do |node, entries|
47-
entries << [node.content, node['id']] unless node.content.include?('Note:')
48-
end
4954
else
5055
css('.method')
5156
.each_with_object({}) { |node, entries|

lib/docs/scrapers/rust.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Rust < UrlScraper
99
self.initial_paths = %w(
1010
reference/introduction.html
1111
std/index.html
12-
error-index.html)
12+
error_codes/error-index.html)
1313
self.links = {
1414
home: 'https://www.rust-lang.org/',
1515
code: 'https://github.com/rust-lang/rust'
@@ -21,7 +21,8 @@ class Rust < UrlScraper
2121
/\Abook\//,
2222
/\Areference\//,
2323
/\Acollections\//,
24-
/\Astd\// ]
24+
/\Astd\//,
25+
/\Aerror_codes\//, ]
2526

2627
options[:skip] = %w(book/README.html book/ffi.html)
2728
options[:skip_patterns] = [/(?<!\.html)\z/, /\/print\.html/, /\Abook\/second-edition\//]

0 commit comments

Comments
 (0)