cloudfront-link-checker 0.0.2
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 +7 -0
- data/lib/cloudfront_link_checker.rb +32 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 56a365f7821a0c9b518a4468248892a5631f7fa2297896943f6484f85a24a9c7
|
4
|
+
data.tar.gz: f92974ad15a2c72061a89aa512ccf2feee4fd44863bb2a7e6fcf2560a0e12667
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 43c71c2483da1f81715fa8cb3651f8bd82a3c1ef359d5361e6bfb6541f178ce669b3381f789a7cb151d9238917b2a462b8a69e22f1e6c4de50443e3af300cdfd
|
7
|
+
data.tar.gz: 33f5425b1baaf3ea4712936e8312fca895c3c7a668c887d8862f61c4558ec2c574afa64cce6d5b0a33c1a9afed84f6b558161fbdaa57ba09530f94b33460b366
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class CloudfrontLinkChecker
|
2
|
+
def self.scan_files(directory_to_scan)
|
3
|
+
Dir.chdir(directory_to_scan) do
|
4
|
+
system('pwd')
|
5
|
+
htmlfiles = File.join("**", "*.html")
|
6
|
+
files = Dir.glob(htmlfiles)
|
7
|
+
bad_files = {}
|
8
|
+
files.each do |file|
|
9
|
+
bad_links = []
|
10
|
+
results = File.readlines(file, :encoding => "UTF-8").grep /href="(.*)"/i
|
11
|
+
results.each do |line|
|
12
|
+
links = line.match(/href=(["'])(.*?)\1/i)[2]
|
13
|
+
exclude_start_with_list = ["https:", "#", "mailto:", "tel:"]
|
14
|
+
exclude_endings = [".ico", ".png", ".css", "/#contact-us", ".pdf"]
|
15
|
+
if !links.start_with?(*exclude_start_with_list) && !links.end_with?(*exclude_endings)
|
16
|
+
if !links.start_with?("/") || !links.end_with?("/")
|
17
|
+
bad_links.push(links)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
# Add the bad files to a map keyed of filename
|
22
|
+
if !bad_links.empty?
|
23
|
+
bad_files[file] = bad_links
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
if !bad_files.empty?
|
28
|
+
raise "Bad links discovered. Links need to start and end with forward-slashs to be served by CloudFront: #{bad_files}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cloudfront-link-checker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brandon Carlson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-06 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Little gem for validating URLs have the proper structure for CloudFront
|
14
|
+
email: bcarlso@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/cloudfront_link_checker.rb
|
20
|
+
homepage:
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.7.7
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Little gem for validating URLs have the proper structure for CloudFront
|
44
|
+
test_files: []
|