History

Rewrite links by generating scraper :replace_paths from entries filter

Cimbali committed 5 years ago

Commit 005db381 parent 42731d62 files · +12 −11Browse files

Unified · Split

2 files
  1. lib/docs/filters/r/entries.rb +6 −3
  2. lib/docs/scrapers/r.rb +6 −8
lib/docs/filters/r/entries.rb+6−3
@@ -4,14 +4,17 @@ module Docs · 3 unmodified lines
44
55 PKG_INDEX_ENTRIES = Hash.new []
66
7− def initialize(*)
8− super
9−
7+ def call
108 if slug_parts[-1] == '00Index'
9+ dir = File.dirname(result[:subpath])
1110 css('tr a').each do |link|
1211 PKG_INDEX_ENTRIES[link['href']] += [link.text]
12+ next if link['href'] == link.text
13+ context[:replace_paths][File.join(dir, "#{link.text}.html")] = File.join(dir, "#{link['href']}.html")
1314 end
1415 end
16+
17+ super
1518 end
1619
1720 def slug_parts
lib/docs/scrapers/r.rb+6−8
@@ -29,14 +29,12 @@ module Docs · 28 unmodified lines
2929 /\.pdf$/
3030 ]
3131
32− ## We want to fix links like so − but only if the targets don’t exist,
33− ## as these target packages or keywords that do not have their own file,
34− ## but exist on another page, and we properly record it.
35− #
36− #options[:fix_urls] = ->(url) do
37− # url.sub!(%r'/library/([^/]+)/doc/index.html$') { |m| "/r-#{$1.parameterize.downcase}/" }
38− # url.sub!(%r'/library/([^/]+)/html/([^/]+).html$') { |m| "/library/#{$1.parameterize.downcase}/html/#{$2.parameterize.downcase}" }
39− #end
32+ options[:replace_paths] = {
33+ ## We want to fix links like so − but only if the targets don’t exist:
34+ # 'library/MASS/html/cov.mve.html' => 'library/MASS/html/cov.rob.html'
35+ ## Paths for target packages or keywords that do not have their own file
36+ ## are generated in the entries filter from 00Index.html files
37+ }
4038
4139 options[:skip] = %w(
4240 doc/html/packages-head-utf8.html