如何使hexo显得自己更有逼格(三)——自定义与优化

Github page原文链接:https://aak1247.github.io/hexo-next-3.html

Coding page镜像链接:http://aak1247.coding.me/hexo-next-3.html

博客地址: 黑境​​​​

 

 

优化策略

考虑到站点的稳定性和加载速度等,可以使用延迟加载图片等方式提高响应速度。hexo还提供了一个最小化静态文件的插件hexo-all-minifier可以压缩html、css、js和图像文件,删除文件中多余的换行等。通过在站点配置文件中加入以下配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
html_minifier:
  enable: true
  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: false
  progressive: false

 

然后安装插件(通过在package.json中加入"hexo-all-minifier": "^0.0.14"依赖项)即可实现压缩静态内容。

自定义方法

以next主题为例,可以直接修改.swig文件修改对应页面,通过修改page.swig文件可以更改页面的主体内容模板,通过page.type字段可以进行页面类型的定义和判断。可以自定义新的type加入判断即可。自定义新的.swig文件,通过

1
{% include xxx %}

 

引入。css和js文件可以在next/layout/_partials/custom_head.swig中引入。建议对于已有的样式定义更高优先级的样式进行覆盖,不建议直接修改原样式。另外css的修改可以直接在next/source/css/_custom/custom.styl中添加。

侧边栏的链接图标可以在next/layout/_macro/sidebar.swig中修改,fontawesome对于国内平台的支持不是很全面,可以使用阿里巴巴矢量图库添加更多图标。在文件中找到如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<div class="links-of-author motion-element">
  {% if theme.social %}
    {% for name, link in theme.social %}
      <span class="links-of-author-item">
        <a href="{{ link }}" target="_blank" title="{{ name }}">
          {% if theme.social_icons.enable %}
  //这里是修改的结果:
            <svg class="icon-symbol" aria-hidden="true">
              <use xlink:href="#icon-{{theme.social_icons[name] | default('link') | lower}}"></use>
            </svg>
  //以上
          {% endif %}
          {{ name }}
        </a>
      </span>
    {% endfor %}
  {% endif %}
</div>

然后在custom.styl中加入.icon-symbol的样式表:

1
2
3
4
5
6
.icon-symbol {
  width: 1em; height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}

随后在登录阿里巴巴矢量图库创建应用,并引入图库,获取到产生svg图像的js代码,并引入next/layout/_partials/custom_head.swig ,即可使用与原生fontawesome图标类似的方式定义图标。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值