jekyll-image-data 0.2.0 → 0.3.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 +4 -4
- data/README.md +12 -26
- data/jekyll-image-data.gemspec +1 -2
- data/lib/jekyll-image-data/crawler.rb +32 -14
- data/lib/jekyll-image-data/version.rb +1 -1
- data/lib/jekyll-image-data.rb +2 -2
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c91e1e0aee9d8638fa3251bf005331018ac9396d28f74677db957617570ea9c2
|
4
|
+
data.tar.gz: 951c65eb83606857b7e7998c8621f5cd75736d1553e5d3eb60ff71e3db34c90f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2b9b48e280d977192e026e0590ec35a981fec6ed1e87038614f4984c9debc6412db559dc6f87a52a4d2b90fc004d84498dd6019b2fd8ed5961b97a8646ca901
|
7
|
+
data.tar.gz: 04d53ed526a13f8477da914c347bd749e62515b48d64f8e93959df701cbf07d411e44d620d3811f350c8b78f43145fc3bddbcbd666ae506fa2200f12894872e2
|
data/README.md
CHANGED
@@ -2,9 +2,7 @@
|
|
2
2
|
|
3
3
|
[](https://travis-ci.org/rukbotto/jekyll-image-data)
|
4
4
|
|
5
|
-
Image data for Jekyll posts and pages. Crawls generated HTML files in search of image
|
6
|
-
data ("src" and "alt" attributes) and makes it available as a post/page
|
7
|
-
metadata attribute.
|
5
|
+
Image data for Jekyll posts and pages. Crawls generated HTML files in search of image data ("src" and "alt" attributes) and makes it available as a post/page metadata attribute.
|
8
6
|
|
9
7
|
## Installation
|
10
8
|
|
@@ -28,8 +26,7 @@ $ gem install jekyll-image-data
|
|
28
26
|
|
29
27
|
## Usage
|
30
28
|
|
31
|
-
Define your images using Markdown format, plain HTML or by including a
|
32
|
-
`.liquid` file:
|
29
|
+
Define your images using Markdown format, plain HTML or by including a `.liquid` file:
|
33
30
|
|
34
31
|
```markdown
|
35
32
|

|
@@ -45,13 +42,12 @@ or
|
|
45
42
|
```
|
46
43
|
|
47
44
|
```liquid
|
48
|
-
{% include image.liquid %}
|
45
|
+
{% include image.liquid src="http://placehold.it/800x600" alt="Image" %}
|
49
46
|
```
|
50
47
|
|
51
|
-
|
52
|
-
|
53
|
-
`page.data["images"]` will hold `alt` and `src` data for all images inside
|
54
|
-
post/page:
|
48
|
+
Note that the included file must be named `image.liquid` or `image.html` and must accept two parameters: `src` and `alt`.
|
49
|
+
|
50
|
+
This plugin gets executed in the `:posts, :pre_render` and `:pages, :post_init` hooks. After execution, `post.data["images"]` or `page.data["images"]` will hold `alt` and `src` data for all images inside post/page:
|
55
51
|
|
56
52
|
```ruby
|
57
53
|
post.data["images"] = [
|
@@ -73,31 +69,21 @@ If you don't want data from some images to be included in the `post.data["images
|
|
73
69
|
|
74
70
|
```yaml
|
75
71
|
image_data:
|
76
|
-
exclude:
|
77
|
-
- /media/images/800x600.png
|
78
|
-
- https://upload.wikimedia.org
|
72
|
+
exclude: "/media/images/800x600.png"
|
79
73
|
```
|
80
74
|
|
81
|
-
You can put the complete URL of the
|
75
|
+
Remember this setting is a regular expression. You can put the complete URL of the images or just part of it. In the above example, data from any image that contains the string `/media/images/800x600.png` in the `src` attribute won't be added to the data variable for any post or page.
|
82
76
|
|
83
77
|
## Development
|
84
78
|
|
85
|
-
After checking out the repo, run `script/setup` to install dependencies. Then,
|
86
|
-
run `rake spec` to run the tests. You can also run `script/console` for an
|
87
|
-
interactive prompt that will allow you to experiment.
|
79
|
+
After checking out the repo, run `script/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `script/console` for an interactive prompt that will allow you to experiment.
|
88
80
|
|
89
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To
|
90
|
-
release a new version, update the version number in `version.rb`, and then run
|
91
|
-
`bundle exec rake release`, which will create a git tag for the version, push
|
92
|
-
git commits and tags, and push the `.gem` file to
|
93
|
-
[rubygems.org](https://rubygems.org).
|
81
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
94
82
|
|
95
83
|
## Contributing
|
96
84
|
|
97
|
-
Bug reports and pull requests are welcome on GitHub at
|
98
|
-
https://github.com/rukbotto/jekyll-image-data.
|
85
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rukbotto/jekyll-image-data.
|
99
86
|
|
100
87
|
## License
|
101
88
|
|
102
|
-
The gem is available as open source under the terms of the [MIT
|
103
|
-
License](http://opensource.org/licenses/MIT).
|
89
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/jekyll-image-data.gemspec
CHANGED
@@ -24,8 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
end
|
25
25
|
spec.require_paths = ["lib"]
|
26
26
|
|
27
|
-
spec.add_dependency "jekyll", "~> 3.
|
28
|
-
spec.add_dependency "nokogiri", "~> 1.8.2"
|
27
|
+
spec.add_dependency "jekyll", "~> 3.4.0"
|
29
28
|
|
30
29
|
spec.add_development_dependency "bundler", "~> 1.14"
|
31
30
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -1,23 +1,41 @@
|
|
1
|
-
require "nokogiri"
|
2
|
-
|
3
1
|
module JekyllImageData
|
4
2
|
class Crawler
|
3
|
+
def initialize
|
4
|
+
src = %r{(?:https|http|mailto)?(?:\:/)?/\S+}
|
5
|
+
alt = %r{[[[:alnum:]][[:space:]]-]+}
|
6
|
+
|
7
|
+
md_image = %r{!\[(.*)\]\((.*)\)}
|
8
|
+
md_image_ref = %r{!\[(.*)\]\[(.*)\]}
|
9
|
+
html_image = %r{<img.*(src="(#{src})".*alt="(#{alt})"|alt="(#{alt})".*src="(#{src})"|src="(#{src})")}
|
10
|
+
include_image = %r{\{\%\s*include\s*image.(liquid|html)\s*(src="(#{src})".*alt="(#{alt})"|alt="(#{alt})".*src="(#{src})")}
|
11
|
+
|
12
|
+
@image = %r{#{md_image}|#{md_image_ref}|#{html_image}|#{include_image}}
|
13
|
+
@image_ref = %r{\[(.*)\]:\s*(\S*)}
|
14
|
+
end
|
15
|
+
|
5
16
|
def crawl(content, config)
|
6
17
|
images = []
|
7
|
-
exclude = config.dig("image_data", "exclude") ||
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
18
|
+
exclude = config.dig("image_data", "exclude") || ""
|
19
|
+
exclude = Regexp.new(exclude)
|
20
|
+
|
21
|
+
content.scan(@image) do |match|
|
22
|
+
src = match[1] || match[5] || match[8] || match[9] || match[12] || match[15] || ""
|
23
|
+
alt = match[0] || match[2] || match[6] || match[7] || match[13] || match[14] || ""
|
24
|
+
ref = match[3] || ""
|
25
|
+
images << { "url" => src, "alt" => alt, "ref" => ref }
|
26
|
+
end
|
27
|
+
|
28
|
+
content.scan(@image_ref) do |match|
|
29
|
+
images.each do |image|
|
30
|
+
image["url"] = match[1] if image["ref"] == match[0]
|
14
31
|
end
|
15
|
-
next unless excluded.empty?
|
16
|
-
images << {
|
17
|
-
"url" => src ? src.content : "",
|
18
|
-
"alt" => alt ? alt.content : ""
|
19
|
-
}
|
20
32
|
end
|
33
|
+
|
34
|
+
images.each do |image|
|
35
|
+
image.delete("ref")
|
36
|
+
images.delete(image) if exclude.match(image["url"])
|
37
|
+
end
|
38
|
+
|
21
39
|
images
|
22
40
|
end
|
23
41
|
end
|
data/lib/jekyll-image-data.rb
CHANGED
@@ -5,11 +5,11 @@ require "jekyll-image-data/version"
|
|
5
5
|
module JekyllImageData
|
6
6
|
@crawler = Crawler.new
|
7
7
|
|
8
|
-
Jekyll::Hooks.register :posts, :
|
8
|
+
Jekyll::Hooks.register :posts, :pre_render do |post|
|
9
9
|
post.data["images"] = @crawler.crawl(post.content, post.site.config)
|
10
10
|
end
|
11
11
|
|
12
|
-
Jekyll::Hooks.register :pages, :
|
12
|
+
Jekyll::Hooks.register :pages, :post_init do |page|
|
13
13
|
page.data["images"] = @crawler.crawl(page.content, page.site.config)
|
14
14
|
end
|
15
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-image-data
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jose Miguel Venegas Mendoza
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -16,28 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.4.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
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.8.2
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.8.2
|
26
|
+
version: 3.4.0
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -123,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
109
|
version: '0'
|
124
110
|
requirements: []
|
125
111
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.7.
|
112
|
+
rubygems_version: 2.7.7
|
127
113
|
signing_key:
|
128
114
|
specification_version: 4
|
129
115
|
summary: Image data for Jekyll posts and pages.
|