jekyll-url-metadata 1.0.2 → 1.0.4

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: 7cc9f88ea850dad060ca2bc836bdd131eef66684aa373048cdabd8246c16953d
4
- data.tar.gz: 8b93797dc82baa3a114ea8243dde0bc9489cb085d8dc62510a2ffd583433a019
3
+ metadata.gz: 3a4e00283a626aebd4b4b3f50efb40d8365e5b2c4b76a6dbb6865c63bfbc16bf
4
+ data.tar.gz: 4ca146d90db461cc10f3ab91d5e70165c1fbcdb2e7d17ceb98c6299ef0829526
5
5
  SHA512:
6
- metadata.gz: 15857ed5557ecb5fc3026561be968f64d98f4b39b55a9b3234b2c956b58b3434c570da016de87756911ce3d2d8c1ead5a525aacceff4c5810d60afaf9819d5ed
7
- data.tar.gz: 7213d51daac4c4037a279c07f818cafdfdfa60a31fac4c324e91ed643905cae1b86202bc29cce86dc355404e4b16ab8904e7d3e35bfb484b014d77f3284ab8d8
6
+ metadata.gz: 76e514cf41b909a6dff7c905e3dd2fa379d814d245f2300a750ede5e142ce8343c34aba16629ac1710f186745e5be2a83aca6b157a7b948afb4650a16ee98eb8
7
+ data.tar.gz: 9c036325a0c1bc2fd03f1421c83e5e426d37f9f5c9474a7a3a9b96da52a49aef703801ffacd85495d41488e6dcaa9aeae84605b8008ba652f6e7affb1be2c56c
@@ -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,43 +18,27 @@ 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
- # The getset() API implements a cache first strategy
40
- cache.getset(input) do
23
+ if Jekyll::VERSION.to_i >= 4
24
+ # The getset() API implements a cache first strategy
25
+ cache.getset(input) do
26
+ generate_hashmap(input)
27
+ end
28
+ else
41
29
  generate_hashmap(input)
42
30
  end
43
31
  end
44
32
 
45
- def generate_hashmap(input)
33
+ def generate_hashmap(input, testCase = false)
46
34
  # 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.")
35
+ begin
36
+ doc = Nokogiri::HTML(URI.open(input, {
37
+ :open_timeout => url_config["open_timeout"].nil? ? 1 : url_config["open_timeout"],
38
+ :read_timeout => url_config["read_timeout"].nil? ? 1 : url_config["read_timeout"]
39
+ }))
40
+ rescue
41
+ log("Failed to parse HTML from '#{input}'. Please double check for URL validity.") if !testCase
54
42
  return
55
43
  end
56
44
 
@@ -86,8 +74,46 @@ module Jekyll
86
74
  hash
87
75
  end
88
76
 
89
- def log(msg)
90
- Jekyll.logger.error "URL Metadata:", msg
77
+ def is_input_valid(input, testCase = false)
78
+ if !input.is_a?(String)
79
+ log("Expected input type 'String'. Got '#{input.class}'.") if !testCase
80
+
81
+ return false
82
+ end
83
+
84
+ if input.nil? || input == ""
85
+ log("Empty input string.") if !testCase
86
+
87
+ return false
88
+ end
89
+
90
+ begin
91
+ if URI.parse(input).kind_of?(URI::HTTP)
92
+ return true
93
+ else
94
+ log("'#{input}' does not seem to be a valid URL.") if !testCase
95
+ end
96
+ rescue
97
+ log("'#{input}' does not seem to be a valid URL.") if !testCase
98
+ end
99
+
100
+ false
101
+ end
102
+
103
+ def is_config_valid()
104
+ if !url_config["open_timeout"].nil? && !url_config["open_timeout"].is_a?(Integer)
105
+ log("Expected an 'Integer' value for config 'open_timeout'. Got '#{url_config["open_timeout"].class}'.")
106
+
107
+ return false
108
+ end
109
+
110
+ if !url_config["read_timeout"].nil? && !url_config["read_timeout"].is_a?(Integer)
111
+ log("Expected an 'Integer' value for config 'read_timeout'. Got '#{url_config["read_timeout"].class}'.")
112
+
113
+ return false
114
+ end
115
+
116
+ true
91
117
  end
92
118
 
93
119
  def exists(obj)
@@ -98,6 +124,10 @@ module Jekyll
98
124
  obj.get_attribute(attr)
99
125
  end
100
126
 
127
+ def log(msg)
128
+ Jekyll.logger.error "URL Metadata:", msg
129
+ end
130
+
101
131
  end # module Jekyll
102
132
  end # module URLMetadata
103
133
 
@@ -1,5 +1,5 @@
1
1
  module Jekyll
2
2
  module URLMetadata
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.4"
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.4
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: 2023-10-01 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:
@@ -70,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
98
  - !ruby/object:Gem::Version
71
99
  version: '0'
72
100
  requirements: []
73
- rubygems_version: 3.3.11
101
+ rubygems_version: 3.4.17
74
102
  signing_key:
75
103
  specification_version: 4
76
104
  summary: Extract all kind of meta data from a url string