mirror of https://github.com/curbengh/hexo-yam
fix(svg): svgo@3 now throws error
- cleanupIDs -> cleanupIds - https://github.com/svg/svgo/releases/tag/v3.0.0
This commit is contained in:
parent
9c8a228e09
commit
a6e2ea0879
|
@ -133,7 +133,7 @@ minify:
|
||||||
# Retain comments
|
# Retain comments
|
||||||
removeComments: false
|
removeComments: false
|
||||||
# Do not remove unused ID attributes
|
# Do not remove unused ID attributes
|
||||||
cleanupIDs: false
|
cleanupIds: false
|
||||||
```
|
```
|
||||||
- For more options, see [svgo](https://github.com/svg/svgo).
|
- For more options, see [svgo](https://github.com/svg/svgo).
|
||||||
- **globOptions** - See [globbing](#globbing) section.
|
- **globOptions** - See [globbing](#globbing) section.
|
||||||
|
|
|
@ -152,12 +152,16 @@ function minifySvg () {
|
||||||
assetPath.on('data', (chunk) => (assetTxt += chunk))
|
assetPath.on('data', (chunk) => (assetTxt += chunk))
|
||||||
assetPath.on('end', async () => {
|
assetPath.on('end', async () => {
|
||||||
if (assetTxt.length) {
|
if (assetTxt.length) {
|
||||||
const { data, error } = svgOptimize(assetTxt, { ...options, plugins })
|
try {
|
||||||
if (data) {
|
const { data } = svgOptimize(assetTxt, { ...options, plugins })
|
||||||
if (verbose) logFn.call(this, assetTxt, data, path, 'svg')
|
if (data) {
|
||||||
resolve(route.set(path, data))
|
if (verbose) logFn.call(this, assetTxt, data, path, 'svg')
|
||||||
} else if (error) {
|
resolve(route.set(path, data))
|
||||||
reject(new Error(`Path: ${path}\n${error}`))
|
} else {
|
||||||
|
reject(new Error(`Path: ${path}\nEmpty svg input`))
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
reject(new Error(`Path: ${path}\n${err}`))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
|
|
|
@ -71,7 +71,7 @@ describe('svg', () => {
|
||||||
|
|
||||||
test('option', async () => {
|
test('option', async () => {
|
||||||
const customOpt = {
|
const customOpt = {
|
||||||
cleanupIDs: false
|
cleanupIds: false
|
||||||
}
|
}
|
||||||
hexo.config.minify.svg.plugins = customOpt
|
hexo.config.minify.svg.plugins = customOpt
|
||||||
plugins = [{
|
plugins = [{
|
||||||
|
@ -117,10 +117,14 @@ describe('svg', () => {
|
||||||
const input = '{}'
|
const input = '{}'
|
||||||
hexo.route.set(path, input)
|
hexo.route.set(path, input)
|
||||||
|
|
||||||
const { error } = svgOptimize(input, { plugins })
|
let expected
|
||||||
|
try {
|
||||||
expect(error).toBeDefined()
|
svgOptimize(input, { plugins })
|
||||||
await expect(s()).rejects.toThrow(`Path: ${path}\n${error}`)
|
} catch (err) {
|
||||||
|
expected = err
|
||||||
|
}
|
||||||
|
expect(expected).toBeDefined()
|
||||||
|
await expect(s()).rejects.toThrow(`Path: ${path}\n${expected}`)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('include - exclude *.min.svg by default', async () => {
|
test('include - exclude *.min.svg by default', async () => {
|
||||||
|
|
Loading…
Reference in New Issue