jekyll-replace-img 0.4.0 → 0.5.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/lib/jekyll-replace-img/hooks.rb +44 -42
 - data/lib/jekyll-replace-img/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA1:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: c439e00bf90addb4b297cde1f71cfaf805369f5b
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 0b07dd5a836b0c2a7fab3012bc0a181d2a887875
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 686e3cd36689285c0564a28d8ae860eb0ee9da8fce61387bbb025da21574c411fc45f4327abb764e59f4c0309d6c8db5edf400d696e574039a4af52d6ee3963b
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: ce695bc93ce79d35b015af3247b6f0806d3ad1bdd99beeb2b4ebae4cf50b4bcf9fce18077b63c142c89ea82d45a20ec0c56648955292d7a6dca54cc04b9a7321
         
     | 
| 
         @@ -1,56 +1,58 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         | 
| 
       3 
     | 
    
         
            -
             
     | 
| 
      
 3 
     | 
    
         
            +
            module JekyllReplaceImg
         
     | 
| 
      
 4 
     | 
    
         
            +
              KEY_CONFIG = "replace_img"
         
     | 
| 
       4 
5 
     | 
    
         | 
| 
       5 
     | 
    
         
            -
            KEY_RE_IMG      = "re_img"
         
     | 
| 
       6 
     | 
    
         
            -
            KEY_RE_IGNORE   = "re_ignore"
         
     | 
| 
       7 
     | 
    
         
            -
            KEY_REPLACEMENT = "replacement"
         
     | 
| 
      
 6 
     | 
    
         
            +
              KEY_RE_IMG      = "re_img"
         
     | 
| 
      
 7 
     | 
    
         
            +
              KEY_RE_IGNORE   = "re_ignore"
         
     | 
| 
      
 8 
     | 
    
         
            +
              KEY_REPLACEMENT = "replacement"
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
            RE_IMG      = "<img\\s*(?<attributes>.*?)\\s*/>"
         
     | 
| 
       10 
     | 
    
         
            -
            RE_IGNORE   = "data-ignore"
         
     | 
| 
       11 
     | 
    
         
            -
            REPLACEMENT = "
         
     | 
| 
       12 
     | 
    
         
            -
             
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
              RE_IMG      = "<img\\s*(?<attributes>.*?)\\s*/>"
         
     | 
| 
      
 11 
     | 
    
         
            +
              RE_IGNORE   = "data-ignore"
         
     | 
| 
      
 12 
     | 
    
         
            +
              REPLACEMENT = "
         
     | 
| 
      
 13 
     | 
    
         
            +
                <hy-img %<attributes>s>
         
     | 
| 
      
 14 
     | 
    
         
            +
                  <noscript><img data-ignore %<attributes>s/></noscript>
         
     | 
| 
      
 15 
     | 
    
         
            +
                </hy-img>"
         
     | 
| 
       15 
16 
     | 
    
         | 
| 
       16 
     | 
    
         
            -
            RE_DATAURL = %r!src\s*=\s*[""]\s*data:!ix.freeze
         
     | 
| 
      
 17 
     | 
    
         
            +
              RE_DATAURL = %r!src\s*=\s*[""]\s*data:!ix.freeze
         
     | 
| 
       17 
18 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
            re_img, re_ignore, replacement = nil
         
     | 
| 
      
 19 
     | 
    
         
            +
              re_img, re_ignore, replacement = nil
         
     | 
| 
       19 
20 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
            def get_config(config, key)
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
            end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
            Jekyll::Hooks.register(:site, :after_init) do |site|
         
     | 
| 
       25 
     | 
    
         
            -
              re_img = Regexp.new(
         
     | 
| 
       26 
     | 
    
         
            -
                get_config(site.config, KEY_RE_IMG) || RE_IMG,
         
     | 
| 
       27 
     | 
    
         
            -
                Regexp::EXTENDED | Regexp::IGNORECASE | Regexp::MULTILINE
         
     | 
| 
       28 
     | 
    
         
            -
              )
         
     | 
| 
      
 21 
     | 
    
         
            +
              def self.get_config(config, key)
         
     | 
| 
      
 22 
     | 
    
         
            +
                config[KEY_CONFIG] && config[KEY_CONFIG][key]
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
       29 
24 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
               
     | 
| 
       31 
     | 
    
         
            -
                 
     | 
| 
       32 
     | 
    
         
            -
             
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
              Jekyll::Hooks.register(:site, :after_init) do |site|
         
     | 
| 
      
 26 
     | 
    
         
            +
                re_img = Regexp.new(
         
     | 
| 
      
 27 
     | 
    
         
            +
                  JekyllReplaceImg.get_config(site.config, KEY_RE_IMG) || RE_IMG,
         
     | 
| 
      
 28 
     | 
    
         
            +
                  Regexp::EXTENDED | Regexp::IGNORECASE | Regexp::MULTILINE
         
     | 
| 
      
 29 
     | 
    
         
            +
                )
         
     | 
| 
       34 
30 
     | 
    
         | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
             
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
      
 31 
     | 
    
         
            +
                re_ignore = Regexp.new(
         
     | 
| 
      
 32 
     | 
    
         
            +
                  JekyllReplaceImg.get_config(site.config, KEY_RE_IGNORE) || RE_IGNORE,
         
     | 
| 
      
 33 
     | 
    
         
            +
                  Regexp::EXTENDED | Regexp::IGNORECASE
         
     | 
| 
      
 34 
     | 
    
         
            +
                )
         
     | 
| 
       38 
35 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
               
     | 
| 
       42 
     | 
    
         
            -
                last_match = Regexp.last_match
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                subs = { :i => i }
         
     | 
| 
       45 
     | 
    
         
            -
                last_match.names.each do |name|
         
     | 
| 
       46 
     | 
    
         
            -
                  subs[name.intern] = last_match[name]
         
     | 
| 
       47 
     | 
    
         
            -
                end
         
     | 
| 
      
 36 
     | 
    
         
            +
                replacement = JekyllReplaceImg.get_config(site.config, KEY_REPLACEMENT) || REPLACEMENT
         
     | 
| 
      
 37 
     | 
    
         
            +
                ENV["JEKYLL_ENV"] == "production" && replacement.gsub!(%r!\n+!, "")
         
     | 
| 
      
 38 
     | 
    
         
            +
              end
         
     | 
| 
       48 
39 
     | 
    
         | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
             
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
      
 40 
     | 
    
         
            +
              Jekyll::Hooks.register([:pages, :documents], :post_render) do |page|
         
     | 
| 
      
 41 
     | 
    
         
            +
                i = 0
         
     | 
| 
      
 42 
     | 
    
         
            +
                page.output = page.output.gsub(re_img) do |match|
         
     | 
| 
      
 43 
     | 
    
         
            +
                  last_match = Regexp.last_match
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                  subs = { :i => i }
         
     | 
| 
      
 46 
     | 
    
         
            +
                  last_match.names.each do |name|
         
     | 
| 
      
 47 
     | 
    
         
            +
                    subs[name.intern] = last_match[name]
         
     | 
| 
      
 48 
     | 
    
         
            +
                  end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
                  if match.index(re_ignore).nil? && match.index(RE_DATAURL).nil?
         
     | 
| 
      
 51 
     | 
    
         
            +
                    i += 1
         
     | 
| 
      
 52 
     | 
    
         
            +
                    replacement % subs
         
     | 
| 
      
 53 
     | 
    
         
            +
                  else
         
     | 
| 
      
 54 
     | 
    
         
            +
                    match
         
     | 
| 
      
 55 
     | 
    
         
            +
                  end
         
     | 
| 
       54 
56 
     | 
    
         
             
                end
         
     | 
| 
       55 
57 
     | 
    
         
             
              end
         
     | 
| 
       56 
58 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: jekyll-replace-img
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.5.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Florian Klampfer
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2019- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2019-08-24 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: jekyll
         
     |