Skip to content

Commit ba399d9

Browse files
authored
Merge pull request #21 from hahwul/dev
Release 1.3.6
2 parents e711004 + e5aa2c0 commit ba399d9

File tree

7 files changed

+102
-30
lines changed

7 files changed

+102
-30
lines changed

.rubocop.yml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,43 @@ AllCops:
55
- 'bin/*'
66
- '*.gemspec'
77
- 'Gemfile*'
8+
SuggestExtensions: false
9+
810
Style/MutableConstant:
9-
Enabled: false
11+
Enabled: false
12+
13+
Style/Documentation:
14+
Exclude:
15+
- 'lib/deadfinder.rb'
16+
- 'lib/deadfinder/logger.rb'
17+
- 'lib/deadfinder/utils.rb'
18+
19+
Metrics/AbcSize:
20+
Exclude:
21+
- 'lib/deadfinder.rb'
22+
- 'lib/deadfinder/utils.rb'
23+
24+
Metrics/CyclomaticComplexity:
25+
Exclude:
26+
- 'lib/deadfinder.rb'
27+
28+
Metrics/MethodLength:
29+
Exclude:
30+
- 'lib/deadfinder.rb'
31+
- 'lib/deadfinder/utils.rb'
32+
33+
Metrics/PerceivedComplexity:
34+
Exclude:
35+
- 'lib/deadfinder.rb'
36+
37+
Lint/SuppressedException:
38+
Exclude:
39+
- 'lib/deadfinder.rb'
40+
41+
Security/Open:
42+
Exclude:
43+
- 'lib/deadfinder.rb'
44+
45+
Metrics/BlockLength:
46+
Exclude:
47+
- 'spec/utils_spec.rb'

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Dead link (broken link) means a link within a web page that cannot be connected. These links can have a negative impact to SEO and Security. This tool makes it easy to identify and modify.
44

