本文介绍Next主题相关的一些配置
1. 常用命令
1 | hexo new "postName" |
2. live2d看板娘
GitHub - xiazeyu/live2d-widget-models: The model library for live2d-widget.js
安装模块
1 | npm install --save hexo-helper-live2d |
安装模型
1 | npm install live2d-widget-model-hibiki |
所有模型列表
1 | live2d-widget-model-chitose |
在主目录下新建一个live2d_models文件夹,将node_modules文件夹下live2d-widget-model-hibiki复制到live2d_models文件夹中
在主配置文件_config.yml添加配置
1 | # 看板娘参数配置 |
接着运行hexo s查看效果
3. hexo的next配置版权信息
在每篇文章末尾默认增加文章作者、链接以及版权信息,是部分博主所需要的,而Hexo的next(v7.1.0)主题默认就集成了该功能,只需要在设置中启用即可。配置方式简要描述,实际效果与下面信息类似。
1 | 本文作者: 何宇泽 |
配置步骤
修改next主题的配置文件(./themes/next/_config.yml),搜索到creative_commons:
标签,
- sidebar参数表示在侧边栏有一个版权的图片链接,
- post参数表示在每一篇文章末尾自动增加本文作者、本文链接、版权声明三个信息,
- language参数表示点击链接后显示的版权信息的语言。
1 | creative_commons: |
如果想个性化配置版权信息,可修改配置文件(./themes/next/layout/_partials/post/post-copyright.swig),如果想修改显示的样式可修改配置文件(./themes/next/source/css/_common/components/post/post-copyright.styl) 。
4. 修改文章底部的那个带#号的标签
修改模板/themes/next/layout/_macro/post.swig
,搜索 rel="tag">#
,将 # 换成 <i class="fa fa-tag"></i>
1 | <div class="post-tags"> |
修改为
1 | <div class="post-tags"> |
5. 右上角添加fork me on github
在主配置文件中打开github_banner配置,permalink修改为自己的github地址
1 | github_banner: |
6. Hexo为标题自动添加序号
在 Hexo 中,使用了一个 hexo 的插件, Hexo 根目录执行下面的命令
1 | npm install hexo-heading-index --save |
然后在 Hexo 根目录的 _config.yml 最后加上下面的配置:
1 | heading_index: |
7. hexo 取消“文章目录”的自动编号
修改主题配置文件那里的number
为false
themes/next/_config.yml
1 | toc: |
8. 短地址
每次从博客分享文章给别人都很苦恼,Hexo 默认生成的链接太长了,而且一旦文章名字改变,链接也跟着改变。有没有什么方法让地址尽量短小精悍,同时永久化呢?
感谢 rozbo/hexo-abbrlink,完美解决此痛点。
使用方法也很简单:
- 在 Hexo 博客根目录,执行
npm install hexo-abbrlink --save
- 在主配置文件
_config.yml
写入
1 | # 更改 permalink 值 |
9. 自动部署hexo博客到阿里云服务器
https://blog.csdn.net/weixin_33790053/article/details/91366365
之前博客是托管在GitHub Page,访问速度不太乐观,后来买了台阿里云ECS,把博客迁了过来,下面介绍如何将博客直接推送到阿里云ECS(CentOS系统),实现自动部署。
9.1. 环境
- 博客网站在服务器上已经搭建好并且可以正常访问;
- 服务器上已经安装git;
- 本地hexo能够正常运行。
9.2. 思路
在阿里云服务器上搭建git仓库,本地博客目录下运行hexo g -d
生成静态文件,并提交到git仓库,从而触发git hook,最后再执行bash命令将文件拷贝到博客网站目录。
9.3. 创建仓库
在阿里云服务器上创建git仓库,注意不要漏掉--bare
参数。
1 | mkdir /www/blog.git && cd /www/blog.git |
9.4. Hexo配置
修改本地博客目录下的_config.yml
配置,其中xx.xxx.xx.xxx
是你的服务器ip地址,/www/blog.git
是你上一步创建的git仓库路径,master
是分支。
1 | deploy: |
9.5. 插件安装
此插件的作用是执行deploy时,将hexo生成的静态文件提交到_config.yml
配置中的deploy.repo
地址,即root@xx.xxx.xx.xxx:/www/blog.git,master
。
1 | npm install hexo-deployer-git --save |
9.6. 自动部署
本地的deploy命令只是把静态文件提交到git仓库,既然有git hooks,那么我们可以在有文件提交上来时,再将文件拷贝到博客网站目录。 进入到git仓库hooks目录,并创建钩子post-receive
。
1 | cd /www/blog.git/hooks |
然后输入下面脚本:
1 |
|
其中/www/blog.git
为仓库路径,/www/blog
为你的博客网站路径,/www/tmp/blog
是临时目录,git会先将文件拉到临时目录,然后再将所有文件拷贝到博客网站目录/www/blog
。
更改目录权限:
1 | chmod +x post-receive |
9.7. 运行
完成上述步骤之后,就可以测试一下了,在本地博客目录下运行hexo g -d
,此时可能还需要输入服务器密码,最后输出以下结果说明部署成功:
1 | ... |
10. 修改主题页面布局为圆角
打开文件,路径:\themes\next\source\css_variables\Gemini.styl ,添加以下代码:
1 | // 修改主题页面布局为圆角 |
11. 增加 canvas 粒子时钟
在 /themes/next/layout/_custom/
目录下,新建 clock.swig
文件,内容如下:
1 | <div style=""> |
在 /themes/next/layout/_custom/sidebar.swig
中引入:
1 | {% include './clock.swig' %} |
在 /themes/next/layout/_macro/sidebar.swig
中引入:
1 | <div class="site-overview-wrap sidebar-panel{% if not display_toc or toc(page.content).length <= 1 %} sidebar-panel-active{% endif %}"> |
这里我放在到顶部按钮上面
canvas 粒子时钟样式
在 /themes/next/source/css/_custom/custom.styl
添加:
1 | // 粒子时钟样式 |
注:另一款样式:https://www.html5tricks.com/html5-canvas-dance-time.html
12. 文章评分功能
widgetpack:https://widgetpack.com/
NexT主题中已经集成了widgetpack的星级评分功能,只需注册账号后,修改主题配置文件:
1 | # Star rating support to each article. |
13. 网站运行时间
打开.\themes\next\layout\_partials\footer.swig
并在最后面添加下列代码
1 | <div> |
14. 阅读全文按钮开启
我们首先找到在next主题下的_config.yml
代码:
1 | # Automatically Excerpt. Not recommand. |
将false修改为true即可,length是显示摘要的长度。
如过需要自动控制可在文章中输入来控制,不生效可用
来控制。
15. 配置实时聊天
一个实时聊天客服系统tidio
首先需要去tidio官网注册一个账户,注册地址:https://www.tidio.com/panel/register
注册后填好网站,然后获取Public Key,获取地址:https://www.tidiochat.com/panel/settings/developer
我们首先找到在next主题下的_config.yml
代码:
1 | tidio: |
将enable修改为true,然后输入tidio控制台获取的key
16. 设置头像圆角及旋转
将头像图片放入目录:/themes/next/source/images
重命名为:avatar.[格式]
找到next主题配置文件_config.yml
下的代码
1 | avatar: |
url:头像图片路径
rounded:头像显示圆圈配置
rotated:头像随鼠标旋转
17. 设置背景彩带
17.1. 方法一
转到 NexT 目录
1 | $ cd themes/next |
获取模块
将模块安装到 source/lib 目录:
1 | $ git clone https://github.com/theme-next/theme-next-canvas-ribbon source/lib/canvas-ribbon |
设置
在 NexT _config.yml 文件中启用模块:
1 | canvas_ribbon: |
自定义背景彩带的宽度、透明度和z-index属性
size
: 彩带宽度, 默认:90
.alpha
: 彩带透明度, 默认:0.6
.zIndex
: 彩带html标签的z-index属性, 默认:-1
.
17.2. 方法二
使用CDN的方式,在 NexT _config.yml 文件中启用canvas_ribbon链接:
1 | vendors: |
在 NexT _config.yml 文件中启用模块:
1 | canvas_ribbon: |
18. 添加动态背景
在主题文件夹下 next/layout/_partials/footer.swig文件最后面添加
1 | <div> |
19. 设置代码块样式
代码块的行号显示在上面已经介绍了,位于站点配置文件,对于代码块的主题我么还能设置其背景,增加复制按钮等,可修改主题配置文件如下:
1 | codeblock: |
20. 修改文章链接样式
修改文件 themes\next\source\css_common\components\post\post.styl,在末尾添加如下css样式,:
1 | // 文章内链接文本样式 |
21. 鼠标点击特效
下面是四个比较常用的鼠标点击特效脚本,我们可以把它们放置在 themes\next\source\js\cursor\ 目录下,创建fireworks.js文件:
礼花特效代码:
1 | class Circle { |
爆炸特效:
explosion.min.js代码:
1 | function updateCoords(e){pointerX=(e.clientX||e.touches[0].clientX)-canvasEl.getBoundingClientRect().left,pointerY=e.clientY||e.touches[0].clientY-canvasEl.getBoundingClientRect().top}function setParticuleDirection(e){var t=anime.random(0,360)*Math.PI/180,a=anime.random(50,180),n=[-1,1][anime.random(0,1)]*a;return{x:e.x+n*Math.cos(t),y:e.y+n*Math.sin(t)}}function createParticule(e,t){var a={};return a.x=e,a.y=t,a.color=colors[anime.random(0,colors.length-1)],a.radius=anime.random(16,32),a.endPos=setParticuleDirection(a),a.draw=function(){ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.fillStyle=a.color,ctx.fill()},a}function createCircle(e,t){var a={};return a.x=e,a.y=t,a.color="#F00",a.radius=.1,a.alpha=.5,a.lineWidth=6,a.draw=function(){ctx.globalAlpha=a.alpha,ctx.beginPath(),ctx.arc(a.x,a.y,a.radius,0,2*Math.PI,!0),ctx.lineWidth=a.lineWidth,ctx.strokeStyle=a.color,ctx.stroke(),ctx.globalAlpha=1},a}function renderParticule(e){for(var t=0;t<e.animatables.length;t++)e.animatables[t].target.draw()}function animateParticules(e,t){for(var a=createCircle(e,t),n=[],i=0;i<numberOfParticules;i++)n.push(createParticule(e,t));anime.timeline().add({targets:n,x:function(e){return e.endPos.x},y:function(e){return e.endPos.y},radius:.1,duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule}).add({targets:a,radius:anime.random(80,160),lineWidth:0,alpha:{value:0,easing:"linear",duration:anime.random(600,800)},duration:anime.random(1200,1800),easing:"easeOutExpo",update:renderParticule,offset:0})}function debounce(e,t){var a;return function(){var n=this,i=arguments;clearTimeout(a),a=setTimeout(function(){e.apply(n,i)},t)}}var canvasEl=document.querySelector(".fireworks");if(canvasEl){var ctx=canvasEl.getContext("2d"),numberOfParticules=30,pointerX=0,pointerY=0,tap="mousedown",colors=["#FF1461","#18FF92","#5A87FF","#FBF38C"],setCanvasSize=debounce(function(){canvasEl.width=2*window.innerWidth,canvasEl.height=2*window.innerHeight,canvasEl.style.width=window.innerWidth+"px",canvasEl.style.height=window.innerHeight+"px",canvasEl.getContext("2d").scale(2,2)},500),render=anime({duration:1/0,update:function(){ctx.clearRect(0,0,canvasEl.width,canvasEl.height)}});document.addEventListener(tap,function(e){"sidebar"!==e.target.id&&"toggle-sidebar"!==e.target.id&&"A"!==e.target.nodeName&&"IMG"!==e.target.nodeName&&(render.play(),updateCoords(e),animateParticules(pointerX,pointerY))},!1),setCanvasSize(),window.addEventListener("resize",setCanvasSize,!1)} ; |
浮出爱心特效
love.min.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); |
浮出文字特效
text.js代码:
1 | var a_idx = 0; |
然后我们在主题自定义布局文件 themes\next\layout\_custom\custom.swig
中添加以下代码:
1 | {# 鼠标点击特效 #} |
如果 custom.swig
文件不存在,我们可以手动新建这个文件并在布局页面 themes\next\layout\_layout.swig
中 body 末尾引入:
1 | ... |
然后我们在主题配置文件中添加以下代码:
1 | # mouse click effect: fireworks | explosion | love | text |
这样即可在配置文件中一键快速切换鼠标点击特效。
22. 打字特效
我们需要添加下面这个脚本 activate-power-mode.min.js
,然后放置在 themes\next\source\js\
目录下:
1 | (function webpackUniversalModuleDefinition(root,factory){if(typeof exports==='object'&&typeof module==='object')module.exports=factory();else if(typeof define==='function'&&define.amd)define([],factory);else if(typeof exports==='object')exports["POWERMODE"]=factory();else root["POWERMODE"]=factory()})(this,function(){return(function(modules){var installedModules={};function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:false};modules[moduleId].call(module.exports,module,module.exports,__webpack_require__);module.loaded=true;return module.exports}__webpack_require__.m=modules;__webpack_require__.c=installedModules;__webpack_require__.p="";return __webpack_require__(0)})([function(module,exports,__webpack_require__){'use strict';var canvas=document.createElement('canvas');canvas.width=window.innerWidth;canvas.height=window.innerHeight;canvas.style.cssText='position:fixed;top:0;left:0;pointer-events:none;z-index:999999';window.addEventListener('resize',function(){canvas.width=window.innerWidth;canvas.height=window.innerHeight});document.body.appendChild(canvas);var context=canvas.getContext('2d');var particles=[];var particlePointer=0;POWERMODE.shake=true;function getRandom(min,max){return Math.random()*(max-min)+min}function getColor(el){if(POWERMODE.colorful){var u=getRandom(0,360);return'hsla('+getRandom(u-10,u+10)+', 100%, '+getRandom(50,80)+'%, '+1+')'}else{return window.getComputedStyle(el).color}}function getCaret(){var el=document.activeElement;var bcr;if(el.tagName==='TEXTAREA'||(el.tagName==='INPUT'&&el.getAttribute('type')==='text')){var offset=__webpack_require__(1)(el,el.selectionStart);bcr=el.getBoundingClientRect();return{x:offset.left+bcr.left,y:offset.top+bcr.top,color:getColor(el)}}var selection=window.getSelection();if(selection.rangeCount){var range=selection.getRangeAt(0);var startNode=range.startContainer;if(startNode.nodeType===document.TEXT_NODE){startNode=startNode.parentNode}bcr=range.getBoundingClientRect();return{x:bcr.left,y:bcr.top,color:getColor(startNode)}}return{x:0,y:0,color:'transparent'}}function createParticle(x,y,color){return{x:x,y:y,alpha:1,color:color,velocity:{x:-1+Math.random()*2,y:-3.5+Math.random()*2}}}function POWERMODE(){{var caret=getCaret();var numParticles=5+Math.round(Math.random()*10);while(numParticles--){particles[particlePointer]=createParticle(caret.x,caret.y,caret.color);particlePointer=(particlePointer+1)%500}}{if(POWERMODE.shake){var intensity=1+2*Math.random();var x=intensity*(Math.random()>0.5?-1:1);var y=intensity*(Math.random()>0.5?-1:1);document.body.style.marginLeft=x+'px';document.body.style.marginTop=y+'px';setTimeout(function(){document.body.style.marginLeft='';document.body.style.marginTop=''},75)}}};POWERMODE.colorful=false;function loop(){requestAnimationFrame(loop);context.clearRect(0,0,canvas.width,canvas.height);for(var i=0;i<particles.length;++i){var particle=particles[i];if(particle.alpha<=0.1)continue;particle.velocity.y+=0.075;particle.x+=particle.velocity.x;particle.y+=particle.velocity.y;particle.alpha*=0.96;context.globalAlpha=particle.alpha;context.fillStyle=particle.color;context.fillRect(Math.round(particle.x-1.5),Math.round(particle.y-1.5),3,3)}}requestAnimationFrame(loop);module.exports=POWERMODE},function(module,exports){(function(){var properties=['direction','boxSizing','width','height','overflowX','overflowY','borderTopWidth','borderRightWidth','borderBottomWidth','borderLeftWidth','borderStyle','paddingTop','paddingRight','paddingBottom','paddingLeft','fontStyle','fontVariant','fontWeight','fontStretch','fontSize','fontSizeAdjust','lineHeight','fontFamily','textAlign','textTransform','textIndent','textDecoration','letterSpacing','wordSpacing','tabSize','MozTabSize'];var isFirefox=window.mozInnerScreenX!=null;function getCaretCoordinates(element,position,options){var debug=options&&options.debug||false;if(debug){var el=document.querySelector('#input-textarea-caret-position-mirror-div');if(el){el.parentNode.removeChild(el)}}var div=document.createElement('div');div.id='input-textarea-caret-position-mirror-div';document.body.appendChild(div);var style=div.style;var computed=window.getComputedStyle?getComputedStyle(element):element.currentStyle;style.whiteSpace='pre-wrap';if(element.nodeName!=='INPUT')style.wordWrap='break-word';style.position='absolute';if(!debug)style.visibility='hidden';properties.forEach(function(prop){style[prop]=computed[prop]});if(isFirefox){if(element.scrollHeight>parseInt(computed.height))style.overflowY='scroll'}else{style.overflow='hidden'}div.textContent=element.value.substring(0,position);if(element.nodeName==='INPUT')div.textContent=div.textContent.replace(/\s/g,"\u00a0");var span=document.createElement('span');span.textContent=element.value.substring(position)||'.';div.appendChild(span);var coordinates={top:span.offsetTop+parseInt(computed['borderTopWidth']),left:span.offsetLeft+parseInt(computed['borderLeftWidth'])};if(debug){span.style.backgroundColor='#aaa'}else{document.body.removeChild(div)}return coordinates}if(typeof module!="undefined"&&typeof module.exports!="undefined"){module.exports=getCaretCoordinates}else{window.getCaretCoordinates=getCaretCoordinates}}())}])}); |
在主题自定义布局文件 themes\next\layout\_custom\custom.swig
中添加以下代码:
1 | {# 打字特效 #} |
如果 custom.swig
文件不存在,我们可以手动新建这个文件并在布局页面 themes\next\layout\_layout.swig
中 body 末尾引入:
1 | ... |
然后我们在主题配置文件中添加以下代码:
1 | # typing effect |
这样即可在配置文件中一键快速切换打字特效。
参考:
23. 字体调整
Next主题自带的字体是较大的,我这里给出了一个比较合适的方案:
1.打开/blog/themes/next/source/css/_variables/base.styl文件,查找Font size字段,将**$font-size-large**参数由1.125em改为1.0em
1 | // Font size |
2.打开/blog/themes/next/_config.yml文件,查找Font Settings字段并修改如下:
1 | # --------------------------------------------------------------- |
24. 修改代码块复制时背景颜色
next/source/css/scaffolding/highlight/theme.styl中修改$highlight-selection的颜色
1 | $highlight-selection = #154487; |
25. 字体相关配置
主题配置文件 _config.yml
里与字体相关的配置项:
1 | font: |
挑选并配置字体
Google Fonts 挑选一款字体,在配置里的 family
处添加即可。
1 | font: |
如此配置之后,基于 hexo-next-theme 的博客就会全局使用「思源宋体」。
同理,配置代码块的字体也只需要挑选并覆盖相应配置即可。如:
1 | font: |
googleapis
前端 CDNJS 库及 Google Fonts、Ajax 和 Gravatar 国内加速服务
国内访问fonts.googleapis.com
不太稳定,有时候很慢,用上面帖子里提供的 CDN,Next 的配置就可以这样:
1 | font: |
配置之后如果还有加载googleapis字体的地方全局替换即可。
参考
https://www.liaofuzhan.com/posts/2114475547.html
https://tding.top/archives/2bd6d82.html
https://www.simon96.online/2018/10/12/hexo-tutorial/
https://blog.csdn.net/weixin_44815733/article/details/88817220
https://blog.csdn.net/weixin_43971764/article/details/96754325