Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Add rake task for image optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
dshevtsov committed May 22, 2019
1 parent 6e12e46 commit 7a785b6
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ group :test do
gem 'launchy'
end

group :optimiztion do
gem 'image_optim'
gem 'image_optim_pack'
end

group :jekyll_plugins do
gem 'jekyll-algolia', '~> 1.0'
gem 'jekyll-redirect-from'
Expand All @@ -20,3 +25,5 @@ group :jekyll_plugins do
gem 'jekyll-relative-links'
gem 'jekyll-optional-front-matter'
end

gem "pry", "~> 0.12.2"
24 changes: 23 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ GEM
algoliasearch (1.26.0)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
coderay (1.1.2)
colorator (1.1.0)
colorize (0.8.1)
concurrent-ruby (1.1.5)
Expand All @@ -30,9 +31,11 @@ GEM
ethon (0.12.0)
ffi (>= 1.3.0)
eventmachine (1.2.7)
exifr (1.3.6)
ffi (1.10.0)
filesize (0.2.0)
forwardable-extended (2.6.0)
fspath (3.1.0)
html-proofer (3.9.3)
activesupport (>= 4.2, < 6.0)
addressable (~> 2.3)
Expand All @@ -46,6 +49,17 @@ GEM
httpclient (2.8.3)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
image_optim (0.26.3)
exifr (~> 1.2, >= 1.2.2)
fspath (~> 3.0)
image_size (>= 1.5, < 3)
in_threads (~> 1.3)
progress (~> 3.0, >= 3.0.1)
image_optim_pack (0.5.2.20190428)
fspath (>= 2.1, < 4)
image_optim (~> 0.19)
image_size (2.0.1)
in_threads (1.5.1)
jekyll (3.8.5)
addressable (~> 2.4)
colorator (~> 1.0)
Expand Down Expand Up @@ -92,14 +106,19 @@ GEM
rb-inotify (~> 0.9, >= 0.9.7)
ruby_dep (~> 1.2)
mercenary (0.3.6)
method_source (0.9.2)
mini_portile2 (2.3.0)
minitest (5.11.3)
nokogiri (1.8.5)
mini_portile2 (~> 2.3.0)
parallel (1.17.0)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
progress (3.5.0)
progressbar (1.10.0)
pry (0.12.2)
coderay (~> 1.1.0)
method_source (~> 0.9.0)
public_suffix (3.0.3)
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
Expand All @@ -126,6 +145,8 @@ PLATFORMS
DEPENDENCIES
devdocs!
html-proofer
image_optim
image_optim_pack
jekyll
jekyll-algolia (~> 1.0)
jekyll-optional-front-matter
Expand All @@ -134,6 +155,7 @@ DEPENDENCIES
jekyll-sitemap
jekyll-titles-from-headings
launchy
pry (~> 0.12.2)

BUNDLED WITH
1.17.2
1.17.3
12 changes: 12 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,15 @@ end

desc 'Pull docs from external repositories'
task init: %w[multirepo:init]

desc 'Optimize images in modified files, or by path (rake image_optim path=path/to/dir/or/file).'
task :image_optim do
path = ENV['path']
unless path
staged_files = `git ls-files --modified --others --exclude-standard`.split("\n")
# staged_md_files = staged_files.select { |file| File.extname(file) == '.md' }
abort 'Didn\'t find any modified files.'.blue if staged_files.empty?
path = staged_files.join(' ')
end
system "bin/image_optim --no-pngout --no-svgo --recursive #{path}"
end
29 changes: 29 additions & 0 deletions bin/image_optim
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'image_optim' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)

bundle_binstub = File.expand_path("../bundle", __FILE__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
load(bundle_binstub)
else
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
end
end

require "rubygems"
require "bundler/setup"

load Gem.bin_path("image_optim", "image_optim")

0 comments on commit 7a785b6

Please sign in to comment.