mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
fix(website): resize showcase images, tighten CI check (#6043)
* fix(website): resize images to width 640 * revert changes first... * resize images * final changes * Add to CI * refactor tests * Fix script * fix script * Final fixes * Oops * relax * fix * crop * Optimize Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
parent
37a84f86a5
commit
4578b8b4c4
201 changed files with 120 additions and 156 deletions
34
admin/scripts/image-resize.mjs
Normal file
34
admin/scripts/image-resize.mjs
Normal file
|
@ -0,0 +1,34 @@
|
|||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
import sharp from 'sharp';
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
|
||||
const images = (
|
||||
await fs.readdir(new URL('../../website/src/data/showcase', import.meta.url))
|
||||
).filter((file) => ['.png', 'jpg', '.jpeg'].includes(path.extname(file)));
|
||||
|
||||
await Promise.all(
|
||||
images.map(async (img) => {
|
||||
const imgPath = new URL(
|
||||
`../../website/src/data/showcase/${img}`,
|
||||
import.meta.url,
|
||||
).pathname;
|
||||
const data = await sharp(imgPath)
|
||||
.resize(640, 320, {fit: 'cover', position: 'top'})
|
||||
.png()
|
||||
.toBuffer();
|
||||
await fs.writeFile(imgPath.replace(/jpe?g/, 'png'), data);
|
||||
}),
|
||||
);
|
||||
|
||||
// You should also run optimizt `find website/src/data/showcase -type f -name '*.png'`.
|
||||
// This is not included here because @funboxteam/optimizt doesn't seem to play well with M1
|
||||
// so I had to run this in a Rosetta terminal.
|
||||
// TODO integrate this as part of the script
|
Loading…
Add table
Add a link
Reference in a new issue