Ikeq ChengIkeq Cheng

The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts.

Inside 主题配置 - Plugins

Feb 1, 2019

plugins

于特定位置动态插入可执行的代码片段,或全局加载脚本/样式。

支持通过安装 html-minifier、babel 和 terser 来实现代码压缩。
于项目根目录执行(Hexo 根目录,非 themes/inside):

1
npm install babel-core babel-preset-env html-minifier terser --save
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
plugins:
# 内置插件
- cipher
- cipher:
placeholder: Passcode is required
excerpt: Content encrypted

# 全局加载脚本/样式
- xxx.css
- xxx.js

# 动态插入可执行的代码片段
- position: # sidebar | post | page | comments | avatar | head_begin | head_end | body_begin | body_end
# HTML 片段
template: <script>...</script>
# 也可以是相对于主题根目录的路径,例如:
template: snippets/template-1.html

position 取值详细枚举:

position 描述
sidebar 于 sidebar 导航链接下方插入
post 于 post 底部插入(tag 列表上方)
page 于 page 底部插入
comments 于评论位置插入,即 post/page 底部,可用于集成第三方评论系统
avatar 自定义头像代码
head_begin https://hexo.io/api/injector
head_end https://hexo.io/api/injector
body_begin https://hexo.io/api/injector
body_end https://hexo.io/api/injector

示例 1:在 sidebar 展示谷歌广告。

_config.yml
1
2
3
4
5
6
7
8
plugins:
- position: sidebar
template: |
<ins class="adsbygoogle"
style="display:inline-block;width:250px;height:250px"
data-ad-client=""
data-ad-slot=""></ins>
<script>(adsbygoogle = window.adsbygoogle || []).push({});</script>

示例 2:MathJax 数学公式。

_config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
plugins:
- position: head_end
template: |
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
showProcessingMessages: false,
messageStyle: 'none',
tex2jax: { inlineMath: [['$','$'], ['\\(','\\)']] }
})
</script>
- //cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML
- position: post
template: |
<script>window.MathJax && MathJax.Hub.Queue(['Typeset', MathJax.Hub, document.querySelector('main')])</script>

示例 3:方头像。

_config.yml
1
2
3
4
plugins:
- position: avatar
template: |
<img src="//www.gravatar.com/avatar/d2e25f51b78fbc6bed7db389f38631bc?s=160">

See also

Buy me a cup of milk 🥛.