jekyll-thumbnail-img 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-thumbnail-img.rb +52 -44
- 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: 9c745c4b8971de2cb1cf37d40e83323e0c8e8ad4c73ed8b24f1de9d9de6e82ad
|
4
|
+
data.tar.gz: 412b4d62315e7f8c95c7821c2b7a0271f84d1a00a294034f016563e88b9998e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: feea8bbc7bb2ffea2607b033672eb8a8e0b5b370fec79e5b366088d0356392636499cf02f18e019c502c24f9f999647bf3fde19874d103e10bb8a77bec1569b4
|
7
|
+
data.tar.gz: eb5f51ac5854e5c4f4e10fdcdf51985a5ac7a2a06d74e2af1a4efb7104c48ef5f80523b6bdc4ef424089a0da693bc11ed3561fa91f9b30cae5cb5d39888197a6
|
data/lib/jekyll-thumbnail-img.rb
CHANGED
@@ -1,50 +1,58 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
def render(context)
|
11
|
-
source, width = @markup.split(" ").map(&:strip)
|
12
|
-
|
13
|
-
# Check if the source is a Liquid variable and attempt to resolve it
|
14
|
-
if context[source]
|
15
|
-
source = context[source]
|
16
|
-
end
|
17
|
-
unless source && width
|
18
|
-
raise "Usage: {% thumbnail_img /path/to/local/image.png 500 %}"
|
19
|
-
end
|
20
|
-
|
21
|
-
source_path = File.join(context.registers[:site].source, source)
|
22
|
-
|
23
|
-
# Check if the source file exists
|
24
|
-
unless File.exist?(source_path)
|
25
|
-
raise "File #{source} could not be found"
|
1
|
+
require 'jekyll'
|
2
|
+
require 'mini_magick'
|
3
|
+
|
4
|
+
module Jekyll
|
5
|
+
class JekyllThumbnailImg < Liquid::Tag
|
6
|
+
def initialize(tag_name, markup, tokens)
|
7
|
+
super
|
8
|
+
@markup = markup
|
26
9
|
end
|
27
10
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
11
|
+
def render(context)
|
12
|
+
source, width = @markup.split(" ").map(&:strip)
|
13
|
+
|
14
|
+
# Check if the source is a Liquid variable and attempt to resolve it
|
15
|
+
if context[source]
|
16
|
+
source = context[source]
|
17
|
+
end
|
18
|
+
unless source && width
|
19
|
+
raise "Usage: {% thumbnail_img /path/to/local/image.png 500 %}"
|
20
|
+
end
|
21
|
+
|
22
|
+
source_path = File.join(context.registers[:site].source, source)
|
23
|
+
|
24
|
+
# Check if the source file exists
|
25
|
+
unless File.exist?(source_path)
|
26
|
+
raise "File #{source} could not be found"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Calculate the relative path to the 'thumbnails' directory
|
30
|
+
relative_dest_dir = File.join(File.dirname(source), "thumbnails")
|
31
|
+
|
32
|
+
# Create the 'thumbnails' directory within the source directory
|
33
|
+
dest_dir = File.join(context.registers[:site].source, relative_dest_dir)
|
34
|
+
Dir.mkdir(dest_dir) unless Dir.exist?(dest_dir)
|
35
|
+
|
36
|
+
ext = File.extname(source)
|
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
|
+
)
|
52
|
+
end
|
53
|
+
dest
|
44
54
|
end
|
45
|
-
|
46
|
-
dest
|
47
55
|
end
|
48
56
|
end
|
49
57
|
|
50
|
-
Liquid::Template.register_tag("thumbnail_img", JekyllThumbnailImg)
|
58
|
+
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abhishek Paudel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|