Skip to content

Avoid trying to optimize unsupported formats #5

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

Open
wants to merge 1 commit 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
build
node_modules
node_modules
package-lock.json
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"authors": ["Kornel Lesiński", "Ale Muñoz"],
"authors": [
"Kornel Lesiński",
"Ale Muñoz"
],
"license": "MIT",
"repository": "https://github.com/BohemianCoding/sketch-image-compressor",
"devDependencies": {
Expand Down
26 changes: 24 additions & 2 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ function exportAndCompress(context){
}
render.data().writeToFile_atomically(currentExport.path, true)
}
// Filter out items that can't be optimized
const optimizableExports = filteredExports(exports);
// …and then we'll be able to compress them :)
const urlsToCompress = getURLsToCompress(exports)

const urlsToCompress = getURLsToCompress(optimizableExports);
if (urlsToCompress.length > 0) {
runImageOptim(context, urlsToCompress, false);
} else {
Expand All @@ -96,8 +99,27 @@ function exportAndCompress(context){
}
}

function filteredExports(exports) {
var optimizableExports = NSMutableArray.new();

for (var i = 0; i < exports.count(); i++) {
if (!exports[i].request.format().isEqualToString("pdf")
&& !exports[i].request.format().isEqualToString("webp")
&& !exports[i].request.format().isEqualToString("eps")
&& !exports[i].request.format().isEqualToString("svg")) {
optimizableExports.addObject(exports[i]);
}
}

return optimizableExports;
}

function compressAutomatically(context){
const urlsToCompress = getURLsToCompress(context.actionContext.exports)
const exports = context.actionContext.exports;
// Filter out items that can't be optimized
const optimizableExports = filteredExports(exports);

const urlsToCompress = getURLsToCompress(optimizableExports)
runImageOptim(context, urlsToCompress, true)
}

Expand Down