mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-23 21:17:54 +02:00
refactor(lqip-loader): remove unused palette option (#6992)
This commit is contained in:
parent
395136a731
commit
d3065b8ad2
8 changed files with 20 additions and 469 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue