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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c03cb0df37cbb2162a3c5c360ddb981b55825629b61427ebe0da2e65b0a1d410
4
- data.tar.gz: 45218a414c218e968970b57736bf64c321994d321334df2c8eb0fe4ef2942000
3
+ metadata.gz: 6d1693fc705af7e30e9587f5d139d20e304d120d7bc18bc6d53f3363a260c203
4
+ data.tar.gz: 3c77ee1b74bb0897cbbdfa8551fb0e44ffea3ee6647bb9de83af1d06a25a58a2
5
5
  SHA512:
6
- metadata.gz: 1f14ef715fa6405813d067914d45390fd5ebaacb0d445876a026e7abb73e32e773be3a6c0526ccd97140a2d6f4144fbdbd2e8f7d18a16cf30aac86ada4d28faf
7
- data.tar.gz: 18c636ce932799e1ab2efd4877798e04381755cdbe2b32810bd32600d53281bfef722bc03b5374e0c6b0737f2cba7821fe823c93303ad6ff799948a96cc07e39
6
+ metadata.gz: eb2d3888112455ff91e843f81f69e0bf1b640611c541f00387f0bcba8d19f5686020e5e73377554a2e09a579905b3b3b6cfb2f42763758d5e55645104d12434c
7
+ data.tar.gz: 25daa12f0fb156a73fe0e165c90282d041d4573cdecc46aa91c4c9550feaf0251af7f9ab3bc0ac608c80cbfb68e58889bc52f095f535e09fdaa30811b5e6c66c
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/rukbotto/jekyll-image-data.svg?branch=master)](https://travis-ci.org/rukbotto/jekyll-image-data)
4
4
 
5
- Image data for Jekyll posts and pages. Crawls markdown files in search of image
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,
@@ -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 : ""
@@ -1,3 +1,3 @@
1
1
  module JekyllImageData
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  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.1.4
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-02-15 00:00:00.000000000 Z
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.3
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.