jekyll-imagemagick-sutermserv 1.4.1
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/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/Rakefile +4 -0
- data/jekyll-imagemagick-sutermserv.gemspec +40 -0
- data/lib/convert.rb +38 -0
- data/lib/defaults.rb +24 -0
- data/lib/generator.rb +151 -0
- data/lib/version.rb +9 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: be9bb607832a1e23d743d4722e3219dbf5ecdf7ffde0f9c1b4795c2158e57e08
|
4
|
+
data.tar.gz: 619c65ebf36d83be20043ab458ae1f02da121131b8652749836674d7db5f24d6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e0e140c1a85018baeae864902561f849ade4508a4604e808e0cc8aa80467ee9653d6a2ebd93035e05f1b9c7af08bcb6199fcf305999d7e859892673bf25a223
|
7
|
+
data.tar.gz: 6e2566e7dd1017bd1c9e67aa7fa60f0c41eed85f2911696adf6b1097109a2103d70971b8ff07fa21b644f13306c27139ff89ce01e7c78186df77122ee8e5d5c0
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Emilio Del Tessandoro
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "jekyll-imagemagick-sutermserv"
|
7
|
+
spec.version = Jekyll::Imagemagick::Sutermserv::VERSION
|
8
|
+
spec.platform = Gem::Platform::RUBY
|
9
|
+
spec.date = Time.now.strftime('%Y-%m-%d')
|
10
|
+
spec.authors = ['Emilio Del Tessandoro', 'Joshua Wiedekopf']
|
11
|
+
spec.email = ['emilio.deltessa@gmail.com', 'j.wiedekopf@uni-luebeck.de']
|
12
|
+
spec.homepage = 'https://gitlab.com/emmmile/jekyll-imagemagick'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.summary = 'Image generator for Jekyll 3 websites with changes for SU-TermServ.'
|
16
|
+
spec.description = 'Image generator for Jekyll 3 websites that automatically ' \
|
17
|
+
'convert images from one format to another.'
|
18
|
+
|
19
|
+
spec.files = Dir[
|
20
|
+
'README.md',
|
21
|
+
'LICENSE.txt',
|
22
|
+
'Rakefile',
|
23
|
+
'*.gemspec',
|
24
|
+
'Gemfile',
|
25
|
+
'lib/**/*'
|
26
|
+
]
|
27
|
+
|
28
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
29
|
+
spec.test_files = spec.files.grep(%r{^spec/})
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_dependency 'jekyll', '~> 4.3'
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
34
|
+
spec.add_development_dependency 'minitest', '~> 5.11'
|
35
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
spec.add_development_dependency 'rubocop', '~> 0.59.1'
|
38
|
+
spec.add_development_dependency 'test-unit', '~> 3.2'
|
39
|
+
|
40
|
+
end
|
data/lib/convert.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module JekyllImagemagickSutermserv
|
4
|
+
# Class used to convert a single image to another format using imagemagick
|
5
|
+
class ImageConvert
|
6
|
+
# Executes a command and wait for the output
|
7
|
+
def self.run_cmd(cmd)
|
8
|
+
exit_code = 0
|
9
|
+
error = ''
|
10
|
+
output = ''
|
11
|
+
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
|
12
|
+
stdin.close # we don't pass any input to the process
|
13
|
+
output = stdout.gets
|
14
|
+
error = stderr.gets
|
15
|
+
exit_code = wait_thr.value
|
16
|
+
end
|
17
|
+
|
18
|
+
if exit_code != 0
|
19
|
+
Jekyll.logger.error(LOG_PREFIX, "Command returned #{exit_code} with error #{error}")
|
20
|
+
end
|
21
|
+
|
22
|
+
# Return any captured return value
|
23
|
+
return [output, error]
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.run(input_file, output_file, flags, long_edge, resize_flags)
|
27
|
+
Jekyll.logger.info(LOG_PREFIX, "Generating image \"#{output_file}\"")
|
28
|
+
|
29
|
+
cmd = "convert \"#{input_file}\" #{flags} "
|
30
|
+
if long_edge != 0
|
31
|
+
cmd += "-resize \"#{long_edge}>\" #{resize_flags} "
|
32
|
+
end
|
33
|
+
cmd += "\"#{output_file}\""
|
34
|
+
Jekyll.logger.debug(LOG_PREFIX, "Running command \"#{cmd}\"")
|
35
|
+
run_cmd(cmd)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/defaults.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module JekyllImagemagickSutermserv
|
2
|
+
LOG_PREFIX = 'ImagemagickSuts:'.freeze
|
3
|
+
|
4
|
+
# The default configuration for the Imagemagick generator
|
5
|
+
# The values here represent the defaults if nothing is set
|
6
|
+
DEFAULTS = {
|
7
|
+
'enabled' => false,
|
8
|
+
|
9
|
+
# List of directories containing images to optimize, Nested directories will not be checked
|
10
|
+
'input_directories' => [],
|
11
|
+
|
12
|
+
# List of resolutions to generate, 0 means full size otherwise is the long edge
|
13
|
+
'widths' => [0],
|
14
|
+
|
15
|
+
'input_formats' => ['.png', '.tiff'],
|
16
|
+
|
17
|
+
'output_formats' => [],
|
18
|
+
|
19
|
+
# List of files or directories to exclude
|
20
|
+
'exclude' => [],
|
21
|
+
|
22
|
+
'skip_languages' => [],
|
23
|
+
}.freeze
|
24
|
+
end
|
data/lib/generator.rb
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
require 'jekyll/document'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module JekyllImagemagickSutermserv
|
5
|
+
# A static file to hold the generated webp image after generation
|
6
|
+
# so that Jekyll will copy it into the site output directory
|
7
|
+
class ImageFile < Jekyll::StaticFile
|
8
|
+
def write(_dest)
|
9
|
+
true # Recover from strange exception when starting server without --auto
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Go through a set of directories and convert files
|
14
|
+
class ImageGenerator < Jekyll::Generator
|
15
|
+
# This generator is safe from arbitrary code execution.
|
16
|
+
safe true
|
17
|
+
|
18
|
+
# This generator should be passive with regard to its execution
|
19
|
+
priority :lowest
|
20
|
+
|
21
|
+
# Main function, called by Jekyll-core. Do the transformations...
|
22
|
+
def generate(site)
|
23
|
+
# Retrieve and merge the configuration from the site yml file
|
24
|
+
@config = DEFAULTS.merge(site.config['imagemagick'] || {})
|
25
|
+
|
26
|
+
# If disabled then simply quit
|
27
|
+
unless @config['enabled']
|
28
|
+
Jekyll.logger.info(LOG_PREFIX, 'Disabled in site.config')
|
29
|
+
return
|
30
|
+
end
|
31
|
+
|
32
|
+
# If the site destination directory has not yet been created then create it now.
|
33
|
+
# Otherwise, we cannot write our file there.
|
34
|
+
unless File.directory? site.dest
|
35
|
+
Dir.mkdir(site.dest)
|
36
|
+
end
|
37
|
+
|
38
|
+
files = get_files_to_transform(site, @config['input_directories'], @config['input_formats'])
|
39
|
+
tuples = compute_transformations(site, files, @config['output_formats'], @config['widths'])
|
40
|
+
generate_output_paths(site, tuples)
|
41
|
+
generated_files = generate_files(site, tuples, @config['output_formats'])
|
42
|
+
|
43
|
+
Jekyll.logger.info(LOG_PREFIX, "Generated #{generated_files} file(s)")
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
# Return all the files to convert
|
49
|
+
def get_files_to_transform(site, directories, input_formats)
|
50
|
+
files = []
|
51
|
+
|
52
|
+
directories.each do |directory|
|
53
|
+
directory_full_path = File.join(site.source, directory)
|
54
|
+
Jekyll.logger.info(LOG_PREFIX, "Searching files in #{directory_full_path}")
|
55
|
+
|
56
|
+
Dir[directory_full_path + '**/*.*'].each do |file_full_path|
|
57
|
+
# If the file_full_path is not one of the supported formats, exit early
|
58
|
+
extension = File.extname(file_full_path).downcase
|
59
|
+
next unless input_formats.include? extension
|
60
|
+
|
61
|
+
files.push(file_full_path)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
return files
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns a list (input, output, edge)
|
69
|
+
def compute_transformations(site, input_files_full_path, formats, edges)
|
70
|
+
output = []
|
71
|
+
|
72
|
+
site_match = /_site\/?(?<lang>.*)$/.match(site.dest)
|
73
|
+
skip_lang = @config['skip_languages']
|
74
|
+
this_lang = site_match.named_captures["lang"]
|
75
|
+
|
76
|
+
if skip_lang.include?(this_lang)
|
77
|
+
Jekyll.logger.info(LOG_PREFIX, "skipping image generation for language '#{this_lang}'")
|
78
|
+
return output
|
79
|
+
end
|
80
|
+
|
81
|
+
if formats.length.zero?
|
82
|
+
Jekyll.logger.warn(LOG_PREFIX, 'No output formats found!')
|
83
|
+
return output
|
84
|
+
end
|
85
|
+
|
86
|
+
input_files_full_path.each do |input_file_full_path|
|
87
|
+
formats.each do |format_extension, _flags|
|
88
|
+
edges.each do |edge|
|
89
|
+
extension = File.extname(input_file_full_path)
|
90
|
+
prefix = File.dirname(input_file_full_path.sub(site.source, ''))
|
91
|
+
suffix = ''
|
92
|
+
unless edge.zero?
|
93
|
+
suffix = '-' + edge.to_s
|
94
|
+
end
|
95
|
+
filename = File.basename(input_file_full_path, extension) +
|
96
|
+
suffix + '.' + format_extension.to_s
|
97
|
+
output_file_full_path = File.join(site.dest + prefix, filename)
|
98
|
+
output.push([input_file_full_path, output_file_full_path, edge])
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
return output
|
104
|
+
end
|
105
|
+
|
106
|
+
def generate_output_paths(_site, tuples)
|
107
|
+
tuples.each do |tuple|
|
108
|
+
_input, output, _edge = tuple
|
109
|
+
directory = File.dirname(output)
|
110
|
+
FileUtils.mkdir_p(directory)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def generate_files(site, tuples, formats)
|
115
|
+
generated_files = 0
|
116
|
+
|
117
|
+
tuples.each do |tuple|
|
118
|
+
input_file_full_path, output_file_full_path, edge = tuple
|
119
|
+
# Check if the file already has a webp alternative?
|
120
|
+
# If we're force rebuilding all webp files then ignore the check
|
121
|
+
# also check the modified time on the files to ensure that the webp file
|
122
|
+
# is newer than the source file, if not then regenerate
|
123
|
+
|
124
|
+
if !File.file?(output_file_full_path) ||
|
125
|
+
(File.mtime(output_file_full_path) <= File.mtime(input_file_full_path))
|
126
|
+
# Generate the file
|
127
|
+
extension = File.extname(output_file_full_path).sub('.', '')
|
128
|
+
ImageConvert.run(input_file_full_path,
|
129
|
+
output_file_full_path,
|
130
|
+
formats[extension],
|
131
|
+
edge,
|
132
|
+
@config['resize_flags'])
|
133
|
+
generated_files += 1
|
134
|
+
end
|
135
|
+
|
136
|
+
next unless File.file?(output_file_full_path)
|
137
|
+
|
138
|
+
# Keep the webp file from being cleaned by Jekyll
|
139
|
+
prefix = File.dirname(input_file_full_path.sub(site.source, ''))
|
140
|
+
file_path = site.dest + prefix + '/' + File.basename(output_file_full_path)
|
141
|
+
Jekyll.logger.info(LOG_PREFIX, "Adding static file #{file_path}")
|
142
|
+
site.static_files << ImageFile.new(site,
|
143
|
+
site.dest,
|
144
|
+
prefix,
|
145
|
+
File.basename(output_file_full_path))
|
146
|
+
end
|
147
|
+
|
148
|
+
return generated_files
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-imagemagick-sutermserv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.4.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emilio Del Tessandoro
|
8
|
+
- Joshua Wiedekopf
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2023-12-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: jekyll
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '4.3'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '4.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: bundler
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '1.15'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '1.15'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: minitest
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '5.11'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '5.11'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '12.3'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '12.3'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - "~>"
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '3.0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - "~>"
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '3.0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rubocop
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "~>"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.59.1
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 0.59.1
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: test-unit
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '3.2'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '3.2'
|
112
|
+
description: Image generator for Jekyll 3 websites that automatically convert images
|
113
|
+
from one format to another.
|
114
|
+
email:
|
115
|
+
- emilio.deltessa@gmail.com
|
116
|
+
- j.wiedekopf@uni-luebeck.de
|
117
|
+
executables: []
|
118
|
+
extensions: []
|
119
|
+
extra_rdoc_files: []
|
120
|
+
files:
|
121
|
+
- Gemfile
|
122
|
+
- LICENSE.txt
|
123
|
+
- Rakefile
|
124
|
+
- jekyll-imagemagick-sutermserv.gemspec
|
125
|
+
- lib/convert.rb
|
126
|
+
- lib/defaults.rb
|
127
|
+
- lib/generator.rb
|
128
|
+
- lib/version.rb
|
129
|
+
homepage: https://gitlab.com/emmmile/jekyll-imagemagick
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubygems_version: 3.4.22
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: Image generator for Jekyll 3 websites with changes for SU-TermServ.
|
152
|
+
test_files: []
|