-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of the webp gem project
- Loading branch information
0 parents
commit fdee843
Showing
17 changed files
with
483 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
language: ruby | ||
cache: bundler | ||
sudo: false | ||
rvm: | ||
- 2.2 | ||
before_script: bundle update | ||
notifications: | ||
email: | ||
on_success: never | ||
on_failure: never |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Contributor Covenant Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
In the interest of fostering an open and welcoming environment, we as | ||
contributors and maintainers pledge to making participation in our project and | ||
our community a harassment-free experience for everyone, regardless of age, body | ||
size, disability, ethnicity, gender identity and expression, level of experience, | ||
nationality, personal appearance, race, religion, or sexual identity and | ||
orientation. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to creating a positive environment | ||
include: | ||
|
||
* Using welcoming and inclusive language | ||
* Being respectful of differing viewpoints and experiences | ||
* Gracefully accepting constructive criticism | ||
* Focusing on what is best for the community | ||
* Showing empathy towards other community members | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
* The use of sexualized language or imagery and unwelcome sexual attention or | ||
advances | ||
* Trolling, insulting/derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or electronic | ||
address, without explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
|
||
## Our Responsibilities | ||
|
||
Project maintainers are responsible for clarifying the standards of acceptable | ||
behavior and are expected to take appropriate and fair corrective action in | ||
response to any instances of unacceptable behavior. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or | ||
reject comments, commits, code, wiki edits, issues, and other contributions | ||
that are not aligned to this Code of Conduct, or to ban temporarily or | ||
permanently any contributor for other behaviors that they deem inappropriate, | ||
threatening, offensive, or harmful. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies both within project spaces and in public spaces | ||
when an individual is representing the project or its community. Examples of | ||
representing a project or community include using an official project e-mail | ||
address, posting via an official social media account, or acting as an appointed | ||
representative at an online or offline event. Representation of a project may be | ||
further defined and clarified by project maintainers. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
reported by contacting the project team at [[email protected]](mailto:[email protected]). All | ||
complaints will be reviewed and investigated and will result in a response that | ||
is deemed necessary and appropriate to the circumstances. The project team is | ||
obligated to maintain confidentiality with regard to the reporter of an incident. | ||
Further details of specific enforcement policies may be posted separately. | ||
|
||
Project maintainers who do not follow or enforce the Code of Conduct in good | ||
faith may face temporary or permanent repercussions as determined by other | ||
members of the project's leadership. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, | ||
available at [http://contributor-covenant.org/version/1/4][version] | ||
|
||
[homepage]: http://contributor-covenant.org | ||
[version]: http://contributor-covenant.org/version/1/4/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in jekyll-webp.gemspec | ||
gemspec | ||
|
||
if ENV["JEKYLL_VERSION"] | ||
gem "jekyll", "~> #{ENV["JEKYLL_VERSION"]}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Sverrir Sigmundarson | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
|
||
# WebP Generator for Jekyll | ||
WebP Image Generator for Jekyll Sites can automatically generate WebP images for all images on your static site and serve them when possible. | ||
> Read more about this tool on my blog at <a href="https://blog.sverrirs.com/2016/06/webp-generator-for-jekyll-sites.html" target="_blank">blog.sverrirs.com</a> | ||
## Installation | ||
|
||
``` | ||
gem install jekyll-webp | ||
``` | ||
|
||
The release includes all necessary files to run, including the WebP redistributable executable files. | ||
|
||
> Currently the release includes the v0.5.1 version of the WebP utilities for Windows, Linux and Mac OS X 10.9 (Mountain Lion). Other versions and releases can be downloaded directly from <a href="https://developers.google.com/speed/webp/docs/precompiled" target="_blank">the Google page</a>. | ||
Add the gem to your `Gemfile` and to Jekyll's `_config.yml` then run `jekyll serve` again and you should see the generator run during site generation. | ||
|
||
## Configuration | ||
The plugin can be configured in the site's `_config.yml` file by including the `webp` configuration element | ||
|
||
``` yml | ||
############################################################ | ||
# Site configuration for the WebP Generator Plugin | ||
# The values here represent the defaults if nothing is set | ||
webp: | ||
enabled: true | ||
|
||
# The quality of the webp conversion 0 to 100 (where 100 is least lossy) | ||
quality: 75 | ||
|
||
# List of directories containing images to optimize, nested directories will not be checked | ||
# By default the generator will search for a folder called `/img` under the site root and process all jpg, png and tiff image files found there. | ||
img_dir: ["/img"] | ||
|
||
# add ".gif" to the format list to generate webp for animated gifs as well | ||
formats: [".jpeg", ".jpg", ".png", ".tiff"] | ||
|
||
# File extensions for animated gif files | ||
gifs: [".gif"] | ||
|
||
# Set to true to always regenerate existing webp files | ||
regenerate: false | ||
|
||
# Local path to the WebP utilities to use (relative or absolute) | ||
# Omit or leave as nil to use the utilities shipped with the gem, override only to use your local install | ||
webp_path: nil | ||
|
||
# List of files or directories to exclude | ||
# e.g. custom or hand generated webp conversion files | ||
exclude: [] | ||
############################################################ | ||
``` | ||
|
||
## Simplest use: HTML | ||
In case you don't have control over your webserver then using the `<picture>` element and specifying all image formats available is the best option. This way the browser will decide which format to use based on its own capabilities. | ||
|
||
``` html | ||
<picture> | ||
<source srcset="/path/to/image.webp" type="image/webp"> | ||
<img src="/path/to/image.jpg" alt=""> | ||
</picture> | ||
``` | ||
|
||
## Advanced use: Webserver Configuration | ||
If you can then configuring your webserver to serve your new _.webp_ files to clients that support the format is probably the least problematic approach. This way you don't need to make any changes to your HTML files as your webserver will automatically serve WebP images when the client supports them. | ||
|
||
Below is an example for a .htaccess configuration section in an Apache web-server. It will redirect users to webp images whenever possible. | ||
|
||
``` | ||
#################### | ||
# Attempt to redirect images to WebP if one exists | ||
# and the client supports the file format | ||
#################### | ||
# check if browser accepts webp | ||
RewriteCond %{HTTP_ACCEPT} image/webp | ||
# check if file is jpg or png | ||
RewriteCond %{REQUEST_FILENAME} (.*)\.(jpe?g|png)$ | ||
# check if corresponding webp file exists image.png -> image.webp | ||
RewriteCond %1\.webp -f | ||
# serve up webp instead | ||
RewriteRule (.+)\.(jpe?g|png)$ $1.webp [T=image/webp,E=accept:1] | ||
AddType image/webp .webp | ||
``` | ||
|
||
> Depending on other configurations in your `.htaccess` file you might have to update your `ExpiresByType`, `ExpiresDefault` and `Header set Cache-Control` directives to include the webp format as well. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
|
||
Rake::TestTask.new do |t| | ||
t.libs.push 'lib' | ||
t.libs.push 'specs' | ||
t.verbose = true | ||
t.pattern = "spec/*_spec.rb" | ||
t.test_files = FileList['spec/*_spec.rb'] | ||
end | ||
|
||
desc "Run tests" | ||
task :default => [:test] |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# coding: utf-8 | ||
require_relative 'lib/jekyll-webp/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "jekyll-webp" | ||
spec.version = Jekyll::Webp::VERSION | ||
spec.platform = Gem::Platform::RUBY | ||
spec.date = DateTime.now.strftime('%Y-%m-%d') | ||
spec.authors = ["Sverrir Sigmundarson"] | ||
spec.email = ["[email protected]"] | ||
spec.homepage = "https://github.com/sverrirs/jekyll-webp" | ||
spec.license = "MIT" | ||
|
||
spec.summary = %q{WebP image generator for Jekyll 3 websites} | ||
spec.description = %q{WebP Image Generator for Jekyll 3 Sites that automatically generate WebP images for all images on your static site and serves them when possible.} | ||
|
||
spec.files = Dir['CODE_OF_CONDUCT.md', 'README.md', 'LICENSE', 'Rakefile', '*.gemspec', 'Gemfile', 'lib/**/*', 'spec/**/*', 'bin/**/*'] | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^spec/}) | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_development_dependency "jekyll", "~> 3.0" | ||
spec.add_development_dependency "bundler", "~> 1.5" | ||
spec.add_development_dependency "rake", "~> 1.5" | ||
spec.add_development_dependency "minitest", '~> 5.4', '>= 5.4.3' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require "jekyll-webp/version" | ||
require "jekyll-webp/defaults" | ||
require "jekyll-webp/webpExec" | ||
require "jekyll-webp/webpGenerator" | ||
|
||
module Jekyll | ||
module Webp | ||
end # module Webp | ||
end # module Jekyll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Jekyll | ||
module Webp | ||
|
||
# The default configuration for the Webp generator | ||
# The values here represent the defaults if nothing is set | ||
DEFAULT = { | ||
'enabled' => false, | ||
|
||
# The quality of the webp conversion 0 to 100 (where 100 is least lossy) | ||
'quality' => 75, | ||
|
||
# List of directories containing images to optimize, Nested directories will not be checked | ||
'img_dir' => ["/img"], | ||
|
||
# add ".gif" to the format list to generate webp for animated gifs as well | ||
'formats' => [".jpeg", ".jpg", ".png", ".tiff"], | ||
|
||
# File extensions for animated gif files | ||
'gifs' => [".gif"], | ||
|
||
# Set to true to always regenerate existing webp files | ||
'regenerate'=> false, | ||
|
||
# Local path to the WebP utilities to use (relative or absolute) | ||
# Leave as nil to use the cmd line utilities shipped with the gem, override to use your local install | ||
'webp_path' => nil, | ||
|
||
# List of files or directories to exclude | ||
# e.g. custom or hand generated webp conversion files | ||
'exclude' => [], | ||
|
||
# List of files or directories to explicitly include | ||
# e.g. single files outside of the main image directories | ||
'include' => [] | ||
} | ||
|
||
end # module Webp | ||
end # module Jekyll |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Jekyll | ||
module Webp | ||
VERSION = "0.1.0" | ||
# When modifying remember to issue a new tag command in git before committing, then push the new tag | ||
# git tag -a v0.1.0 -m "Gem v0.1.0" | ||
# git push origin --tags | ||
end #module Webp | ||
end #module Jekyll |
Oops, something went wrong.