Hexo-Neat介绍

需求

由于markdownhtml的bug,导致生成的html留有大量的空白,十分的难看,另外就是因为性能缘由,须要对jscss进行压缩。css

实现过程

前人种树

首先考虑的方案就是使用Hexo的插件来实现,包括其中的而后体验了以后并不完美,甚至报错,并无符合个人需求的。 因而我决定在其基础上自行开发。html

后人乘凉

我参考了官方插件文档,和现有插件,发现了一些问题,包括:node

官方文档过期

首先,在 node_modules 文件夹中创建文件夹,文件夹名称开头必须为 hexo-,如此一来 Hexo 才会在启动时载入不然 Hexo 将会忽略它。git

然而这一描述对于现行版本根本无效,你必须在手动在根目录的package.json中手动添加依赖才可。github

现行release版本的接口出错

若是你使用了主题,就会发现after_render:html这个钩子对于博文是没有效果的,由于hexo现行版本(3.2)的bug致使。 你须要自行更新node_modules\hexo\lib\theme\view.js来解决bug,参考官方最新view.jsnpm

插件依赖的模块接口变更

导致出错json

后人种树

在贯通了以上种种以后,我有了本身的解决方案以下。markdown

使用

安装

$ npm install hexo-neat --save

配置

To Enable Auto neat , you must config like this:

neat_enable: true

neat_html:
enable: true
exclude:

  • enable - Enable the plugin. Defaults to true.

  • exclude: Exclude files Note: there are so many params please see ‘HTMLMinifier

    • *

neat_css:
enable: true
exclude:

  • '*.min.css'

  • enable - Enable the plugin. Defaults to true.

  • exclude: Exclude files

    • *

neat_js:
enable: true
mangle: true
output:
compress:
exclude:

  • '*.min.js'

  • enable - Enable the plugin. Defaults to true.

  • mangle: Mangle file names

  • output: Output options

  • compress: Compress options

  • exclude: Exclude files

调试

作好以上几步以后,从新生成博客的时候就会自动压缩全部的html、css、js,效果应该和本博客一致。

反馈

若是你在使用的过程当中遇到问题,请在本博文下面描述,或到issues下反馈。

相关文章
相关标签/搜索