chenzhutian / hexo-all-minifier

A plugin for Hexo that optimizes HTML, CSS, JS and imagages, and it can optionally deploys your blog.
MIT License
277 stars 30 forks source link

image optimizer breaks my svg #20

Closed fabsenet closed 6 years ago

fabsenet commented 7 years ago

Hi,

I have a svg file containing image icon data:

<svg style="position: absolute; width: 0; height: 0; overflow: hidden;" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<symbol id="icon-clock" viewBox="0 0 30 32">
<title>clock</title>
<path d="M14.848 5.28q-4.416 0-7.552 3.136t-3.136 7.584 3.136 7.584 7.552 3.104 7.584-3.104 3.136-7.584-3.136-7.584-7.584-3.136zM14.88 1.696q5.888 0 10.080 4.192t4.192 10.112-4.192 10.080-10.080 4.224-10.112-4.224-4.192-10.080 4.192-10.112 10.112-4.192zM19.712 18.272l-2.56 2.56-3.488-3.552q-0.608-0.544-0.608-1.312v-7.136h3.616v6.368z"></path>
</symbol>
<symbol id="icon-calendar" viewBox="0 0 30 32">
<title>calendar</title>
<path d="M2.272 29.728h5.152v-5.152h-5.152v5.152zM8.576 29.728h5.696v-5.152h-5.696v5.152zM2.272 23.424h5.152v-5.696h-5.152v5.696zM8.576 23.424h5.696v-5.696h-5.696v5.696zM2.272 16.576h5.152v-5.152h-5.152v5.152zM15.424 29.728h5.728v-5.152h-5.728v5.152zM8.576 16.576h5.696v-5.152h-5.696v5.152zM22.272 29.728h5.152v-5.152h-5.152v5.152zM15.424 23.424h5.728v-5.696h-5.728v5.696zM9.152 8v-5.152q0-0.224-0.192-0.384t-0.384-0.192h-1.152q-0.224 0-0.384 0.192t-0.192 0.384v5.152q0 0.224 0.192 0.416t0.384 0.16h1.152q0.224 0 0.384-0.16t0.192-0.416zM22.272 23.424h5.152v-5.696h-5.152v5.696zM15.424 16.576h5.728v-5.152h-5.728v5.152zM22.272 16.576h5.152v-5.152h-5.152v5.152zM22.848 8v-5.152q0-0.224-0.16-0.384t-0.416-0.192h-1.12q-0.224 0-0.416 0.192t-0.16 0.384v5.152q0 0.224 0.16 0.416t0.416 0.16h1.12q0.256 0 0.416-0.16t0.16-0.416zM29.728 6.848v22.88q0 0.928-0.704 1.6t-1.6 0.672h-25.152q-0.928 0-1.6-0.672t-0.672-1.6v-22.88q0-0.928 0.672-1.6t1.6-0.672h2.304v-1.728q0-1.184 0.832-2.016t2.016-0.832h1.152q1.184 0 2.016 0.832t0.832 2.016v1.728h6.848v-1.728q0-1.184 0.864-2.016t2.016-0.832h1.12q1.184 0 2.048 0.832t0.832 2.016v1.728h2.272q0.928 0 1.6 0.672t0.704 1.6z"></path>
</symbol>
<symbol id="icon-author" viewBox="0 0 23 32">
<title>author</title>
<path d="M11.296 15.968q4.448 0 7.584 3.168t3.136 7.552q0 1.504-1.056 2.56t-2.528 1.056h-14.272q-1.472 0-2.528-1.056t-1.056-2.56q0-4.416 3.136-7.552t7.584-3.168zM5.952 7.040q0-5.344 5.344-5.344 5.376 0 5.376 5.344 0 5.376-5.376 5.376-5.344 0-5.344-5.376z"></path>
</symbol>

<symbol id="icon-twitter" viewBox="0 0 30 32">
<title>twitter</title>
<path d="M28.928 7.296q-1.184 1.728-2.88 2.976 0 0.256 0 0.736 0 2.336-0.672 4.64t-2.048 4.448-3.296 3.744-4.608 2.624-5.792 0.96q-4.832 0-8.832-2.592 0.608 0.064 1.376 0.064 4.032 0 7.168-2.464-1.888-0.032-3.36-1.152t-2.048-2.848q0.608 0.096 1.088 0.096 0.768 0 1.536-0.192-2.016-0.416-3.328-1.984t-1.312-3.68v-0.064q1.216 0.672 2.624 0.736-1.184-0.8-1.888-2.048t-0.704-2.752q0-1.568 0.8-2.912 2.176 2.656 5.248 4.256t6.656 1.76q-0.16-0.672-0.16-1.312 0-2.4 1.696-4.064t4.064-1.696q2.528 0 4.224 1.824 1.952-0.384 3.68-1.408-0.672 2.048-2.56 3.2 1.664-0.192 3.328-0.896z"></path>
</symbol>

