Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async optimizeFile(path) {
try {
const dataUri = await DataURI(path);
const originalBuffer = await fs.readFile(path);
const optimizedBuffer = await imagemin.buffer(originalBuffer, { plugins: imageMinPlugins });
await fs.writeFile(path, optimizedBuffer);
return {
dataUri: dataUri,
originalSize: originalBuffer.length,
optimizedSize: optimizedBuffer.length
}
} catch (error) {
return { status: false, originalSize: null, optimizedSize: null }
console.error('Error: ', error);
}
}
this.mainRenderer.image = function(href, title, text) {
if (!href.match(/^https?:\/\//)) {
href = path.resolve(self.wikiPath, href)
return util.format('<img src="%s">', datauri(href))
} else {
return util.format('<img src="%s">', href)
}
}
return this
this.mainRenderer.image = function (href, title, text) {
if (!href.match(/^https?:\/\//)) {
href = path.resolve(self.wikiPath, href);
return util.format('<img src="%s">', datauri(href));
} else {
return util.format('<img src="%s">', href);
}
};
return this;
getLimedocsGeneratedImgData() {
return datauri(path.resolve(__dirname, '../assets/images/Limedocs-generated.png'))
}
'inline-image($path)': function inlineImage(filepath) {
const imagePath = getFilePath(filepath);
if (imagePath) {
return new types.String('url(\'' + datauri(imagePath) + '\')');
}
return null;
}
};
value: function getLimedocsGeneratedImgData() {
return datauri(path.resolve(__dirname, '../assets/images/Limedocs-generated.png'));
}
}, {
const toDataUri = (page: Page): string => {
const html = `
<style>
${page.css}
</style>
${page.body}
`;
const htmlBuffer = Buffer.from(html, 'utf8');
const datauri = new Datauri();
datauri.format('.html', htmlBuffer);
return datauri.content;
};
function bufferToDataUri(type, buffer) {
return new DataUri().format(type, buffer).content;
}
export default html => {
const datauri = new Datauri();
return datauri.format('.html', html).content;
};
private async createGeneratorChoice(genName: string, genPackagePath: string, packageJson: any): Promise {
let genImageUrl;
try {
genImageUrl = await datauri.promise(path.join(genPackagePath, YeomanUI.YEOMAN_PNG));
} catch (error) {
genImageUrl = defaultImage.default;
}
const genMessage = _.get(packageJson, "description", YeomanUI.defaultMessage);
const genPrettyName = titleize(humanizeString(genName));
const genHomepage = _.get(packageJson, "homepage", '');
return {
name: genName,
prettyName: genPrettyName,
message: genMessage,
homepage: genHomepage,
imageUrl: genImageUrl
};
}