forked from rvm/rvm-site
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal_links.rb
More file actions
57 lines (48 loc) · 1.42 KB
/
external_links.rb
File metadata and controls
57 lines (48 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# require "typhoeus"
# Nanoc::Extra::Checking::Checks.send(:remove_const, :ExternalLinks)
# module Nanoc::Extra::Checking::Checks
# class ExternalLinks < Nanoc::Extra::Checking::Check
# identifiers :external_links, :elinks
# @count = 4
# class << self
# attr_accessor :count
# end
# def run
# hrefs =
# Nanoc::Extra::LinkCollector.new(
# self.output_filenames.select { |f|
# File.extname(f) == ".html"
# }, :external
# ).filenames_per_href
# list = hrefs.keys.select { |u| u =~ %r!https?://! }
# self.find_invalid(list).each do |l|
# filenames = hrefs[l]
# filenames.map do |f|
# self.add_issue("#{l} is broken, fix it", subject: f)
# end
# end
# end
# def find_invalid(hrefs)
# self.class.count.times do |i|
# hydra = Typhoeus::Hydra.new(max_concurrency: 20)
# hrefs.each do |l|
# hydra.queue(
# req =
# Typhoeus::Request.new(
# l, method: :head, followlocation: true)
# )
# req.on_complete do |r|
# if [200, 301, 302].include?(r.response_code)
# hrefs.delete(l)
# end
# end
# end
# hydra.run
# if i < self.class.count
# (hrefs.empty?) ? break : sleep(i * 5)
# end
# end
# hrefs
# end
# end
# end