jekyll-thumbnail-img 0.1.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 +7 -0
- data/lib/jekyll-thumbnail-img.rb +50 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c6f1558133356d35708570fe3adc2002f8527a3bbd0b6f0339f8df5f5861356e
|
4
|
+
data.tar.gz: df2e246e6bfcdca889563df614e2b89b028ec3b9688c83ffd5b9e77b8bf49b51
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1edcdfceae5b2f2c75d00d57d9cef8a9eab64bcf737aef60d3e5dae93aca814b49c664e59c3286bf4bfdfef61c1213fed3d225ed5391149194a75fd60cf49d4e
|
7
|
+
data.tar.gz: 816be152f8b6283a5db5ab1b83842313586bc073245f6a74554bd67e739afc8acbf9e2a89d40624c12772c08bc54761a7708bc776f3925ef6c56f6b2dacd2775
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "jekyll"
|
2
|
+
require "mini_magick"
|
3
|
+
|
4
|
+
class JekyllThumbnailImg < Liquid::Tag
|
5
|
+
def initialize(tag_name, markup, tokens)
|
6
|
+
super
|
7
|
+
@markup = markup
|
8
|
+
end
|
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"
|
26
|
+
end
|
27
|
+
|
28
|
+
# Calculate the relative path to the 'thumbnails' directory
|
29
|
+
relative_dest_dir = File.join(File.dirname(source), "thumbnails")
|
30
|
+
|
31
|
+
# Create the 'thumbnails' directory within the source directory
|
32
|
+
dest_dir = File.join(context.registers[:site].source, relative_dest_dir)
|
33
|
+
Dir.mkdir(dest_dir) unless Dir.exist?(dest_dir)
|
34
|
+
|
35
|
+
ext = File.extname(source)
|
36
|
+
dest = File.join(relative_dest_dir, File.basename(source, ext) + "_#{width}w#{ext}")
|
37
|
+
|
38
|
+
# Generate the thumbnail if it doesn't exist or if the source file was modified more recently than the thumbnail
|
39
|
+
full_dest_path = File.join(context.registers[:site].source, dest)
|
40
|
+
if !File.exist?(full_dest_path) || File.mtime(full_dest_path) <= File.mtime(source_path)
|
41
|
+
image = MiniMagick::Image.open(source_path)
|
42
|
+
image.resize("#{width}x")
|
43
|
+
image.write(File.join(context.registers[:site].source, dest))
|
44
|
+
end
|
45
|
+
|
46
|
+
dest
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
Liquid::Template.register_tag("thumbnail_img", JekyllThumbnailImg)
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-thumbnail-img
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Abhishek Paudel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-11-02 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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mini_magick
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- lib/jekyll-thumbnail-img.rb
|
48
|
+
homepage: https://github.com/abpaudel/jekyll-thumbnail-img
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata: {}
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubygems_version: 3.3.26
|
68
|
+
signing_key:
|
69
|
+
specification_version: 4
|
70
|
+
summary: A Jekyll plugin to generate image thumbnails with specified width.
|
71
|
+
test_files: []
|