Hexo next 主题配置美化
在博客根目录下操作
下载使用next主题
1 | git clone https://github.com/theme-next/hexo-theme-next themes/next |
1 | theme:next |
官方不建议直接修改主题文件下的内容,这不利于升级
1 | cp themes/next/_config.yml _config.next.yml # 复制主题文件到主目录 |
Hexo 配置文件($blog/_config.yml)中的 theme_config 的优先级最高,其次是 $blog/_config.[theme].yml 文件,最后是位于主题目录下的 _config.yml 文件
博客配置文件基础配置
1 | vim _config |
1 | # Site |
next主题主配置文件基础配置
1 | vim _config.next.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 _config.next.yml #修改主题配置文件 |
1 | # Local search |
- 全文阅读
博客主页会有多篇文章,如果想让你的文章只显示一部分,多余内容需要点击阅读全文来查看,那么就需要在的文章中添加:
1 | <!--more--> |
在它后面的内容会被隐藏,当点击阅读全文才能看到
可将其添加到模板文件(scaffolds/post.md) 中,每次创建新文章都自动添加
头像图标
将头像图标文件放到 $blog/source/images 下
头像
1 | # Sidebar Avatar |
博客网站图标
1 | favicon: |
侧栏配置
1 | sidebar: |
访问计数
用的是不蒜子脚本来达到计数目的的
1 | # Show Views / Visitors of the website / page with busuanzi. |
若显示出错可到不蒜子官网查询到最新脚本变化
在本地查看的变量是错误, hexo c ,hexo d之后打开网页,就能看到正确的访问人数
阅读书签
用于记录本次阅读文章的位置,下次访问直接打开到上次的位置
1 | # Bookmark Support |
侧边栏目录
在写文章是通常会有给标题编号的情况,但主题默认也会给加上一个编号,这样就会有些多余,关闭自动编号只需在侧边栏目录配置关闭即可
1 | # Table Of Contents in the Sidebar #边栏中的目录 |
侧边栏社交链接
1 | social: |
侧边栏友情链接
1 | # Blog rolls |
文章版权信息
1 | creative_commons: |
动画
1 | # Use velocity to animate everything. |
动画背景
克隆脚本到themes/next/source/lib/three
1 | git clone https://github.com/theme-next/theme-next-three themes/next/source/lib/three |
修改主题配置文件开启动态背景:
1 | # JavaScript 3D library. |
顶部加载进度条
克隆脚本到themes/next/source/lib/pace
1 | git clone https://github.com/theme-next/theme-next-pace themes/next/source/lib/pace |
修改主题配置文件:
1 | pace: |
添加打赏
1 | # Reward (Donate) |
底部博客平台信息
1 | # Powered by Hexo & NexT |
自定义主题内容
底部标签图标样式
1 | vim themes/next/layout/_macro/post.swig |
将rel="tag">{{ tag_indicate }}改为:rel="tag"><i class="fa fa-tag"></i>
1 | <a href="{{ url_for(tag.path) }}" rel="tag"><i class="fa fa-tag"></i> {{ tag.name }}</a> |
鼠标点击特效
第一种(小心心)
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 #body标签中添加 |
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 _config.next.yml #在主题文件中加入 |
1 | # Fireworksfireworks: true |
github角落及丝带
在GitHub Corners(角落)或GitHub Ribbons(丝带)选择一款你喜欢的挂饰,拷贝方框内的代码
1 | vim themes/next/layout/_layout.swig #将代码加入<div class="headband"></div>下方 |
右上角蓝底:
1 | <a href="https://github.com/eonun" class="github-corner" aria-label="View source on GitHub"><svg width="80" height="80" viewBox="0 0 250 250" style="fill:#70B7FD; color:#fff; position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style> |
宠物
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: |
文章插入图片
hexo 自带方式
1 | # {% asset_img <slug> [title] %} |
hexo-renderer-marked 3.1.0引入了一个新的选项,允许在markdown不使用 asset_img 标签插件的情况下嵌入图像
1 | post_asset_folder: true |
然后在文章中使用:
1 |  |
插件方式
1 | vim _config.yml #修改博客配置文件,开启资源文件夹 |
1 | post_asset_folder: true |
1 | yarn add hexo-asset-image #安装插件 |
1 | else { |
将图片放到该文件夹下,在文章中添加图片
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 前加入 |
1 | <div> |
1 | vim _config.next.yml #加入以下内容 |
1 | # 文章末尾添加“本文结束”标记 |
自定义样式
1 | vim _config.next.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;
字体颜色
在自定义样式文件 source/_data/styles.styl 中添加定义
1 | //博客标题字体色 |
配置链接文本样式
1 | vim source/_data/styles.styl #添加自定义样式 |
1 | .post-body p a { |
杂项
文章模板
1 | vim scaffolds/post.md |
1 | --- |
文章内容中的影音
音乐
直接使用HTML标签:
1 | <audio src="https://音乐链接.mp3" style="max-height :100%; max-width: 100%; display: block; margin-left: auto; margin-right: auto;" controls="controls" loop="loop" preload="meta">Your browser does not support the audio tag.</audio> |
使用插件(hexo-tag-aplayer),有显示歌词功能,也美观
1 | yarn add hexo-tag-aplayer |
然后在文章中使用:
1 | {% aplayer "歌曲名" "歌手名" "https://音乐链接.mp3" "https://封面图.jpg" "lrc:https://歌词.lrc" %} |
支持歌单:
1 | {% aplayerlist %} |
视频
直接使用HTML标签:
1 | <video poster="https://封面图.jpg" src="https://视频链接.mp4" style="max-height :100%; max-width: 100%; display: block; margin-left: auto; margin-right: auto;" controls="controls" loop="loop" preload="meta">Your browser does not support the video tag.</video> |
用插件(hexo-tag-dplayer),可支持弹幕:
1 | yarn add hexo-tag-dplayer |
然后在文章中使用:
1 | {% dplayer "url=https://视频链接.mp4" "https://封面图.jpg" "api=https://api.prprpr.me/dplayer/" "id=" "loop=false" %} |
使用弹幕必须有 api 和 id 两项,并且若使用的是 官方 的 api 地址(即上面的),id 的值需要随机自定义,可用 工具 将与众不同的文字😂生成哈希值来使用。
配置RSS
1 | yarn add hexo-generator-feed #安装插件 |
1 | # 添加RSS订阅配置内容 |
1 | vim _config.next.yml #修改主题配置文件 |
1 | rss:/atom.xml |
配置评论系统
到来必力注册登录,安装免费版填入相关信息后获得一串代码,在代码中有一串uid,将uid值复制出出来添加到主题配置文件中即可
1 | <!-- 来必力City版安装代码 --> |
1 | vim _config.next.yml #修改主题配置文件 |
1 | #找到LiveRe comments system |
文章加密
1 | yarn add hexo-blog-encrypt #安装插件 |
1 | # Security |
给文章加密
1 | --- |
腾讯公益404页面
1 | vim source/404.html #添加代码 |
1 |
|
压缩静态文件提高访问速度
1 | yarn add hexo-neat #安装插件 |
1 | #静态文件压缩 |
Hexo-admin
可视化界面操作文章
1 | yarn add hexo-admin |
访问localhost:4000/admin/, Settings > Setup authentification 输入相关信息得到配置内容添加到_config.yml 进行配置
1 | # hexo-admin authentification |