Rewrite links by generating scraper :replace_paths from entries filter

pull/1547/head
Cimbali 4 years ago
parent 42731d6407
commit 005db388ce

@ -4,14 +4,17 @@ module Docs
PKG_INDEX_ENTRIES = Hash.new [] PKG_INDEX_ENTRIES = Hash.new []
def initialize(*) def call
super
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

@ -29,14 +29,12 @@ module Docs
/\.pdf$/ /\.pdf$/
] ]
## We want to fix links like so but only if the targets dont exist, options[:replace_paths] = {
## as these target packages or keywords that do not have their own file, ## We want to fix links like so but only if the targets dont exist:
## but exist on another page, and we properly record it. # '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
#options[:fix_urls] = ->(url) do ## are generated in the entries filter from 00Index.html files
# 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[:skip] = %w( options[:skip] = %w(
doc/html/packages-head-utf8.html doc/html/packages-head-utf8.html

Loading…
Cancel
Save