总述
这篇文用来介绍本站点使用的Hexo+Next主题配置及各种相关的依赖配置。
引子
什么是hexo:一个基于Node.js的博客框架
什么是next:hexo的一个主题
步骤
第一步:Node.js,npm环境配置
Windows:移步https://juejin.im/post/5a92b735f265da4e761fea22
MacOS:
1 | brew install node |
第二步:hexo的安装
Windows:这有个坑“所有hexo命令前需要加npx,不然就会:’hexo’ 不是内部或外部命令,也不是可运行的程序或批处理文件。”
1 | $ npm install hexo-cli -g |
MacOS:
1 | $ npm install hexo-cli -g |
第三步:Next的安装
这里只针对v7.8及以上版本,老的版本教程很多过时了
从源安装Next主题
1 | $ cd your-hexo-site |
改动站点根目录下的_config.yml,指定使用Next主题
1 | theme: next |
改动theme/next目录下的_config.yml,更改Next样式
1 | #scheme: Muse |
自定义样式文件
variables.styl内容是(值得一提的是,原作者的设置也在这里做出了改动)-> 这个蓝色不能覆盖左上角Blog名称,非常难看
也可以不改variables.styl 采用默认的next配色
1 | // Custom styles. |
styles.styl的内容是(用于调整主题显示宽度)
1 | $content-desktop = 97.7% |
自定义背景图
根据自定义样式原作者ExtremeGTR的博客描述:
“自定义背景图的配置还是没法解耦出来,或许只是我想不到办法而已,我的自定义配置仍然要写到NexT的js文件里,但还是有一点点变化的。
自定义[]的配置要写到\themes\next\source\js\next-boot.js里。”
刷新界面随机加载背景图
1 | $(document).ready(function () { |
点击出现小红心
在\theme\*\source\js
下新建click.js复制以下代码
1 | !function(e,t,a){function n(){c(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"),o(),r()}function r(){for(var e=0;e<d.length;e++)d[e].alpha<=0?(t.body.removeChild(d[e].el),d.splice(e,1)):(d[e].y--,d[e].scale+=.004,d[e].alpha-=.013,d[e].el.style.cssText="left:"+d[e].x+"px;top:"+d[e].y+"px;opacity:"+d[e].alpha+";transform:scale("+d[e].scale+","+d[e].scale+") rotate(45deg);background:"+d[e].color+";z-index:99999");requestAnimationFrame(r)}function o(){var t="function"==typeof e.onclick&&e.onclick;e.onclick=function(e){t&&t(),i(e)}}function i(e){var a=t.createElement("div");a.className="heart",d.push({el:a,x:e.clientX-5,y:e.clientY-5,scale:1,alpha:1,color:s()}),t.body.appendChild(a)}function c(e){var a=t.createElement("style");a.type="text/css";try{a.appendChild(t.createTextNode(e))}catch(t){a.styleSheet.cssText=e}t.getElementsByTagName("head")[0].appendChild(a)}function s(){return"rgb("+~~(255*Math.random())+","+~~(255*Math.random())+","+~~(255*Math.random())+")"}var d=[];e.requestAnimationFrame=function(){return e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(e){setTimeout(e,1e3/60)}}(),n()}(window,document); |
在\themes\*\layout\_layout.swig
文件末尾添加
1 | <!-- 页面点击小红心 --> |
改动主题配置文件_config.yml
激活gitalk
1 | # Multiple Comment System Support |
1 | # Gitalk |
第四步:插件配置
这里是hexo插件全家桶的页面,以下推荐:
hexo-deploy-git插件配置
用途:hexo deploy一键部署
1 | $ npm install hexo-deployer-git --save |
在Hexo站点下的_config.yml文件添加
1 | # Deployment |
symbols_count_time插件配置
用途:计算字数和阅读时间
1 | $ npm install hexo-symbols-count-time |
在Hexo站点下的_config.yml文件添加
1 | symbols_count_time: |
hexo-generator-searchdb插件配置
用途:站点内搜索
1 | $ npm install hexo-generator-searchdb --save |
!注意此处不要-g全局安装
在Hexo站点下的_config.yml文件添加
1 | search: |
在Next主题的_config.yml文件修改local search
把enable: false修改为true
hexo-helper-live2d插件配置
用途:萌萌哒
1 | $ npm install hexo-helper-live2d |
可以上github找找喜欢的模型,以下使用
在Hexo站点下的_config.yml文件添加
1 | live2d: |
在Hexo站点根目录下新建文件夹live2d_models
然后在node_modules
文件夹下找到下载好的模型,拷贝到live2d_models
1 | $ cd <hexo-root-path> |
travis-CI配置
详见https://hexo.io/docs/github-pages.html,作者没配直接本地hexo generate && hexo deploy
参考
[1] https://juejin.im/post/5a92b735f265da4e761fea22
[2] https://theme-next.iissnan.com/getting-started.html
[3] https://hexo.io/zh-cn/index.html
[4] https://extremegtr.github.io/2017/09/27/Customize-NexT-Gemini-theme/
[5] https://hexo.io/zh-cn/docs/one-command-deployment.html
[6] https://hexo.io/docs/github-pages.html
[7] https://hexo.io/plugins/