refactor(lqip-loader): remove unused palette option (#6992)

This commit is contained in:
Joshua Chen 2022-03-25 10:23:42 +08:00 committed by GitHub
parent 395136a731
commit d3065b8ad2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 469 deletions

View file

@ -6,10 +6,8 @@
*/
import logger from '@docusaurus/logger';
import Vibrant from 'node-vibrant';
import path from 'path';
import sharp from 'sharp';
import {toPalette, toBase64} from './utils';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const {version} = require('../package.json');
@ -22,6 +20,13 @@ const SUPPORTED_MIMES: Record<string, string> = {
png: 'image/png',
};
/**
* it returns a Base64 image string with required formatting
* to work on the web (<img src=".." /> or in CSS url('..'))
*/
const toBase64 = (extMimeType: string, data: Buffer): string =>
`data:${extMimeType};base64,${data.toString('base64')}`;
export async function base64(file: string): Promise<string> {
let extension = path.extname(file);
extension = extension.split('.').pop()!;
@ -39,14 +44,3 @@ export async function base64(file: string): Promise<string> {
throw err;
}
}
export async function palette(file: string): Promise<string[]> {
const vibrant = new Vibrant(file, {});
try {
const pal = await vibrant.getPalette();
return toPalette(pal);
} catch (err) {
logger.error`Generation of color palette failed for image path=${file}.`;
throw err;
}
}