jekyll-url-metadata 1.0.0
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/Gemfile +4 -0
- data/jekyll-url-metadata.gemspec +28 -0
- data/lib/jekyll-url-metadata/main.rb +71 -0
- data/lib/jekyll-url-metadata/version.rb +5 -0
- data/lib/jekyll-url-metadata.rb +7 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a6794509dbeaeeb5c084ff07122e29a3c40b1bf9e76f07c7d08fcd2d12df0bf2
|
4
|
+
data.tar.gz: 0e80ce37dff34867ed8b48cbb4c2cccfc74a8da83fb9c34cbe7d3d55eae7f143
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: efbf35177b2b7f3ae27b885575283d38f4b11ef9532a77da9bc45e3dfd579b34b44e424f728044a78b14b0a46ef560c12f2e1ab8198abc01397b985633c5d4e7
|
7
|
+
data.tar.gz: 2f851ad1e3c0a79868aae40f547d184a7fdf1b68edd97e3dc303c691a2fb5aa071b269fcc6b718fdd85211bbdd1716a992623b4fe19f6b81cc11a5fdf20cd13b
|
data/Gemfile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "jekyll-url-metadata/version"
|
5
|
+
require "date"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "jekyll-url-metadata"
|
9
|
+
spec.version = Jekyll::URLMetadata::VERSION
|
10
|
+
spec.platform = Gem::Platform::RUBY
|
11
|
+
spec.required_ruby_version = ">= 2.0.0" # Same as Jekyll
|
12
|
+
spec.date = DateTime.now.strftime("%Y-%m-%d")
|
13
|
+
spec.authors = ["Gourav Khunger"]
|
14
|
+
spec.email = ["gouravkhunger18@gmail.com"]
|
15
|
+
spec.homepage = "https://github.com/gouravkhunger/jekyll-url-metadata"
|
16
|
+
spec.license = "MIT"
|
17
|
+
|
18
|
+
spec.summary = "Extract all kind of meta data from a url string"
|
19
|
+
spec.description = "A plugin to expose meta data information from the head tag of a webapge to liquid variables just from its url string."
|
20
|
+
|
21
|
+
spec.files = Dir["*.gemspec", "Gemfile", "lib/**/*"]
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
# Dependencies
|
25
|
+
spec.add_runtime_dependency "jekyll", ">= 3.0.0"
|
26
|
+
spec.add_runtime_dependency "nokogiri", ">= 1.10.0"
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "open-uri"
|
2
|
+
require "nokogiri"
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
module URLMetadata
|
6
|
+
|
7
|
+
def metadata(input)
|
8
|
+
if !input.is_a?(String)
|
9
|
+
log("Expected input type \"String\". Got \"#{input.class}\".")
|
10
|
+
return
|
11
|
+
end
|
12
|
+
|
13
|
+
if input.nil? || input == ""
|
14
|
+
log("Empty input string.")
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
18
|
+
# parse HTML from URL
|
19
|
+
doc = Nokogiri::HTML(URI.open(input))
|
20
|
+
if !doc
|
21
|
+
log("Failed to parse HTML from #{input}. Please double check for URL validity.")
|
22
|
+
end
|
23
|
+
|
24
|
+
hash = Hash.new
|
25
|
+
|
26
|
+
# add <title> tag's value to the hash
|
27
|
+
doc.search("title").each do | title |
|
28
|
+
next if title.content == ""
|
29
|
+
hash["title"] = title.content
|
30
|
+
end
|
31
|
+
|
32
|
+
# add possible <meta> tag attribute's value to the hash
|
33
|
+
doc.search("meta").each do | meta |
|
34
|
+
name = get(meta, "name")
|
35
|
+
property = get(meta, "property")
|
36
|
+
charset = get(meta, "charset")
|
37
|
+
content = get(meta, "content")
|
38
|
+
|
39
|
+
if exists(name)
|
40
|
+
hash[name] = content
|
41
|
+
elsif exists(property)
|
42
|
+
hash[property] = content
|
43
|
+
elsif exists(charset)
|
44
|
+
hash["charset"] = charset
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# add possible <link> tag attribute's value to the hash
|
49
|
+
doc.search("link").each do | link |
|
50
|
+
hash[get(link, "rel")] = get(link, "href")
|
51
|
+
end
|
52
|
+
|
53
|
+
hash
|
54
|
+
end
|
55
|
+
|
56
|
+
def log(msg)
|
57
|
+
Jekyll.logger.error "URL Metadata:", msg
|
58
|
+
end
|
59
|
+
|
60
|
+
def exists(obj)
|
61
|
+
!obj.nil? && obj != ""
|
62
|
+
end
|
63
|
+
|
64
|
+
def get(obj, attr)
|
65
|
+
obj.get_attribute(attr)
|
66
|
+
end
|
67
|
+
|
68
|
+
end # module Jekyll
|
69
|
+
end # module URLMetadata
|
70
|
+
|
71
|
+
Liquid::Template.register_filter(Jekyll::URLMetadata)
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-url-metadata
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gourav Khunger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-07-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: jekyll
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.10.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.10.0
|
41
|
+
description: A plugin to expose meta data information from the head tag of a webapge
|
42
|
+
to liquid variables just from its url string.
|
43
|
+
email:
|
44
|
+
- gouravkhunger18@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- Gemfile
|
50
|
+
- jekyll-url-metadata.gemspec
|
51
|
+
- lib/jekyll-url-metadata.rb
|
52
|
+
- lib/jekyll-url-metadata/main.rb
|
53
|
+
- lib/jekyll-url-metadata/version.rb
|
54
|
+
homepage: https://github.com/gouravkhunger/jekyll-url-metadata
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.0.0
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubygems_version: 3.3.11
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Extract all kind of meta data from a url string
|
77
|
+
test_files: []
|