jekyll-url-metadata 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7cc9f88ea850dad060ca2bc836bdd131eef66684aa373048cdabd8246c16953d
4
- data.tar.gz: 8b93797dc82baa3a114ea8243dde0bc9489cb085d8dc62510a2ffd583433a019
3
+ metadata.gz: 07f8f6a1a9019b147240b9c24ccdf325351a438430401937ee09586786318688
4
+ data.tar.gz: 8629259c9beed38570135fa3eebbadcd5b708e76bb33154fbae89fc54f95ddef
5
5
  SHA512:
6
- metadata.gz: 15857ed5557ecb5fc3026561be968f64d98f4b39b55a9b3234b2c956b58b3434c570da016de87756911ce3d2d8c1ead5a525aacceff4c5810d60afaf9819d5ed
7
- data.tar.gz: 7213d51daac4c4037a279c07f818cafdfdfa60a31fac4c324e91ed643905cae1b86202bc29cce86dc355404e4b16ab8904e7d3e35bfb484b014d77f3284ab8d8
6
+ metadata.gz: 7b335e1dadb10c5cc7bb228e692b6f3aba28005b720e47cbf5c34033d5713194b8e8c603c607059285bae213bfc70d8736197f8dca2f30fdc5480347858d01cb
7
+ data.tar.gz: 4dc6c36426d180d2e83ed8eefe75bfca97687c342651bdc2a09235a33a8c5d986b768d82a2be0d7d88c67db16bf544f63cee0074744fa8648a9f56864fcf6f0d
@@ -24,5 +24,6 @@ Gem::Specification.new do |spec|
24
24
  # Dependencies
25
25
  spec.add_runtime_dependency "jekyll", ">= 3.0.0"
26
26
  spec.add_runtime_dependency "nokogiri", ">= 1.10.0"
27
-
27
+ spec.add_development_dependency "rake", "~> 13.0"
28
+ spec.add_development_dependency "minitest", "~> 5.14"
28
29
  end
@@ -5,8 +5,12 @@ module Jekyll
5
5
  module URLMetadata
6
6
 
7
7
  def url_config
8
- @@url_config ||= @context.registers[:site].config['url_metadata'].nil? ? {} :
9
- @context.registers[:site].config['url_metadata']
8
+ begin
9
+ @@url_config ||= @context.registers[:site].config['url_metadata'].nil? ? {} :
10
+ @context.registers[:site].config['url_metadata']
11
+ rescue
12
+ {}
13
+ end
10
14
  end
11
15
 
12
16
  def cache
@@ -14,27 +18,7 @@ module Jekyll
14
18
  end
15
19
 
16
20
  def metadata(input)
17
- if !input.is_a?(String)
18
- log("Expected input type \"String\". Got \"#{input.class}\".")
19
- return
20
- end
21
-
22
- if input.nil? || input == ""
23
- log("Empty input string.")
24
- return
25
- end
26
-
27
- if !url_config["open_timeout"].nil? && !url_config["open_timeout"].is_a?(Integer)
28
- log("Expected an \"Integer\" value for config \"open_timeout\". Got #{url_config["open_timeout"]}.")
29
-
30
- return
31
- end
32
-
33
- if !url_config["read_timeout"].nil? && !url_config["read_timeout"].is_a?(Integer)
34
- log("Expected an \"Integer\" value for config \"read_timeout\". Got #{url_config["read_timeout"]}.")
35
-
36
- return
37
- end
21
+ return if !is_input_valid(input) || !is_config_valid()
38
22
 
39
23
  # The getset() API implements a cache first strategy
40
24
  cache.getset(input) do
@@ -42,15 +26,15 @@ module Jekyll
42
26
  end
43
27
  end
44
28
 
45
- def generate_hashmap(input)
29
+ def generate_hashmap(input, testCase = false)
46
30
  # parse HTML from URL
47
- doc = Nokogiri::HTML(URI.open(input, {
48
- :open_timeout => url_config["open_timeout"].nil? ? 1 : url_config["open_timeout"],
49
- :read_timeout => url_config["read_timeout"].nil? ? 1 : url_config["read_timeout"]
50
- }))
51
-
52
- if !doc
53
- log("Failed to parse HTML from #{input}. Please double check for URL validity.")
31
+ begin
32
+ doc = Nokogiri::HTML(URI.open(input, {
33
+ :open_timeout => url_config["open_timeout"].nil? ? 1 : url_config["open_timeout"],
34
+ :read_timeout => url_config["read_timeout"].nil? ? 1 : url_config["read_timeout"]
35
+ }))
36
+ rescue
37
+ log("Failed to parse HTML from '#{input}'. Please double check for URL validity.") if !testCase
54
38
  return
55
39
  end
56
40
 
@@ -86,8 +70,46 @@ module Jekyll
86
70
  hash
87
71
  end
88
72
 
89
- def log(msg)
90
- Jekyll.logger.error "URL Metadata:", msg
73
+ def is_input_valid(input, testCase = false)
74
+ if !input.is_a?(String)
75
+ log("Expected input type 'String'. Got '#{input.class}'.") if !testCase
76
+
77
+ return false
78
+ end
79
+
80
+ if input.nil? || input == ""
81
+ log("Empty input string.") if !testCase
82
+
83
+ return false
84
+ end
85
+
86
+ begin
87
+ if URI.parse(input).kind_of?(URI::HTTP)
88
+ return true
89
+ else
90
+ log("'#{input}' does not seem to be a valid URL.") if !testCase
91
+ end
92
+ rescue
93
+ log("'#{input}' does not seem to be a valid URL.") if !testCase
94
+ end
95
+
96
+ false
97
+ end
98
+
99
+ def is_config_valid()
100
+ if !url_config["open_timeout"].nil? && !url_config["open_timeout"].is_a?(Integer)
101
+ log("Expected an 'Integer' value for config 'open_timeout'. Got '#{url_config["open_timeout"].class}'.")
102
+
103
+ return false
104
+ end
105
+
106
+ if !url_config["read_timeout"].nil? && !url_config["read_timeout"].is_a?(Integer)
107
+ log("Expected an 'Integer' value for config 'read_timeout'. Got '#{url_config["read_timeout"].class}'.")
108
+
109
+ return false
110
+ end
111
+
112
+ true
91
113
  end
92
114
 
93
115
  def exists(obj)
@@ -98,6 +120,10 @@ module Jekyll
98
120
  obj.get_attribute(attr)
99
121
  end
100
122
 
123
+ def log(msg)
124
+ Jekyll.logger.error "URL Metadata:", msg
125
+ end
126
+
101
127
  end # module Jekyll
102
128
  end # module URLMetadata
103
129
 
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module URLMetadata
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.3"
4
4
  end # module Jekyll
5
5
  end # module URLMetadata
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-url-metadata
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gourav Khunger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-01 00:00:00.000000000 Z
11
+ date: 2022-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.10.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.14'
41
69
  description: A plugin to expose meta data information from the head tag of a webapge
42
70
  to liquid variables just from its url string.
43
71
  email: