jekyll-theme-artsy 0.1.5 → 0.1.6
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/_plugins/ext.rb +1 -0
- data/_plugins/thumbnail.rb +86 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a32d46bef7b8759abbb956569e9563ec75a9c315
|
4
|
+
data.tar.gz: c04481e6a45b31a64f83fb11b460d1402c8f099d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20e472a0a2cfe30bf73e56920ff8bae15e73c663d40dea2b5b7087ce8934376c250ae4406d12dfff6774bbf5b99342d47b5dd588dbf8fbf04039eb3247c05707
|
7
|
+
data.tar.gz: 40738a33739789a870ba58f3c195b7f6d5b9895e13d2d4a55392556b95ab94a54e00df53e314c42fd6d292fe1d43277242d5a6f78fcfe61bf4a58aa723a4dc59
|
data/_plugins/ext.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'jekyll/tagging'
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# Generates a thumbnail to an image and renders an image tag.
|
2
|
+
|
3
|
+
require 'mini_magick'
|
4
|
+
|
5
|
+
class Jekyll::Thumbnail < Liquid::Tag
|
6
|
+
# look up liquid variables
|
7
|
+
# source: http://stackoverflow.com/a/8771374/1489823
|
8
|
+
def look_up(context, name)
|
9
|
+
lookup = context
|
10
|
+
|
11
|
+
name.split(".").each do |value|
|
12
|
+
lookup = lookup[value]
|
13
|
+
end
|
14
|
+
|
15
|
+
lookup
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(tag_name, markup, tokens)
|
19
|
+
if /(?<source>[^\s]+)\s+(?<dimensions>[^\s]+)/i =~ markup
|
20
|
+
@source = source
|
21
|
+
@dimensions = dimensions
|
22
|
+
end
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def render(context)
|
27
|
+
if @source
|
28
|
+
|
29
|
+
# parking
|
30
|
+
# also put the parameters into the liquid parser again, to allow variable paths
|
31
|
+
source = @source
|
32
|
+
source = look_up context, source unless File.readable?(source)
|
33
|
+
dimensions = @dimensions
|
34
|
+
|
35
|
+
source_path = "#{source}"
|
36
|
+
raise "#{source_path} is not readable" unless File.readable?(source_path)
|
37
|
+
ext = File.extname(source)
|
38
|
+
desc = dimensions.gsub(/[^\da-z]+/i, '')
|
39
|
+
dest_dir = "#{File.dirname(source)}/thumbs"
|
40
|
+
Dir.mkdir dest_dir unless Dir.exists? dest_dir
|
41
|
+
dest = "#{dest_dir}/#{File.basename(source, ext)}_#{desc}#{ext}"
|
42
|
+
dest_path = "#{dest}"
|
43
|
+
|
44
|
+
# only thumbnail the image if it doesn't exist tor is less recent than the source file
|
45
|
+
# will prevent re-processing thumbnails for a ton of images...
|
46
|
+
if !File.exists?(dest_path) || File.mtime(dest_path) <= File.mtime(source_path)
|
47
|
+
# puts ENV.inspect
|
48
|
+
|
49
|
+
# don't generate images in preview mode whenever possible
|
50
|
+
if ENV['OCTOPRESS_ENV'] == 'preview' && /(?<width>\d+)?x(?<height>\d+)?/ =~ dimensions
|
51
|
+
html = "<img src='#{source}' style='"
|
52
|
+
html << "max-width: #{width}px; " unless width.nil? || width.empty?
|
53
|
+
html << "max-height: #{height}px;" unless height.nil? || height.empty?
|
54
|
+
html << "' />"
|
55
|
+
return html
|
56
|
+
end
|
57
|
+
|
58
|
+
puts "Thumbnailing #{source} to #{dest} (#{dimensions})"
|
59
|
+
|
60
|
+
image = MiniMagick::Image.open(source_path)
|
61
|
+
image.strip
|
62
|
+
image.resize dimensions
|
63
|
+
image.quality 60
|
64
|
+
|
65
|
+
second_image = MiniMagick::Image.new("img/watermark-#{dimensions}.png")
|
66
|
+
|
67
|
+
result = image.composite(second_image) do |c|
|
68
|
+
c.compose "Over" # OverCompositeOp
|
69
|
+
c.geometry "+20+20" # copy second_image onto first_image from (20, 20)
|
70
|
+
end
|
71
|
+
|
72
|
+
result.write dest_path
|
73
|
+
end
|
74
|
+
|
75
|
+
"""<img src='#{dest}' />"""
|
76
|
+
|
77
|
+
# TODO support relative paths
|
78
|
+
else
|
79
|
+
"Could not create thumbnail for #{source}. Usage: thumbnail /path/to/local/image.png 50x50<"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
Liquid::Template.register_tag('thumbnail', Jekyll::Thumbnail)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-theme-artsy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug Hatcher
|
@@ -92,6 +92,8 @@ files:
|
|
92
92
|
- _layouts/paginated.html
|
93
93
|
- _layouts/post.html
|
94
94
|
- _layouts/tag_page.html
|
95
|
+
- _plugins/ext.rb
|
96
|
+
- _plugins/thumbnail.rb
|
95
97
|
- assets/css/bootstrap.min.css
|
96
98
|
- assets/css/galleries.css
|
97
99
|
- assets/css/home.css
|