jekyll-replace-img 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 19ac9404a77bb4e82bb4d2dc4f197800685bcfac
4
+ data.tar.gz: 5bd255e400fe59065af40f6c4e2e913bdb155110
5
+ SHA512:
6
+ metadata.gz: 8275ddf89840cdb35b3cbf14a8ddc0373d2cc993694807d69a2fe0f236570d4a4814d5beed076406021b9e23909103d2dce84c22ae119b023da7bf18e8048712
7
+ data.tar.gz: 61b301f10da7f2d679cd9e9c18109e05292cbab55a6bf8e0022b5e163f02ebbfac3e9c3ff31d7a06497e734bd83e0d34d853da6258b30accf8300a5244b838fb
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jekyll"
4
+ require_relative "jekyll-replace-img/hooks"
5
+
6
+ module JekyllReplaceImg
7
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ KEY_CONFIG = "replace_img"
4
+
5
+ KEY_RE_IMG = "re_img"
6
+ KEY_RE_IGNORE = "re_ignore"
7
+ KEY_REPLACEMENT = "replacement"
8
+
9
+ RE_IMG = "<img\\s*(?<attributes>.*?)\\s*/>"
10
+ RE_IGNORE = "data-ignore"
11
+ REPLACEMENT = "
12
+ <hy-img %<attributes>s>
13
+ <noscript><img data-ignore %<attributes>s/></noscript>
14
+ </hy-img>"
15
+
16
+ RE_DATAURL = %r!src\s*=\s*[""]\s*data:!ix.freeze
17
+
18
+ re_img, re_ignore, replacement = nil
19
+
20
+ def get_config(config, key)
21
+ config[KEY_CONFIG] && config[KEY_CONFIG][key]
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
+ )
29
+
30
+ re_ignore = Regexp.new(
31
+ get_config(site.config, KEY_RE_IGNORE) || RE_IGNORE,
32
+ Regexp::EXTENDED | Regexp::IGNORECASE
33
+ )
34
+
35
+ replacement = get_config(site.config, KEY_REPLACEMENT) || REPLACEMENT
36
+ ENV["JEKYLL_ENV"] == "production" && replacement.gsub!(%r!\n+!, "")
37
+ end
38
+
39
+ Jekyll::Hooks.register([:pages, :documents], :post_render) do |page|
40
+ i = 0
41
+ page.output = page.output.gsub(re_img) do |match|
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
48
+
49
+ if match.index(re_ignore).nil? && match.index(RE_DATAURL).nil?
50
+ i += 1
51
+ replacement % subs
52
+ else
53
+ match
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module JekyllReplaceImg
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-replace-img
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Florian Klampfer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-03 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.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.49.0
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: 1.0.0
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: 0.49.0
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: 1.0.0
61
+ - !ruby/object:Gem::Dependency
62
+ name: rubocop-jekyll
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: 0.7.0
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 0.7.0
75
+ description:
76
+ email:
77
+ - mail@qwtel.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - lib/jekyll-replace-img.rb
83
+ - lib/jekyll-replace-img/hooks.rb
84
+ - lib/jekyll-replace-img/version.rb
85
+ homepage: https://github.com/qwtel/jekyll-replace-img
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.5.2.3
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: A Jekyll plugin to replace <img/> tags with custom elements.
109
+ test_files: []