<symbol id="icon-github" viewBox="0 0 27 32">
<title>github</title>
<path d="M13.728 2.272q3.712 0 6.88 1.856t4.992 4.992 1.824 6.88q0 4.48-2.624 8.064t-6.752 4.96q-0.48 0.096-0.704-0.128t-0.224-0.544q0-0.032 0-1.376t0-2.4q0-1.728-0.928-2.528 1.024-0.096 1.824-0.32t1.696-0.704 1.44-1.184 0.96-1.856 0.352-2.688q0-2.144-1.408-3.68 0.672-1.632-0.128-3.648-0.512-0.16-1.472 0.192t-1.632 0.8l-0.672 0.416q-1.664-0.48-3.424-0.48t-3.456 0.48q-0.256-0.192-0.736-0.48t-1.504-0.704-1.504-0.224q-0.8 2.016-0.16 3.648-1.408 1.536-1.408 3.68 0 1.504 0.384 2.656t0.928 1.888 1.44 1.184 1.664 0.704 1.824 0.32q-0.672 0.64-0.864 1.856-0.384 0.16-0.8 0.256t-1.024 0.096-1.152-0.384-0.992-1.12q-0.352-0.576-0.864-0.928t-0.896-0.448l-0.352-0.032q-0.384 0-0.512 0.064t-0.096 0.224 0.16 0.256 0.224 0.192l0.128 0.096q0.384 0.192 0.768 0.672t0.576 0.928l0.192 0.416q0.224 0.672 0.768 1.088t1.184 0.544 1.248 0.096 0.992-0.032l0.416-0.096q0 0.704 0 1.6t0.032 0.96q0 0.32-0.256 0.544t-0.704 0.128q-4.128-1.376-6.752-4.96t-2.624-8.064q0-3.744 1.856-6.88t4.96-4.992 6.912-1.856zM5.184 21.984q0.064-0.128-0.096-0.224-0.192-0.032-0.256 0.032-0.032 0.128 0.128 0.224t0.224-0.032zM5.76 22.592q0.128-0.096-0.032-0.288-0.192-0.16-0.288-0.064-0.128 0.096 0.032 0.288t0.288 0.064zM6.272 23.392q0.192-0.128 0-0.352-0.128-0.224-0.288-0.096-0.16 0.096 0 0.32t0.288 0.128zM7.040 24.128q0.128-0.128-0.064-0.32-0.224-0.224-0.352-0.064-0.16 0.16 0.064 0.352 0.192 0.192 0.352 0.032zM8.064 24.576q0.032-0.192-0.256-0.288-0.256-0.064-0.32 0.128t0.224 0.288q0.256 0.096 0.352-0.128zM9.184 24.672q0-0.224-0.32-0.192-0.288 0-0.288 0.192 0 0.224 0.32 0.192 0.288 0 0.288-0.192zM10.208 24.512q-0.032-0.224-0.32-0.16-0.288 0.032-0.256 0.256t0.32 0.128 0.256-0.224z"></path>
</symbol>

<symbol id="icon-facebook" viewBox="0 0 18 32">
<title>facebook</title>
<path d="M17.12 0.224v4.704h-2.784q-1.536 0-2.080 0.64t-0.544 1.92v3.392h5.248l-0.704 5.28h-4.544v13.568h-5.472v-13.568h-4.544v-5.28h4.544v-3.904q0-3.328 1.856-5.152t4.96-1.824q2.624 0 4.064 0.224z"></path>
</symbol>

<symbol id="icon-mail" viewBox="0 0 32 32">
<title>mail</title>
<path d="M29.728 26.848v-13.696q-0.576 0.64-1.248 1.152-4.768 3.68-7.616 6.048-0.896 0.768-1.472 1.184t-1.536 0.896-1.824 0.416h-0.064q-0.832 0-1.824-0.416t-1.536-0.896-1.472-1.184q-2.816-2.368-7.616-6.048-0.672-0.512-1.248-1.152v13.696q0 0.224 0.192 0.416t0.384 0.16h26.304q0.224 0 0.384-0.16t0.192-0.416zM29.728 8.096v-0.448t-0.032-0.224-0.032-0.224-0.096-0.16-0.16-0.128-0.256-0.064h-26.304q-0.224 0-0.384 0.192t-0.192 0.384q0 3.008 2.656 5.088 3.424 2.688 7.136 5.632 0.128 0.096 0.64 0.544t0.8 0.672 0.8 0.544 0.896 0.512 0.768 0.16h0.064q0.352 0 0.768-0.16t0.896-0.512 0.8-0.544 0.8-0.672 0.64-0.544q3.712-2.944 7.168-5.632 0.96-0.768 1.792-2.080t0.832-2.336zM32 7.424v19.424q0 1.184-0.832 2.016t-2.016 0.864h-26.304q-1.152 0-2.016-0.864t-0.832-2.016v-19.424q0-1.184 0.832-2.016t2.016-0.832h26.304q1.184 0 2.016 0.832t0.832 2.016z"></path>
</symbol>

</defs>
</svg>

and after optimization, all that is left is:

<svg style="position:absolute;width:0;height:0" xmlns="http://www.w3.org/2000/svg" overflow="hidden"/>

not sure, what you can do, because you only call the other optimizers, but is it possible to add an exclude option for the image_minifier ?

here is my relevant config so far with exclude obviously not working:

html_minifier:
  enable: true
  ignore_error: false
  exclude:

css_minifier:
  enable: true
  exclude: 
    - '*.min.css'

js_minifier:
  enable: true
  mangle: true
  output:
  compress:
  exclude: 
    - '*.min.js'

image_minifier:
  enable: true
  interlaced: false
  multipass: false
  optimizationLevel: 2
  pngquant: true
  progressive: false
  exclude: 
    - '*.svg'
ghost commented 6 years ago

same

chenzhutian commented 6 years ago

fix, check this commit for detail e91340b52be74e54b8f61d21f648815aea72f705 Please try the latest version v0.3.2 Many thanks