5-
![](https://user-images.githubusercontent.com/13212227/192243070-0c960680-ae08-4f30-8cf9-0844eca7c5ea.png)
5+
![](https://github.com/user-attachments/assets/92129de9-90c6-41e0-a424-883fe30858f6)
66

77
## Installation
88
### Install with Gem
@@ -34,7 +34,7 @@ deadfinder sitemap https://www.hahwul.com/sitemap.xml
3434
```yml
3535
steps:
3636
- name: Run DeadFinder
37-
uses: hahwul/[email protected].5
37+
uses: hahwul/[email protected].6
3838
id: broken-link
3939
with:
4040
command: sitemap
@@ -49,7 +49,7 @@ steps:
4949
require 'deadfinder'
5050

5151
app = DeadFinderRunner.new
52-
options = {}
52+
options = app.default_options
5353
options['concurrency'] = 30
5454

5555
app.run('https://www.hahwul.com/2022/09/30/deadfinder/', options)
@@ -67,12 +67,14 @@ Commands:
6767
deadfinder version # Show version.
6868
6969
Options:
70-
c, [--concurrency=N] # Number of concurrncy
71-
# Default: 20
72-
t, [--timeout=N] # Timeout in seconds
73-
# Default: 10
74-
o, [--output=OUTPUT] # File to write JSON result
75-
H, [--headers=one two three] # Custom HTTP headers to send with request
70+
-c, [--concurrency=N] # Number of concurrency
71+
# Default: 50
72+
-t, [--timeout=N] # Timeout in seconds
73+
# Default: 10
74+
-o, [--output=OUTPUT] # File to write JSON result
75+
-H, [--headers=one two three] # Custom HTTP headers to send with request
76+
-s, [--silent], [--no-silent], [--skip-silent] # Silent mode
77+
# Default: false
7678
```
7779

7880
## Modes

deadfinder.gemspec

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ Gem::Specification.new do |s|
1313
s.files = ['lib/deadfinder.rb', 'lib/deadfinder/utils.rb', 'lib/deadfinder/logger.rb', 'lib/deadfinder/version.rb']
1414
s.metadata['rubygems_mfa_required'] = 'true'
1515
s.metadata['source_code_uri'] = 'https://github.com/hahwul/deadfinder'
16-
s.add_runtime_dependency 'colorize', '~> 0.8.0'
17-
s.add_runtime_dependency 'concurrent-ruby-edge', '~> 0.6.0'
18-
s.add_runtime_dependency 'json', '~> 2.6.0'
19-
s.add_runtime_dependency 'nokogiri', '~> 1.13.0'
20-
s.add_runtime_dependency 'open-uri', '~> 0.2.0'
21-
s.add_runtime_dependency 'set', '~> 1.0.0'
22-
s.add_runtime_dependency 'sitemap-parser', '~> 0.5.0'
23-
s.add_runtime_dependency 'thor', '~> 1.2.0'
16+
s.add_runtime_dependency 'colorize', '>= 0.8.0'
17+
s.add_runtime_dependency 'concurrent-ruby-edge', '>= 0.6.0'
18+
s.add_runtime_dependency 'json', '>= 2.6.0'
19+
s.add_runtime_dependency 'nokogiri', '>= 1.13.0'
20+
s.add_runtime_dependency 'open-uri', '>= 0.2.0'
21+
s.add_runtime_dependency 'set', '>= 1.0.0'
22+
s.add_runtime_dependency 'sitemap-parser', '>= 0.5.0'
23+
s.add_runtime_dependency 'thor', '>= 1.2.0'
2424
end

github-action/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ghcr.io/hahwul/deadfinder:1.3.5
1+
FROM ghcr.io/hahwul/deadfinder:1.3.6
22
COPY entrypoint.sh /entrypoint.sh
33
RUN chmod 755 /entrypoint.sh
44
ENTRYPOINT ["/entrypoint.sh"]

lib/deadfinder.rb

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,18 @@
1818
Output = Concurrent::Map.new
1919

2020
class DeadFinderRunner
21+
def default_options
22+
{
23+
'concurrency' => 50,
24+
'timeout' => 10,
25+
'output' => '',
26+
'headers' => [],
27+
'silent' => true
28+
}
29+
end
30+
2131
def run(target, options)
32+
Logger.set_silent if options['silent']
2233
headers = options['headers'].each_with_object({}) do |header, hash|
2334
kv = header.split(': ')
2435
hash[kv[0]] = kv[1]
@@ -96,35 +107,49 @@ def extract_links(page)
96107
end
97108

98109
def run_pipe(options)
110+
Logger.set_silent if options['silent']
111+
112+
Logger.info 'Reading from STDIN'
99113
app = DeadFinderRunner.new
100114
while $stdin.gets
101115
target = $LAST_READ_LINE.chomp
116+
Logger.target "Checking: #{target}"
102117
app.run target, options
103118
end
104119
gen_output(options)
105120
end
106121

107122
def run_file(filename, options)
123+
Logger.set_silent if options['silent']
124+
125+
Logger.info "Reading: #{filename}"
108126
app = DeadFinderRunner.new
109127
File.foreach(filename) do |line|
110128
target = line.chomp
129+
Logger.target "Checking: #{target}"
111130
app.run target, options
112131
end
113132
gen_output(options)
114133
end
115134

116135
def run_url(url, options)
136+
Logger.set_silent if options['silent']
137+
138+
Logger.target "Checking: #{url}"
117139
app = DeadFinderRunner.new
118140
app.run url, options
119141
gen_output(options)
120142
end
121143

122144
def run_sitemap(sitemap_url, options)
145+
Logger.set_silent if options['silent']
146+
Logger.info "Parsing sitemap: #{sitemap_url}"
123147
app = DeadFinderRunner.new
124148
base_uri = URI(sitemap_url)
125149
sitemap = SitemapParser.new sitemap_url, { recurse: true }
126150
sitemap.to_a.each do |url|
127151
turl = generate_url url, base_uri
152+
Logger.target "Checking: #{turl}"
128153
app.run turl, options
129154
end
130155
gen_output(options)
@@ -139,28 +164,25 @@ class DeadFinder < Thor
139164
class_option :timeout, aliases: :t, default: 10, type: :numeric, desc: 'Timeout in seconds'
140165
class_option :output, aliases: :o, default: '', type: :string, desc: 'File to write JSON result'
141166
class_option :headers, aliases: :H, default: [], type: :array, desc: 'Custom HTTP headers to send with request'
167+
class_option :silent, aliases: :s, default: false, type: :boolean, desc: 'Silent mode'
142168

143169
desc 'pipe', 'Scan the URLs from STDIN. (e.g cat urls.txt | deadfinder pipe)'
144170
def pipe
145-
Logger.info 'Pipe mode'
146171
run_pipe options
147172
end
148173

149174
desc 'file <FILE>', 'Scan the URLs from File. (e.g deadfinder file urls.txt)'
150175
def file(filename)
151-
Logger.info 'File mode'
152176
run_file filename, options
153177
end
154178

155179
desc 'url <URL>', 'Scan the Single URL.'
156180
def url(url)
157-
Logger.info 'Single URL mode'
158181
run_url url, options
159182
end
160183

161184
desc 'sitemap <SITEMAP-URL>', 'Scan the URLs from sitemap.'
162185
def sitemap(sitemap)
163-
Logger.info 'Sitemap mode'
164186
run_sitemap sitemap, options
165187
end
166188

lib/deadfinder/logger.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,37 @@
33
require 'colorize'
44

55
class Logger
6+
@silent = false
7+
8+
def self.set_silent
9+
@silent = true
10+
end
11+
12+
def self.silent?
13+
@silent
14+
end
15+
616
def self.info(text)
7-
puts 'ℹ '.colorize(:blue) + text.to_s.colorize(:light_blue)
17+
puts 'ℹ '.colorize(:blue) + text.to_s.colorize(:light_blue) unless silent?
818
end
919

1020
def self.error(text)
11-
puts '⚠︎ '.colorize(:red) + text.to_s
21+
puts '⚠︎ '.colorize(:red) + text.to_s unless silent?
1222
end
1323

1424
def self.target(text)
15-
puts '► '.colorize(:green) + text.to_s.colorize(:light_green)
25+
puts '► '.colorize(:green) + text.to_s.colorize(:light_green) unless silent?
1626
end
1727

1828
def self.sub_info(text)
19-
puts ' ● '.colorize(:blue) + text.to_s.colorize(:light_blue)
29+
puts ' ● '.colorize(:blue) + text.to_s.colorize(:light_blue) unless silent?
2030
end
2131

2232
def self.sub_done(text)
23-
puts ' ✓ '.colorize(:blue) + text.to_s.colorize(:light_blue)
33+
puts ' ✓ '.colorize(:blue) + text.to_s.colorize(:light_blue) unless silent?
2434
end
2535

2636
def self.found(text)
27-
puts " ✘ #{text}".colorize(:red)
37+
puts " ✘ #{text}".colorize(:red) unless silent?
2838
end
2939
end

lib/deadfinder/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# frozen_string_literal: true
22

3-
VERSION = '1.3.5'
3+
VERSION = '1.3.6'

0 commit comments

Comments
 (0)