deadfinder 1.0.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3a2e86be2607ea1af0d52ca1ed57055869cb457d58aa0b3773154d8de15f7a08
4
- data.tar.gz: ffb4fa247f7f388c9e5f71144f8b9728118627feead5159380bac65d2af4420f
3
+ metadata.gz: 248abe3bb3c321a29cb164930132c0a61ad9e3f7987a8cfb863eebe614d0350f
4
+ data.tar.gz: bbd932e255500d98dbd2171d5fe3fb66a820846bb5801f4b6b1b1b74905675e7
5
5
  SHA512:
6
- metadata.gz: 237f99c06741f5b509af6ede98be469e20d9a60f7be2a5d615568eb7707686a40998ee49ce41143cb6af72beb3fe181ad9cebaed114d11f7a8e9408b3fd54fee
7
- data.tar.gz: 8cfd465a45ae8b4646e82810e4aa595c809a44a11107c0845f06e11a2eddeee394bb8e01b53a412f33b13bc05aaca49bd0a890ed6a702138d3b7b327634712f1
6
+ metadata.gz: 4b722245eafc6373f2776db13377cbb391ab9a4c4cffb7b226e206fb8c8f7a58d1474345a7fef41b7cc14cc350ef3549db95f3359b7df7b3bcd43d0d3d580dac
7
+ data.tar.gz: 5b9706ea35279e5f7c881d1839bb030ab73fb412a474a3cc9ac01837a256ff121b17154246a9ef6173a7410f29e611f52cf66dff9eff7a14c7176b27a9ab00c1
@@ -2,20 +2,20 @@
2
2
 
3
3
  require 'colorize'
4
4
 
5
- class Logger
6
- def self.info text
7
- puts "".colorize(:blue) + "#{text}".colorize(:light_blue)
8
- end
5
+ class Logger
6
+ def self.info(text)
7
+ puts ''.colorize(:blue) + text.to_s.colorize(:light_blue)
8
+ end
9
9
 
10
- def self.target text
11
- puts "".colorize(:green) + "#{text}".colorize(:light_green)
12
- end
10
+ def self.target(text)
11
+ puts ''.colorize(:green) + text.to_s.colorize(:light_green)
12
+ end
13
13
 
14
- def self.sub_info text
15
- puts "".colorize(:blue) + "#{text}".colorize(:light_blue)
16
- end
14
+ def self.sub_info(text)
15
+ puts ''.colorize(:blue) + text.to_s.colorize(:light_blue)
16
+ end
17
17
 
18
- def self.found text
19
- puts " ✘ #{text}".colorize(:red)
20
- end
21
- end
18
+ def self.found(text)
19
+ puts " ✘ #{text}".colorize(:red)
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ VERSION = '1.1.1'
data/lib/deadfinder.rb CHANGED
@@ -6,13 +6,14 @@ require 'open-uri'
6
6
  require 'nokogiri'
7
7
  require 'deadfinder/utils'
8
8
  require 'deadfinder/logger'
9
+ require 'deadfinder/version'
9
10
  require 'concurrent-edge'
10
11
  require 'sitemap-parser'
11
12
 
12
13
  Channel = Concurrent::Channel
13
14
 
14
15
  class DeadFinderRunner
15
- def run(target)
16
+ def run(target, options)
16
17
  page = Nokogiri::HTML(URI.open(target))
17
18
  nodeset = page.css('a')
18
19
  link_a = nodeset.map { |element| element['href'] }.compact
@@ -22,7 +23,7 @@ class DeadFinderRunner
22
23
  jobs = Channel.new(buffer: :buffered, capacity: 100)
23
24
  results = Channel.new(buffer: :buffered, capacity: 100)
24
25
 
25
- (1..20).each do |w|
26
+ (1..options['concurrency']).each do |w|
26
27
  Channel.go { worker(w, jobs, results) }
27
28
  end
28
29
 
@@ -32,78 +33,82 @@ class DeadFinderRunner
32
33
  end
33
34
  jobs.close
34
35
 
35
- (1..link_a.uniq.length).each do
36
+ (1..link_a.uniq.length).each do
36
37
  ~results
37
38
  end
38
39
  Logger.sub_info 'Done'
39
40
  end
40
41
 
41
- def worker(id, jobs, results)
42
+ def worker(_id, jobs, results)
42
43
  jobs.each do |j|
