jekyll-thumbnail-img 0.1.1 → 0.1.2
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-thumbnail-img.rb +28 -37
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2aac91c9210d6650d7870b5a70c2477ddac7d7f72b754adcdd02af0b1a7b988
|
4
|
+
data.tar.gz: f5234e4e9f262d3036d4ca62bb2d1cddaf747978cd4ebda013c18ff4ccfb138d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 358d4723d03ee22488fef29ace01225445fb668152600219a28323369c242478d2f173204993bcd739e55d22510dcf104deaf98c022940138129dd63912843ba
|
7
|
+
data.tar.gz: f720d8d0bd21ec8cd054113ce8ff9aba228d2617523e8c3c5113961c8db81dc7650272c68c987389ad950bf59c187284a13e5eee1963c7cddb82baf8cf951930
|
data/lib/jekyll-thumbnail-img.rb
CHANGED
@@ -3,56 +3,47 @@ require 'mini_magick'
|
|
3
3
|
|
4
4
|
module Jekyll
|
5
5
|
class JekyllThumbnailImg < Liquid::Tag
|
6
|
+
@@pending = [] # thumbnails to be generated
|
7
|
+
|
6
8
|
def initialize(tag_name, markup, tokens)
|
7
9
|
super
|
8
10
|
@markup = markup
|
9
11
|
end
|
10
12
|
|
11
13
|
def render(context)
|
12
|
-
source, width = @markup.split
|
14
|
+
source, width = @markup.split.map(&:strip)
|
15
|
+
source = context[source] if context[source] # resolve liquid vars
|
13
16
|
|
14
|
-
|
15
|
-
|
16
|
-
source = context[source]
|
17
|
-
end
|
18
|
-
unless source && width
|
19
|
-
raise "Usage: {% thumbnail_img /path/to/local/image.png 500 %}"
|
20
|
-
end
|
17
|
+
raise "Usage: {% thumbnail_img /path/to/image.png 500 %}" unless source && width
|
18
|
+
raise "File #{source} not found" unless File.exist?(File.join(context.registers[:site].source, source))
|
21
19
|
|
22
|
-
|
20
|
+
# Queue thumbnail for generation
|
21
|
+
dest = File.join(File.dirname(source), "thumbnails", "#{File.basename(source, '.*')}_#{width}w#{File.extname(source)}")
|
22
|
+
@@pending << {
|
23
|
+
source: File.join(context.registers[:site].source, source),
|
24
|
+
dest: File.join(context.registers[:site].dest, dest),
|
25
|
+
width: width
|
26
|
+
}
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
raise "File #{source} could not be found"
|
27
|
-
end
|
28
|
+
dest
|
29
|
+
end
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
dest = File.join(relative_dest_dir, File.basename(source, ext) + "_#{width}w#{ext}")
|
38
|
-
|
39
|
-
# Generate the thumbnail if it doesn't exist or if the source file was modified more recently than the thumbnail
|
40
|
-
full_dest_path = File.join(context.registers[:site].source, dest)
|
41
|
-
if !File.exist?(full_dest_path) || File.mtime(full_dest_path) <= File.mtime(source_path)
|
42
|
-
image = MiniMagick::Image.open(source_path)
|
43
|
-
image.resize("#{width}x")
|
44
|
-
image.write(full_dest_path)
|
45
|
-
Jekyll.logger.info "JekyllThumbnailImg", "Generating: " + File.join(context.registers[:site].source, dest)
|
46
|
-
context["site"]["static_files"] << StaticFile.new(
|
47
|
-
context.registers[:site],
|
48
|
-
context.registers[:site].source,
|
49
|
-
@dir,
|
50
|
-
dest
|
51
|
-
)
|
31
|
+
def self.generate_thumbnails(site)
|
32
|
+
@@pending.each do |thumb|
|
33
|
+
FileUtils.mkdir_p(File.dirname(thumb[:dest]))
|
34
|
+
# Check if thumbnail doesn't exist or if the source file was modified more recently than the thumbnail
|
35
|
+
if !File.exist?(thumb[:dest]) || File.mtime(thumb[:dest]) <= File.mtime(thumb[:source])
|
36
|
+
Jekyll.logger.info "JekyllThumbnailImg:", "Generating: #{thumb[:dest].sub(site.dest + '/', '')}"
|
37
|
+
MiniMagick::Image.open(thumb[:source]).resize("#{thumb[:width]}x").write(thumb[:dest])
|
38
|
+
end
|
52
39
|
end
|
53
|
-
|
40
|
+
@@pending.clear
|
54
41
|
end
|
55
42
|
end
|
56
43
|
end
|
57
44
|
|
45
|
+
Jekyll::Hooks.register :site, :post_write do |site|
|
46
|
+
Jekyll::JekyllThumbnailImg.generate_thumbnails(site)
|
47
|
+
end
|
48
|
+
|
58
49
|
Liquid::Template.register_tag("thumbnail_img", Jekyll::JekyllThumbnailImg)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-thumbnail-img
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abhishek Paudel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|