1
0
Эх сурвалжийг харах

Update rustc error codes URL, and improve Rust logic for page names

Fixes freeCodeCamp/devdocs#2568
Calum Smith 3 сар өмнө
parent
commit
e1e9f8bdd4

+ 2 - 2
lib/docs/filters/rust/clean_html.rb

@@ -4,9 +4,9 @@ module Docs
   class Rust
     class CleanHtmlFilter < Filter
       def call
-        if slug.start_with?('book') ||  slug.start_with?('reference')
+        if slug.start_with?('book') ||  slug.start_with?('reference') || slug.start_with?('error_codes')
           @doc = at_css('#content main')
-        elsif slug == 'error-index'
+        elsif slug.start_with?('error_codes')
           css('.error-undescribed').remove
 
           css('.error-described').each do |node|

+ 16 - 11
lib/docs/filters/rust/entries.rb

@@ -3,13 +3,22 @@ module Docs
     class EntriesFilter < Docs::EntriesFilter
 
       def get_name
-        if slug.start_with?('book') || slug.start_with?('reference')
-          name = at_css("h2", "h1")
-          ch1 = slug[/ch(\d+)-(\d+)/, 1]
-          ch2 = slug[/ch(\d+)-(\d+)/, 2]
+        if slug.start_with?('book')
+          name = at_css('main h1', 'main h2')
+
+          if slug.start_with?('book/appendix')
+            return name ? name.content : 'Appendix'
+          end
+
+          ch1 = slug[/ch(\d+)-(\d+)/, 1] || '00'
+          ch2 = slug[/ch(\d+)-(\d+)/, 2] || '00'
           name ? "#{ch1}.#{ch2}. #{name.content}" : 'Introduction'
-        elsif slug == 'error-index'
+        elsif slug.start_with?('reference')
+          at_css('main h1').content
+        elsif slug == 'error_codes/error-index'
           'Compiler Errors'
+        elsif slug.start_with?('error_codes')
+          slug.split('/').last.upcase
         else
           at_css('main h1').at_css('button')&.remove
           name = at_css('main h1').content.remove(/\A.+\s/).remove('⎘')
@@ -26,7 +35,7 @@ module Docs
           'Guide'
         elsif slug.start_with?('reference')
           'Reference'
-        elsif slug == 'error-index'
+        elsif slug.start_with?('error_codes')
           'Compiler Errors'
         else
           path = name.split('::')
@@ -40,12 +49,8 @@ module Docs
       end
 
       def additional_entries
-        if slug.start_with?('book') || slug.start_with?('reference')
+        if slug.start_with?('book') || slug.start_with?('reference') || slug.start_with?('error_codes')
           []
-        elsif slug == 'error-index'
-          css('.error-described h2.section-header').each_with_object [] do |node, entries|
-            entries << [node.content, node['id']] unless node.content.include?('Note:')
-          end
         else
           css('.method')
             .each_with_object({}) { |node, entries|

+ 3 - 2
lib/docs/scrapers/rust.rb

@@ -9,7 +9,7 @@ module Docs
     self.initial_paths = %w(
       reference/introduction.html
       std/index.html
-      error-index.html)
+      error_codes/error-index.html)
     self.links = {
       home: 'https://www.rust-lang.org/',
       code: 'https://github.com/rust-lang/rust'
@@ -21,7 +21,8 @@ module Docs
       /\Abook\//,
       /\Areference\//,
       /\Acollections\//,
-      /\Astd\// ]
+      /\Astd\//,
+      /\Aerror_codes\//, ]
 
     options[:skip] = %w(book/README.html book/ffi.html)
     options[:skip_patterns] = [/(?<!\.html)\z/, /\/print\.html/, /\Abook\/second-edition\//]