Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
ee294453
Commit
ee294453
authored
Sep 09, 2021
by
Markus Koller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert pngquant tasks into shell script, support file arguments
parent
565fba25
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
62 deletions
+78
-62
bin/pngquant
bin/pngquant
+64
-0
doc/development/documentation/styleguide/index.md
doc/development/documentation/styleguide/index.md
+14
-7
lib/tasks/pngquant.rake
lib/tasks/pngquant.rake
+0
-55
No files found.
bin/pngquant
0 → 100755
View file @
ee294453
#!/usr/bin/env ruby
# frozen_string_literal: true
require
'rails'
require
'png_quantizator'
require
'parallel'
require
'rainbow/ext/string'
require_relative
'../tooling/lib/tooling/images'
return
if
Rails
.
env
.
production?
def
usage
puts
<<~
EOF
Usage:
#{
$0
}
[compress|lint] [PATH..]
compress Compress all documentation PNG images using pngquant.
lint Checks that all documentation PNG images have been compressed with pngquant.
PATH One or more files or directories. If empty, `doc/**/*.png` is used.
EOF
end
command
=
ARGV
.
shift
paths
=
ARGV
.
presence
||
[
'doc'
]
files
=
paths
.
flat_map
do
|
path
|
File
.
directory?
(
path
)
?
Dir
.
glob
(
File
.
join
(
path
,
'/**/*.png'
))
:
path
end
case
command
when
'compress'
puts
"Compressing
#{
files
.
size
}
PNG files"
Parallel
.
each
(
files
)
do
|
file
|
was_uncompressed
,
savings
=
Tooling
::
Image
.
compress_image
(
file
)
if
was_uncompressed
puts
"
#{
file
}
was reduced by
#{
savings
}
bytes"
end
end
when
'lint'
puts
"Checking
#{
files
.
size
}
PNG files"
uncompressed_files
=
Parallel
.
map
(
files
)
do
|
file
|
is_uncompressed
,
_
=
Tooling
::
Image
.
compress_image
(
file
,
true
)
if
is_uncompressed
puts
"Uncompressed file detected: "
.
color
(
:red
)
+
file
file
end
end
.
compact
if
uncompressed_files
.
empty?
puts
"All documentation images are optimally compressed!"
.
color
(
:green
)
else
warn
(
"The
#{
uncompressed_files
.
size
}
image(s) above have not been optimally compressed using pngquant."
.
color
(
:red
),
'Please run "bin/pngquant compress" and commit the result.'
)
abort
end
else
usage
end
doc/development/documentation/styleguide/index.md
View file @
ee294453
...
...
@@ -1141,7 +1141,7 @@ known tool is [`pngquant`](https://pngquant.org/), which is cross-platform and
open source. Install it by visiting the official website and following the
instructions for your OS.
GitLab has a
[
R
ake task
](
https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/tasks/pngquant.rake
)
GitLab has a
[
R
uby script
](
https://gitlab.com/gitlab-org/gitlab/-/blob/master/bin/pngquant
)
that you can use to automate the process. In the root directory of your local
copy of
`https://gitlab.com/gitlab-org/gitlab`
, run in a terminal:
...
...
@@ -1149,19 +1149,26 @@ copy of `https://gitlab.com/gitlab-org/gitlab`, run in a terminal:
been compressed:
```
shell
b
undle
exec
rake pngquant:
lint
b
in/pngquant
lint
```
-
Compress all documentation PNG images using
`pngquant`
:
```
shell
b
undle
exec
rake pngquant:
compress
b
in/pngquant
compress
```
The only caveat is that the task runs on all images under
`doc/`
, not only the
ones you might have included in a merge request. In that case, you can run the
compress task and only commit the images that are relevant to your merge
request.
-
Compress specific files:
```
shell
bin/pngquant compress doc/user/img/award_emoji_select.png doc/user/img/markdown_logo.png
```
-
Compress all PNG files in a specific directory:
```
shell
bin/pngquant compress doc/user/img
```
## Videos
...
...
lib/tasks/pngquant.rake
deleted
100644 → 0
View file @
565fba25
# frozen_string_literal: true
return
if
Rails
.
env
.
production?
require
'png_quantizator'
require
'parallel'
require_relative
'../../tooling/lib/tooling/images'
# The amount of variance (in bytes) allowed in
# file size when testing for compression size
namespace
:pngquant
do
# Returns an array of all images eligible for compression
def
doc_images
Dir
.
glob
(
'doc/**/*.png'
,
File
::
FNM_CASEFOLD
)
end
desc
'GitLab | Pngquant | Compress all documentation PNG images using pngquant'
task
:compress
do
files
=
doc_images
puts
"Compressing
#{
files
.
size
}
PNG files in doc/**"
Parallel
.
each
(
files
)
do
|
file
|
was_uncompressed
,
savings
=
Tooling
::
Image
.
compress_image
(
file
)
if
was_uncompressed
puts
"
#{
file
}
was reduced by
#{
savings
}
bytes"
end
end
end
desc
'GitLab | Pngquant | Checks that all documentation PNG images have been compressed with pngquant'
task
:lint
do
files
=
doc_images
puts
"Checking
#{
files
.
size
}
PNG files in doc/**"
uncompressed_files
=
Parallel
.
map
(
files
)
do
|
file
|
is_uncompressed
,
_
=
Tooling
::
Image
.
compress_image
(
file
,
true
)
if
is_uncompressed
puts
"Uncompressed file detected: "
.
color
(
:red
)
+
file
file
end
end
.
compact
if
uncompressed_files
.
empty?
puts
"All documentation images are optimally compressed!"
.
color
(
:green
)
else
warn
(
"The
#{
uncompressed_files
.
size
}
image(s) above have not been optimally compressed using pngquant."
.
color
(
:red
),
'Please run "bin/rake pngquant:compress" and commit the result.'
)
abort
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment