浏览代码

Rewrite links by generating scraper :replace_paths from entries filter

Cimbali 4 年之前
父节点
当前提交
005db388ce
共有 2 个文件被更改,包括 12 次插入11 次删除
  1. 6 3
      lib/docs/filters/r/entries.rb
  2. 6 8
      lib/docs/scrapers/r.rb

+ 6 - 3
lib/docs/filters/r/entries.rb

@@ -4,14 +4,17 @@ module Docs
 
 
       PKG_INDEX_ENTRIES = Hash.new []
       PKG_INDEX_ENTRIES = Hash.new []
 
 
-      def initialize(*)
-        super
-
+      def call
         if slug_parts[-1] == '00Index'
         if slug_parts[-1] == '00Index'
+          dir = File.dirname(result[:subpath])
           css('tr a').each do |link|
           css('tr a').each do |link|
             PKG_INDEX_ENTRIES[link['href']] += [link.text]
             PKG_INDEX_ENTRIES[link['href']] += [link.text]
+            next if link['href'] == link.text
+            context[:replace_paths][File.join(dir, "#{link.text}.html")] = File.join(dir, "#{link['href']}.html")
           end
           end
         end
         end
+
+        super
       end
       end
 
 
       def slug_parts
       def slug_parts

+ 6 - 8
lib/docs/scrapers/r.rb

@@ -29,14 +29,12 @@ module Docs
       /\.pdf$/
       /\.pdf$/
     ]
     ]
 
 
-    ## We want to fix links like so − but only if the targets don’t exist,
-    ## as these target packages or keywords that do not have their own file,
-    ## but exist on another page, and we properly record it.
-    #
-    #options[:fix_urls] = ->(url) do
-    #  url.sub!(%r'/library/([^/]+)/doc/index.html$') { |m| "/r-#{$1.parameterize.downcase}/" }
-    #  url.sub!(%r'/library/([^/]+)/html/([^/]+).html$') { |m| "/library/#{$1.parameterize.downcase}/html/#{$2.parameterize.downcase}" }
-    #end
+    options[:replace_paths] = {
+    ## We want to fix links like so − but only if the targets don’t exist:
+    #  'library/MASS/html/cov.mve.html' => 'library/MASS/html/cov.rob.html'
+    ## Paths for target packages or keywords that do not have their own file
+    ## are generated in the entries filter from 00Index.html files
+    }
 
 
     options[:skip] = %w(
     options[:skip] = %w(
       doc/html/packages-head-utf8.html
       doc/html/packages-head-utf8.html