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

fix: copy static image as it is if image compression fail #887

Merged
merged 2 commits into from
Aug 4, 2018
Merged
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Thank you to the following contributors who helped with this release:
- Docusaurus own search will now search the docs in the correct language & version [\#859](https://github.com/facebook/Docusaurus/pull/859)
- Fix phrase emphasis not italicized [\#850](https://github.com/facebook/Docusaurus/pull/850)
- Blogpost summary for blog feed is now properly truncated [\#880](https://github.com/facebook/Docusaurus/pull/880)
- Fix failure to copy static image if image compression fail [\#887](https://github.com/facebook/Docusaurus/pull/887)

**Chore and Maintenance**
- Remove unused files [\#881](https://github.com/facebook/Docusaurus/pull/881)
Expand Down
12 changes: 7 additions & 5 deletions lib/server/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,9 @@ async function execute() {
!commander.skipImageCompression
) {
const parts = normalizedFile.split(`${sep}static${sep}`);
const targetDirectory = join(
buildDir,
parts[1].substring(0, parts[1].lastIndexOf(sep))
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this always wrong? I see you removed this from your update.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not really wrong but this is not declarative enough. I think using function from nodejs path clearly shows the intent.

const targetDirectory = path.dirname(targetFile);

The previous code in the below section

mkdirp.sync(path.dirname(targetDirectory));

is wrong though. It should be

mkdirp.sync(targetDirectory);

);
mkdirp.sync(path.dirname(targetDirectory));
const targetFile = join(buildDir, parts[1]);
const targetDirectory = path.dirname(targetFile);
mkdirp.sync(targetDirectory);
imagemin([normalizedFile], targetDirectory, {
use: [
imageminOptipng(),
Expand All @@ -261,6 +259,10 @@ async function execute() {
}),
imageminGifsicle(),
],
}).catch(error => {
// if image compression fail, just copy it as it is
console.error(error);
fs.copySync(normalizedFile, targetFile);
});
} else if (!fs.lstatSync(normalizedFile).isDirectory()) {
const parts = normalizedFile.split(`${sep}static${sep}`);
Expand Down