hexo主题Icarus浅度修改教程
难得放假两天(还是因为来台风),结果so又没得颓,实在是闲的没事干,随便写写博吧,说不定还能当备忘录使……
Icarus实在是hexo的一款非常优秀的主题。它具有极高的自由度和兼容性,并且功能也很齐全。不过还是有一些美中不足的地方,其中一部分被我摸索(瞎蒙)着解决了(蒙中了)。
2021.1.6 注:由于 Icarus 3.0 及以上版本的修改,现在侧边栏小部件的相关代码需要到 \hexo\node_modules\hexo-component-inferno\lib\view\widget\
这个文件夹下去找,语言也从 EJS 变成了 JS,但是方法还是大同小异的。
侧边栏
侧边栏“最新文章”栏
这个东西啊,个人感觉真的没什么实用性。可以把它改成类似于优秀文章推广之类的,就比较好了。
打开\icarus\layout\widget\recent_posts.ejs
,找到:
1 | <% site.posts.sort('date', -1).limit(5).each(post => { %> |
一行,改成:
1 | <% site.posts.sort('priority', -1).limit(5).each(post => { %> |
然后只需要在每篇文章上面的配置里加上priority: xxx
,其中xxx
是你自由确定的优先级(1,2,3之类的数字),就可以自由更改显示在那里的文章了。
当然也可以调整显示在那里的文章数量,像这样:
1 | <% site.posts.sort('priority', -1).limit(10).each(post => { %> |
就是显示10篇文章。10也可以改成其它数字。
然后更改栏目名称。打开\icarus\languages\zh-CN.yml
,找到:
1 | recents: '最新文章' |
一句,把“最新文章”替换成“阅读推荐”就好了。
侧边栏“目录”栏自动编号
目录本人一般会手动编号,所以这个自动编号功能对我来说并不友好。所以加个开关好了。
打开\icarus\layout\widget\toc.ejs
,把整个文件复制一遍然后粘贴到最后面。然后会有两行像这样的语句:
1 | <% if (get_config('toc') === true && (post.layout === 'page' || post.layout === 'post')) { |
把第一句改成:
1 | <% if (get_config('toc_auto_num') === false && get_config('toc') === true && (post.layout === 'page' || post.layout === 'post')) { |
第二句改成:
1 | <% if ((get_config('toc_auto_num') === true || !has_config('toc_auto_num')) && get_config('toc') === true && (post.layout === 'page' || post.layout === 'post')) { |
然后找到第一个if
语段中如下的位置:
1 | <span class="has-mr-6">${toc.index}</span> |
把它注释掉:
1 | <!--span class="has-mr-6">${toc.index}</span--> |
然后就可以通过文章前面的toc_auto_num: true/false
来控制是不是开启自动编号。
侧边栏“资料”栏关注按钮
这个东西对我来说也没什么用处。把它链接到关于页面之后,在\icarus\languages\zh-CN.yml
里,找到:
1 | follow: '关注' |
一句,改成:
1 | follow: '关于' |
然后更改页面打开方式为同一页面跳转,具体做法是打开\icarus\layout\widget\profile.ejs
,找到:
1 | <a class="level-item button is-link is-rounded" href="<%= url_for(widget.follow_link) %>" target="_blank"> |
把target="_blank"
属性删掉就好了。
站底
站底备案号及链接
这个Icarus貌似并没有预留接口……只能自己写了。
打开\icarus\layout\common\footer.ejs
,找到:
1 | <% if (has_config('plugins.busuanzi') ? get_config('plugins.busuanzi') : false) { %> |
一段,在后面添加:
1 | <br> |
然后更改样式文件。打开\icarus\source\css\style.styl
,找到这样的两段:
1 | .has-link-black-ter |
1 | .has-link-black-ter |
把这两段分别扩充成:
1 | .has-link-black-ter |
1 | .has-link-black-ter |
就好了。
站底字数统计
这个主题是没有集成的,所以首先安插件:
1 | $ npm i --save hexo-wordcount |
然后打开\icarus\layout\common\footer.ejs
,找到:
1 | <% if (has_config('plugins.busuanzi') ? get_config('plugins.busuanzi') : false) { %> |
一段,在后面添加:
1 | <br> |
当然,如果想和备案号放在一块,可以这样添加:
1 | <br> |
站点推送
Sitemap生成
这个的方法对与所有hexo博客来说都是一样的吧…装个插件就好了:
1 | $ npm install hexo-generator-sitemap --save |
百度自动推送
这个貌似并没有什么用处…但是有总比没有好。
需要从baidu上搞到的推送代码,这个代码可能跟下面这份一样或相似:
1 | <script> |
然后打开\icarus\layout\common\scripts.ejs
,在顶部添加上面的代码就好了。
其他
markdown行间代码样式
emm,我还真不知道这个叫什么,其实就是abcde
这个东西。这个默认的是红色字体,个人感觉不好看。其实可以改。
打开\icarus\source\css\style.styl
,找到:
1 | code |
1 | code |
其实就是本博客现在呈现的行间代码样式。
Sharthis分享插件
emm,这个毕竟是国外的东西,在国内不怎么实用。但是它好看啊…
想在站底插入这样一个分享按钮,得先注册一个Sharethis账号,然后获得一个javascript代码的url。这个是免费的。
然后主题里大概集成了这个,但是貌似存在BUG导致hexo无法渲染。于是还得自己加。
打开\icarus\layout\common\article.ejs
,找到:
1 | <div class="level is-mobile"> |
一段,在下面添加:
1 | <% if (!index |
隐藏首页文章
打开\icarus\layout\index.ejs
,把它改成这样:
1 | <% page.posts.each(function(post){ %> |
然后通过文章表头的unshown: true/false
控制就好了。
在搜索中隐藏文章
Icarus的insight搜索基于一个本地生成的content.json。所以只要让页面不出现在这个里面就好了。
打开\icarus\includes\generators\insight.js
,找到这样一段:
1 | function postMapper(post) { |
在前面加上一段:
1 | function postMapper(post) { |
hexo主题Icarus浅度修改教程