Skip to content

Commit f6bbe55

Browse files
authored
Merge pull request #2732 from freeCodeCamp/webp
Re-encode scraped images as WebP
2 parents e93667b + 12244b0 commit f6bbe55

15 files changed

Lines changed: 207 additions & 41 deletions

File tree

‎.devcontainer/devcontainer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"image": "mcr.microsoft.com/devcontainers/ruby:4",
33
"postAttachCommand": "bundle exec rackup",
4-
"postCreateCommand": "bundle install",
4+
"postCreateCommand": "sudo apt-get update && sudo apt-get install -y webp && bundle install",
55
"mounts": [
66
"source=${localEnv:HOME}/.claude,target=/home/vscode/.claude,type=bind"
77
],

‎.github/workflows/test.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
14+
- name: Install libwebp tools
15+
run: sudo apt-get update && sudo apt-get install -y webp
1416
- name: Set up Ruby
1517
uses: ruby/setup-ruby@95ef2b042f9d7a56d8268cba8559e2842e2ad01b # v1.321.0
1618
with:

‎Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ENV ENABLE_SERVICE_WORKER=true
55
WORKDIR /devdocs
66

77
RUN apt-get update && \
8-
apt-get -y install git nodejs libcurl4 libarchive-tools && \
8+
apt-get -y install git nodejs libcurl4 libarchive-tools webp && \
99
gem install bundler && \
1010
rm -rf /var/lib/apt/lists/*
1111

‎Dockerfile-alpine‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ WORKDIR /devdocs
77

88
COPY . /devdocs
99

10-
RUN apk --update add nodejs build-base libstdc++ libarchive-tools git zlib-dev libcurl && \
10+
RUN apk --update add nodejs build-base libstdc++ libarchive-tools git zlib-dev libcurl libwebp-tools && \
1111
gem install bundler && \
1212
bundle config set path.system true && \
1313
bundle config set without 'test' && \

‎assets/javascripts/app/config.js.erb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const config = {
1616
version: <%= Time.now.to_i %>,
1717
release: <%= Time.now.utc.httpdate.to_json %>,
1818
mathml_stylesheet: '/mathml.css',
19-
favicon_spritesheet: '<%= image_path('sprites/docs.png') %>',
19+
favicon_spritesheet: '<%= image_path('sprites/docs.webp') %>',
2020
service_worker_path: '/service-worker.js',
2121
service_worker_enabled: <%= App.environment == :production || ENV['ENABLE_SERVICE_WORKER'] == 'true' %>,
2222
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
._hide-in-development {
2-
<%= App.environment != :production ? 'display: none;' : '' %>
2+
<%= environment != :production ? 'display: none;' : '' %>
33
}

‎assets/stylesheets/global/_icons.scss.erb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
display: block;
1515
width: 1rem;
1616
height: 1rem;
17-
background-image: image-url('sprites/docs.png');
17+
background-image: image-url('sprites/docs.webp');
1818
background-size: <%= manifest['icons_per_row'] %>rem <%= manifest['icons_per_row'] %>rem;
1919
}
2020

2121
@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi) {
22-
%doc-icon { background-image: image-url('sprites/docs@2x.png'); }
22+
%doc-icon { background-image: image-url('sprites/docs@2x.webp'); }
2323
}
2424

2525
html._theme-dark {

‎docs/filter-reference.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ The `call` method must return either `doc` or `html`, depending on the type of f
8282
* [`InnerHtmlFilter`](https://github.com/freeCodeCamp/devdocs/blob/main/lib/docs/filters/core/inner_html.rb) — converts the document to a string
8383
* [`CleanTextFilter`](https://github.com/freeCodeCamp/devdocs/blob/main/lib/docs/filters/core/clean_text.rb) — removes empty nodes
8484
* [`AttributionFilter`](https://github.com/freeCodeCamp/devdocs/blob/main/lib/docs/filters/core/attribution.rb) — appends the license info and link to the original document
85+
* [`ImagesFilter`](https://github.com/freeCodeCamp/devdocs/blob/main/lib/docs/filters/core/images.rb) — downloads and inlines images as data URIs, optimizing them and re-encoding PNGs and GIFs as lossless WebP and JPEGs as lossy WebP
8586
* [`TitleFilter`](https://github.com/freeCodeCamp/devdocs/blob/main/lib/docs/filters/core/title.rb) — prepends the document with a title (disabled by default)
8687
* [`EntriesFilter`](https://github.com/freeCodeCamp/devdocs/blob/main/lib/docs/filters/core/entries.rb) — abstract filter for extracting the page's metadata
8788

‎docs/scraper-reference.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Default `html_filters`:
109109

110110
Default `text_filters`:
111111

112+
* [`ImagesFilter`](https://github.com/freeCodeCamp/devdocs/blob/main/lib/docs/filters/core/images.rb) — downloads and inlines images as data URIs, optimizing them and re-encoding PNGs and GIFs as lossless WebP and JPEGs as lossy WebP
112113
* [`InnerHtmlFilter`](https://github.com/freeCodeCamp/devdocs/blob/main/lib/docs/filters/core/inner_html.rb) — converts the document to a string
113114
* [`CleanTextFilter`](https://github.com/freeCodeCamp/devdocs/blob/main/lib/docs/filters/core/clean_text.rb) — removes empty nodes
114115
* [`AttributionFilter`](https://github.com/freeCodeCamp/devdocs/blob/main/lib/docs/filters/core/attribution.rb) — appends the license info and link to the original document

‎lib/app.rb‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class App < Sinatra::Application
5656
.sort
5757
.freeze
5858

59-
set :assets_compile, %w(*.png docs.json vendor.js unsupported.js application.css application-dark.css) + js_modules
59+
set :assets_compile, %w(sprites/docs.webp sprites/docs@2x.webp docs.json vendor.js unsupported.js application.css application-dark.css) + js_modules
6060

6161
require 'json'
6262
set :docs_prefix, 'docs'
@@ -267,8 +267,8 @@ def service_worker_asset_urls
267267
javascript_path('vendor'),
268268
javascript_path('unsupported'),
269269
stylesheet_path('application'),
270-
image_path('sprites/docs.png'),
271-
image_path('sprites/docs@2x.png'),
270+
image_path('sprites/docs.webp'),
271+
image_path('sprites/docs@2x.webp'),
272272
].compact
273273
end
274274

0 commit comments

Comments
 (0)