Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Webp images with fallback #99

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ gem "jekyll", "~> 3.7.2"
group :jekyll_plugins do
gem "jekyll-feed", "~> 0.6"
gem "jekyll-assets"
gem "jekyll-webp"
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
Expand Down
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ GEM
sass (~> 3.4)
jekyll-watch (2.1.2)
listen (~> 3.0)
jekyll-webp (1.0.0)
kramdown (1.17.0)
liquid (4.0.3)
liquid-tag-parser (1.9.0)
Expand Down Expand Up @@ -98,7 +99,8 @@ DEPENDENCIES
jekyll (~> 3.7.2)
jekyll-assets
jekyll-feed (~> 0.6)
jekyll-webp
tzinfo-data

BUNDLED WITH
1.16.1
2.0.1
31 changes: 31 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,34 @@ exclude:
- CONTRIBUTING.md
- LICENSE.md
- WEBSITE-CODE-OF-CONDUCT.md

############################################################
# 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: ["/assets/images"]

# 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: []
############################################################
14 changes: 10 additions & 4 deletions _includes/footer.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
<div class="row">
<div class="col-md-3 text-center">
<ul class="list-inline">
<li><a target="_blank" href="https://www.facebook.com/PyConIndia/">{% asset fb.png alt="Facebook" %}</a></li>
<li><a target="_blank" href="https://twitter.com/pyconindia">{% asset tw.png alt="Twitter" %}</a></li>
<li><a target="_blank" href="https://www.facebook.com/PyConIndia/">
{% picture src=fb alt="Facebook"%}
</a></li>
<li><a target="_blank" href="https://twitter.com/pyconindia">
{% picture src=tw alt="Twitter"%}
</a></li>
</ul>
<a target="_blank" href="mailto:[email protected]">[email protected]</a>
</div>
<div class="col-md-6 text-center">
{% asset logo-small.png alt="PyCon India 2019 Logo" width="70%" %}
{% picture src=logo-small alt="Twitter" width="70%"%}
</div>
<div class="col-md-3 text-center">
<p class="design-by">Design by</p>
<a target="_blank" href="http://webchirpy.com">{% asset wclogo.png alt="Webchirpy Logo" width="40%" %}</a>
<a target="_blank" href="http://webchirpy.com">
{% picture src=wclogo alt="Webchirpy Logo" width="40%"%}
</a>
</div>
</div>
</div>
Expand Down
28 changes: 28 additions & 0 deletions _plugins/picture.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Jekyll
class RenderTimeTag < Liquid::Tag

def initialize(tag_name, markup, tokens)
super
@args = Parser.new(markup)
end

def render(context)
attributes = ""
@args.each do |key, value|
if key == :src
attributes.concat("#{key}='./assets/images/#{value}.png'")
else
attributes.concat("#{key}='#{value}' ");
end
end
tag = "<picture>
<source srcset='./assets/images/#{@args[:src]}.webp' type='image/webp'>
<img #{attributes}>
</picture>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than checking for each attribute like this, can we just loop over all attributes and add them here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@astronomersiva Can you check now ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks good...I believe the only issue now is with versioning the files(the checksum)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@astronomersiva Yes. Do you have any suggestions wrt versioning ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try using the jekyll assets helper here? Let's try that out and see

"
return tag
end
end
end

Liquid::Template.register_tag('picture', Jekyll::RenderTimeTag)