Hexo next v7主题配置美化
在博客根目录下操作
下载使用next主题
1 | git clone https://github.com/theme-next/hexo-theme-next themes/next |
1 | theme:next |
博客配置文件基础配置
1 | vim _config |
1 | # Site |
next主题主配置文件基础配置
1 | vim themes/next/_config.yml |
主题样式配置
1 | # Schemes #选择一个主题样式,去掉前面的注释,将不用的主题样式注释掉 |
菜单栏配置
1 | menu: #将需要的菜单取消注释即可,顺便换一下顺序 |
添加模块
- 分类模块
1 | hexo n page categories |
1 | --- |
需要在把文章进行分类时只需在文章顶部标题下方添加categories字段,即可自动创建分类名并加入对应的分类中
栗子:
1 | #单个分类 |
- 标签模块
1 | hexo n page tags |
1 | --- |
需要在给文章添加时只需在文章顶部标题下方添加tags字段,即可自动创建标签名并归入对应的标签中
栗子:
1 | title: 这是文章标题 |
- 关于模块
1 | hexo n page about |
source文件夹下会生成about/index.md,打开index.md文件即可编辑个人相关信息
- 本地搜索模块
1 | yarn add hexo-generator-searchdb #安装搜索插件 |
1 | # 在Extensions下添加搜索配置模块 |
1 | vim themes/next/_config.yml #修改主题配置文件 |
1 | # Local search |
- 全文阅读
博客主页会有多篇文章,如果想让你的文章只显示一部分,多余内容需要点击阅读全文来查看,那么就需要在的文章中添加:
1 | <!--more--> |
在它后面的内容会被隐藏,当点击阅读全文就能看到了
底部标签图标样式
1 | vim themes/next/layout/_macro/post.swig |
将rel="tag">{{ tag_indicate }}改为:rel="tag"><i class="fa fa-tag"></i>
头像配置
1 | # Sidebar Avatar |
侧栏配置
1 | sidebar: |
博客网站图标
将png、jpg格式的图标放到themes/next/source/images下
1 | favicon: |
访问计数
用的是不蒜子脚本来达到计数目的的
1 | # Show Views / Visitors of the website / page with busuanzi. |
若显示出错可到不蒜子官网查询到最新脚本变化
在本地查看的变量是错误, hexo c ,hexo d之后打开网页,就能看到正确的访问人数
侧边栏目录
在写文章是通常会有给标题编号的情况,但主题默认也会给加上一个编号,这样就会有些多余,关闭自动编号只需在侧边栏目录配置关闭即可
1 | # Table Of Contents in the Sidebar #边栏中的目录 |
侧边栏社交链接
1 | social: |
github角落及丝带
在GitHub Corners(角落)或GitHub Ribbons(丝带)选择一款你喜欢的挂饰,拷贝方框内的代码
1 | vim themes/next/layout/_layout.swig #将代码加入<div class="headband"></div>下方 |
侧边栏友情链接
1 | # Blog rolls |
文章版权信息
1 | creative_commons: |
动画
1 | # Use velocity to animate everything. |
背景动画
根据自己需要开启即可
1 | # Canvas-nest |
1 | #要使用的动画需下载相关插件才能使用,不用就无需下载了 |
鼠标点击特效
1 | vim themes/next/source/js/clicklove.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); |
1 | vim themes/next/laout/_layout.swig #添加 |
1 | <!-- 页面点击小红心 --><script type="text/javascript" src="/js/clicklove.js"></script> |
另一种特效
1 | vim themes/next/source/js/fireworks.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=0.1,a.alpha=0.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:0.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)}"use strict";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=0.1,a.alpha=0.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:0.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)}; |
1 | vim themes/next/laout/_layout.swig #添加 |
1 | {% if theme.fireworks %} <canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 1; pointer-events: none;" ></canvas> <script type="text/javascript" src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script> <script type="text/javascript" src="/js/fireworks.js"></script>{% endif %} |
1 | vim themes/next/_config.yml #在主题文件中加入 |
1 | # Fireworksfireworks: true |
添加打赏
1 | # Reward (Donate) |
底部博客平台信息
1 | powered: |
其他配置文件配置
宠物
1 | yarn add hexo-helper-live2d |
hexo-helper-live2d
live2d-widget-models
宠物样式表
live2d-widget-model-chitose
live2d-widget-model-epsilon2_1
live2d-widget-model-gf
live2d-widget-model-haru/01 (live2d-widget-model-haru)
live2d-widget-model-haru/02 (live2d-widget-model-haru)
live2d-widget-model-haruto
live2d-widget-model-hibiki
live2d-widget-model-hijiki
live2d-widget-model-izumi
live2d-widget-model-koharu
live2d-widget-model-miku
live2d-widget-model-ni-j
live2d-widget-model-nico
live2d-widget-model-nietzsche
live2d-widget-model-nipsilon
live2d-widget-model-nito
live2d-widget-model-shizuku
live2d-widget-model-tororo(白猫)
live2d-widget-model-tsumiki
live2d-widget-model-unitychan
live2d-widget-model-wanko
live2d-widget-model-z16
需要先使用 yarn add 模型的包名 来安装
1 | live2d: |
文章插入图片
1 | vim _config.yml #修改博客配置文件,开启资源文件夹 |
1 | post_asset_folder: true |
1 | yarn add hexo-asset-image #安装插件 |
1 | else { |
将图片放到该文件夹下,在文章中添加图片
1 |  #只需要添加文件名即可,无需加上目录 |
自定义样式(next v7)
1 | vim themes/next/_config.yml |
1 | # 定义自定义文件路径 |
文章阴影
1 | vim source/_data/styles.styl #添加自定义样式 |
1 | // Custom styles. |
背景图
1 | vim source/_data/styles.styl #添加指自定义样式 |
1 | // 添加背景图片 |
解决按钮透明度: themes\next\source\css\_common\components\post\post-button.styl 同上修改对应位置为 background: transparent;
字体颜色
博客标题及菜单栏字体颜色
1 | vim theme/next/source/css_/common/components/header/site-meta.styl |
1 | color: #00BFFF; //博客标题 |
找到博客目录下theme/next/source/css_common/components/header/menu.styl文件,在a{}里面添加以下代码:
1 | color: #00BFFF; //菜单栏 |
底部字体颜色
1 | vim theme/next/source/css/_common/components/header/menu.styl #a{}里面添加代码 |
1 | .footer-inner {color: #00688B;} |
侧边栏字体颜色
1 | vim themes/next/source/css/_custom/custom.styl #加入代码 |
1 | #sidebar { p,span,a {color: #EE2C2C;}} |
杂项
文章模板
1 | vim scaffolds/post.md |
1 | --- |
配置链接文本样式
1 | vim themes/next/source/css/_common/components/post/post.styl #修改配置文件,在末尾加入 |
1 | .post-body p a { |
.post-body 是为了不影响标题
p 是为了不影响“阅读全文”的显示样式
颜色可以自定义
配置RSS
1 | yarn add hexo-generator-feed #安装插件 |
1 | # 添加RSS订阅配置内容 |
1 | vim themes/next/_config.yml #修改主题配置文件 |
1 | rss:/atom.xml |
配置评论系统
到来必力注册登录,安装免费版填入相关信息后获得一串代码,在代码中有一串uid,将uid值复制出出来添加到主题配置文件中即可
1 | <!-- 来必力City版安装代码 --> |
1 | vim themes/next/_config.yml #修改主题配置文件 |
1 | #找到LiveRe comments system |
文章加密
1 | yarn add hexo-blog-encrypt #安装插件 |
1 | # Security |
给文章加密
1 | --- |
侧边栏加入音乐播放器
到网易云音乐选择歌单,生成外链
1 | <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=298 height=52 src="//music.163.com/outchain/player?type=2&id=1365959078&auto=1&height=32"></iframe> |
1 | vim themes/next/layout/_macro/sidebar.swig #将生成的外链放到合适的位置即可 |
文章结束标语
1 | vim themes/next/layout/_macro/passage-end-tag.swig #新建文件并加入内容 |
1 | <div> |
1 | vim themes/next/layout/_macro/post.swig #在post-body 之后(END POST BODY), post-footer 之前添加如代码 |
1 | <div> |
1 | vim themes/next/_config.yml #加入以下内容 |
1 | # 文章末尾添加“本文结束”标记 |
腾讯公益404页面
1 | vim source/404.html #添加代码 |
1 |
|
压缩静态文件提高访问速度
1 | yarn add hexo-neat #安装插件 |
1 | #静态文件压缩 |
Hexo-admin
可视化界面操作文章
1 | yarn add hexo-admin |
1 | # 管理配置 |
password_hash 是密码的哈希secret 用来保证cookie的安全,越长越复杂最好。
通过http://localhost:4000/admin/访问