jekyll-image-data 0.1.4 → 0.2.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 +14 -1
- data/lib/jekyll-image-data.rb +2 -2
- data/lib/jekyll-image-data/crawler.rb +6 -1
- data/lib/jekyll-image-data/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d1693fc705af7e30e9587f5d139d20e304d120d7bc18bc6d53f3363a260c203
|
4
|
+
data.tar.gz: 3c77ee1b74bb0897cbbdfa8551fb0e44ffea3ee6647bb9de83af1d06a25a58a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb2d3888112455ff91e843f81f69e0bf1b640611c541f00387f0bcba8d19f5686020e5e73377554a2e09a579905b3b3b6cfb2f42763758d5e55645104d12434c
|
7
|
+
data.tar.gz: 25daa12f0fb156a73fe0e165c90282d041d4573cdecc46aa91c4c9550feaf0251af7f9ab3bc0ac608c80cbfb68e58889bc52f095f535e09fdaa30811b5e6c66c
|
data/README.md
CHANGED
@@ -2,7 +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
|
5
|
+
Image data for Jekyll posts and pages. Crawls generated HTML files in search of image
|
6
6
|
data ("src" and "alt" attributes) and makes it available as a post/page
|
7
7
|
metadata attribute.
|
8
8
|
|
@@ -67,6 +67,19 @@ post.data["images"] = [
|
|
67
67
|
{% endfor %}
|
68
68
|
```
|
69
69
|
|
70
|
+
### Excluding images
|
71
|
+
|
72
|
+
If you don't want data from some images to be included in the `post.data["images"]` or `page.data["images"]` variables, you can add the image URL to the `exclude` setting in the `_config.yml` file:
|
73
|
+
|
74
|
+
```yaml
|
75
|
+
image_data:
|
76
|
+
exclude:
|
77
|
+
- /media/images/800x600.png
|
78
|
+
- https://upload.wikimedia.org
|
79
|
+
```
|
80
|
+
|
81
|
+
You can put the complete URL of the image or just part of it. In the above example, data from any image that contains the string `/media/images/800x600.png` or `https://upload.wikimedia.org` in the `src` attribute won't be added to the data variable for any post or page.
|
82
|
+
|
70
83
|
## Development
|
71
84
|
|
72
85
|
After checking out the repo, run `script/setup` to install dependencies. Then,
|
data/lib/jekyll-image-data.rb
CHANGED
@@ -6,10 +6,10 @@ module JekyllImageData
|
|
6
6
|
@crawler = Crawler.new
|
7
7
|
|
8
8
|
Jekyll::Hooks.register :posts, :post_render do |post|
|
9
|
-
post.data["images"] = @crawler.crawl(post.content)
|
9
|
+
post.data["images"] = @crawler.crawl(post.content, post.site.config)
|
10
10
|
end
|
11
11
|
|
12
12
|
Jekyll::Hooks.register :pages, :post_render do |page|
|
13
|
-
page.data["images"] = @crawler.crawl(page.content)
|
13
|
+
page.data["images"] = @crawler.crawl(page.content, page.site.config)
|
14
14
|
end
|
15
15
|
end
|
@@ -2,12 +2,17 @@ require "nokogiri"
|
|
2
2
|
|
3
3
|
module JekyllImageData
|
4
4
|
class Crawler
|
5
|
-
def crawl(content)
|
5
|
+
def crawl(content, config)
|
6
6
|
images = []
|
7
|
+
exclude = config.dig("image_data", "exclude") || []
|
7
8
|
html = Nokogiri::HTML(content)
|
8
9
|
html.xpath("//img").each do |item|
|
9
10
|
src = item.xpath("@src").first
|
10
11
|
alt = item.xpath("@alt").first
|
12
|
+
excluded = exclude.select do |exclude_item|
|
13
|
+
src.value.include?(exclude_item)
|
14
|
+
end
|
15
|
+
next unless excluded.empty?
|
11
16
|
images << {
|
12
17
|
"url" => src ? src.content : "",
|
13
18
|
"alt" => alt ? alt.content : ""
|
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.2.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-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.7.
|
126
|
+
rubygems_version: 2.7.6
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: Image data for Jekyll posts and pages.
|