Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

Fix: Using Heigth and Width Different on Icon #93

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 21 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 27 additions & 4 deletions src/icons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ function sanitizeIcon (iconSnippet) {
const arr = parseArray(iconSnippet.size || iconSnippet.sizes)
if (!arr) throw new IconError('Unknown icon sizes.')
const sizes = []
for (let size of arr) sizes.push(+size || parseInt(size))
for (let size of arr) sizes.push(size)

return {
src: iconSnippet.src,
sizes,
Expand All @@ -27,7 +28,16 @@ function sanitizeIcon (iconSnippet) {
}

function processIcon (currentSize, icon, buffer, mimeType, publicPath, shouldFingerprint) {
const dimensions = `${currentSize}x${currentSize}`

let xDimension = currentSize, yDimension = currentSize, tmp;
if (typeof currentSize === 'string') {
tmp = currentSize.split('x');
xDimension = Number(tmp[0]);
yDimension = Number(tmp[1]);
}

const dimensions = `${xDimension}x${yDimension}`

const fileName = shouldFingerprint ? `icon_${dimensions}.${generateFingerprint(buffer)}.${mime.getExtension(mimeType)}` : `icon_${dimensions}.${mime.getExtension(mimeType)}`
const iconOutputDir = icon.destination ? joinURI(icon.destination, fileName) : fileName
const iconPublicUrl = joinURI(publicPath, iconOutputDir)
Expand Down Expand Up @@ -61,7 +71,8 @@ function process (sizes, icon, cachedIconsCopy, icons, assets, fingerprint, publ
}

const size = sizes.pop()
if (size > 0) {

if (size > 0 || typeof size === 'string') {
const mimeType = mime.getType(icon.src)
if (!supportedMimeTypes.includes(mimeType)) {
let buffer
Expand All @@ -77,8 +88,20 @@ function process (sizes, icon, cachedIconsCopy, icons, assets, fingerprint, publ
}

jimp.read(icon.src, (err, img) => {

if (err) throw new IconError(`It was not possible to read '${icon.src}'.`)
img.resize(size, size).getBuffer(mimeType, (err, buffer) => {
let x = size, y = size, tmp;

if (typeof size === 'string'){
tmp = size.split('x');

x = Number(tmp[0]);
y = Number(tmp[1]);
}



img.resize(x, y).getBuffer(mimeType, (err, buffer) => {
if (err) throw new IconError(`It was not possible to retrieve buffer of '${icon.src}'.`)
const processedIcon = processIcon(size, icon, buffer, mimeType, publicPath, fingerprint)
icons.push(processedIcon.manifestIcon)
Expand Down
2 changes: 1 addition & 1 deletion src/injector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const voidTags = [
'wbr'
]

const appleTags = {
const appleTags = {
'apple-touch-icon': 'link',
'apple-touch-startup-image': 'link',
'apple-mobile-web-app-title': 'meta',
Expand Down