43
44
  begin
44
45
  URI.open(j)
45
- rescue => exception
46
- if exception.to_s.include? '404 Not Found'
47
- Logger.found "[#{exception}] #{j}"
48
- end
49
- end
46
+ rescue StandardError => e
47
+ Logger.found "[#{e}] #{j}" if e.to_s.include? '404 Not Found'
48
+ end
50
49
  results << j
51
50
  end
52
51
  end
53
52
  end
54
53
 
55
- def run_pipe
54
+ def run_pipe(options)
56
55
  app = DeadFinderRunner.new
57
56
  while $stdin.gets
58
57
  target = $LAST_READ_LINE.gsub("\n", '')
59
- app.run target
58
+ app.run target, options
60
59
  end
61
60
  end
62
61
 
63
- def run_file(filename)
62
+ def run_file(filename, options)
64
63
  app = DeadFinderRunner.new
65
64
  File.open(filename).each do |line|
66
65
  target = line.gsub("\n", '')
67
- app.run target
66
+ app.run target, options
68
67
  end
69
68
  end
70
69
 
71
- def run_url(url)
70
+ def run_url(url, options)
72
71
  app = DeadFinderRunner.new
73
- app.run url
72
+ app.run url, options
74
73
  end
75
74
 
76
- def run_sitemap(sitemap_url)
75
+ def run_sitemap(sitemap_url, options)
77
76
  app = DeadFinderRunner.new
78
- sitemap = SitemapParser.new sitemap_url, {recurse: true}
77
+ sitemap = SitemapParser.new sitemap_url, { recurse: true }
79
78
  sitemap.to_a.each do |url|
80
- app.run url
79
+ app.run url, options
81
80
  end
82
81
  end
83
82
 
84
83
  class DeadFinder < Thor
85
-
84
+ class_option :concurrency, aliases: :c, default: 20, type: :numeric
85
+
86
86
  desc 'pipe', 'Scan the URLs from STDIN. (e.g cat urls.txt | deadfinder pipe)'
87
87
  def pipe
88
88
  Logger.info 'Pipe mode'
89
- run_pipe
89
+ run_pipe options
90
90
  end
91
91
 
92
92
  desc 'file', 'Scan the URLs from File. (e.g deadfinder file urls.txt)'
93
93
  def file(filename)
94
94
  Logger.info 'File mode'
95
- run_file filename
95
+ run_file filename, options
96
96
  end
97
97
 
98
98
  desc 'url', 'Scan the Single URL.'
99
99
  def url(url)
100
100
  Logger.info 'Single URL mode'
101
- run_url url
101
+ run_url url, options
102
102
  end
103
103
 
104
104
  desc 'sitemap', 'Scan the URLs from sitemap.'
105
105
  def sitemap(sitemap)
106
106
  Logger.info 'Sitemap mode'
107
- run_sitemap sitemap
107
+ run_sitemap sitemap, options
108
+ end
109
+
110
+ desc 'version', 'Show version.'
111
+ def version
112
+ Logger.info "deadfinder #{VERSION}"
108
113
  end
109
114
  end
metadata CHANGED
@@ -1,16 +1,102 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deadfinder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - hahwul
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-24 00:00:00.000000000 Z
12
- dependencies: []
13
- description: Find dead-links (broken links)
11
+ date: 2022-09-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: concurrent-ruby-edge
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: nokogiri
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.13.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.13.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: open-uri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: sitemap-parser
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.5.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.5.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: thor
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.2.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.2.0
97
+ description: Dead link (broken link) means a link within a web page that cannot be
98
+ connected. These links can have a security negative impact with SEO. This tool makes
99
+ it easy to identify and modify.
14
100
  email: hahwul@gmail.com
15
101
  executables:
16
102
  - deadfinder
@@ -21,11 +107,13 @@ files:
21
107
  - lib/deadfinder.rb
22
108
  - lib/deadfinder/logger.rb
23
109
  - lib/deadfinder/utils.rb
110
+ - lib/deadfinder/version.rb
24
111
  homepage: https://www.hahwul.com
25
112
  licenses:
26
113
  - MIT
27
114
  metadata:
28
115
  rubygems_mfa_required: 'true'
116
+ source_code_uri: https://github.com/hahwul/deadfinder
29
117
  post_install_message:
30
118
  rdoc_options: []
31
119
  require_paths: