jekyll-url-metadata 1.0.1 → 1.0.3
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 +4 -4
- data/jekyll-url-metadata.gemspec +2 -1
- data/lib/jekyll-url-metadata/main.rb +62 -36
- data/lib/jekyll-url-metadata/version.rb +1 -1
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07f8f6a1a9019b147240b9c24ccdf325351a438430401937ee09586786318688
|
4
|
+
data.tar.gz: 8629259c9beed38570135fa3eebbadcd5b708e76bb33154fbae89fc54f95ddef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b335e1dadb10c5cc7bb228e692b6f3aba28005b720e47cbf5c34033d5713194b8e8c603c607059285bae213bfc70d8736197f8dca2f30fdc5480347858d01cb
|
7
|
+
data.tar.gz: 4dc6c36426d180d2e83ed8eefe75bfca97687c342651bdc2a09235a33a8c5d986b768d82a2be0d7d88c67db16bf544f63cee0074744fa8648a9f56864fcf6f0d
|
data/jekyll-url-metadata.gemspec
CHANGED
@@ -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
|
-
|
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
|
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,23 +26,23 @@ 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
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
|
57
41
|
hash = Hash.new
|
58
42
|
|
59
|
-
# add <title> tag's value to the hash
|
60
|
-
doc.search("title").each do | title |
|
61
|
-
|
43
|
+
# add first <title> tag's value to the hash
|
44
|
+
doc.search("head title").each do | title |
|
45
|
+
break if exists(hash["title"])
|
62
46
|
hash["title"] = title.content
|
63
47
|
end
|
64
48
|
|
@@ -86,8 +70,46 @@ module Jekyll
|
|
86
70
|
hash
|
87
71
|
end
|
88
72
|
|
89
|
-
def
|
90
|
-
|
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
|
|
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.
|
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-07
|
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:
|