hexo静态博客之next主题的配置
官方教程:开始使用 - NexT 使用文档 (iissnan.com)
1、Hexo-NexT (v7.0+) 主题配置 | 小丁的个人博客 (tding.top)
2、hexo搭建个人博客—NexT主题优化 - 简书 (jianshu.com)
3、hexonext主题解决无法显示数学公式 - 百度文库 (baidu.com)
4、Hexo 搭建个人博客系列:主题美化篇 | Yearito’s Blog
我的本地博客根目录为yanglinqi_blog
下载next
下载方式二选一:
1、打开终端,进入hexo站点目录,执行命令
cd e:\yanglinqi_blog
这是我的站点根目录
git clone https://github.com/iissnan/hexo-theme-next themes/next
完成后,在themes文件夹下会多出next文件夹
2、打开Releases · theme-next/hexo-theme-next (github.com) 选择版本下载,将文件夹命名为next放入themes下就行
然后打开站点配置文件_config.yml
,选择next主题 theme: next
终端一键三连,看网页是否正常
1 | hexo clean |
next提供了四种页面样式,可以在主题配置文件_config.yml
中选择,我选择的Pisces
1 | # Schemes |
配置next
标签和分类
1、主题配置文件_config.yml
内:
1 | menu: |
2、新建tags
和categories
页面
终端输入(要进入hexo博客根目录)
1 | hexo new page tags |
在 tags
页面文件 hexo/source/tags/index.md
的头部修改为:
1 | --- |
在 categories
页面文件 hexo/source/categories/index.md
的头部修改为:
1 | --- |
之后在对应博客md文件中添加tags
和categories
就行了。如有一个test.md
,给它添加分类和标签,在它首部添加
1 | --- |
背景图片和字体
将你要作为背景的图片background.jpg
放在next\source\images
文件夹下
所修改的文件:E:\yanglinqi_blog\themes\next\source\css\_common\scaffolding\base.styl
内的body
1 | /*body { |
头像
将要作为头像的图片放在next\source\images
文件夹下,我的图片名称是headpic.jpg
在主题配置文件中修改avatar
1 | avatar: |
网页图标
将你要作为图标的图片修改好大小,放在E:\yanglinqi_blog\themes\next\source\images
文件夹下
修改主题配置文件E:\yanglinqi_blog\themes\next\_config.yml
中的favicon
:我的图片命名为icon.png
1 | # 网页的图标 icon |
侧边菜单栏
所修改的文件:E:\yanglinqi_blog\themes\next\source\css\_schemes\Pisces\_layout.styl
内的.header-inner
1 | .header-inner { |
侧边头像栏
要修改的文件:E:\yanglinqi_blog\themes\next\source\css\_schemes\Pisces\_sidebar.styl
.sidebar
1 | .sidebar { |
.sidebar-inner
注释掉
1 | //background: var(--content-bg-color); |
标签样式
要修改的文件:E:\yanglinqi_blog\themes\next\source\css\_common\components\pages\tag-cloud.styl
注释掉原来的.tag-cloud
1 | /*.tag-cloud { |
分类样式
要修改的文件:
E:\yanglinqi_blog\themes\next\source\css\_common\components\pages\categories.styl
修改.category-list
的 list-style: circle;
1 | .category-list { |
主体背景
修改的文件:E:\yanglinqi_blog\themes\next\source\css\_schemes\Pisces\_layout.styl
.content-wrap
更换为下面内容:
1 | .content-wrap { |
再在文件E:\yanglinqi_blog\themes\next\source\css\main.styl
尾追加
1 | .posts-expand { |
再修改文件 E:\yanglinqi_blog\themes\next\layout\_macro\post.swig
删除以下<footer class="post-footer">
的内容
1 | <footer class="post-footer"> |
链接样式
修改文件:E:\yanglinqi_blog\themes\next\source\css\_common\components\post\post-expand.styl
在.post-body
中添加以下内容
1 | a:not(.btn):not(.hexo-douban-button):not(.hexo-douban-tab) { |
代码块样式
修改文件:E:\yanglinqi_blog\themes\next\_config.yml
修改codeblock
部分
1 | codeblock: |
搜索功能
安装插件:
1 | npm install hexo-generator-searchdb --save |
然后我们修改站点配置_config.yml
文件,添加如下内容:
1 | # 本地搜索 |
- path:索引文件的路径,相对于站点根目录
- field:搜索范围,默认是 post,还可以选择 page、all,设置成 all 表示搜索所有页面
- limit:限制搜索的条目数
然后修改主题配置文件_config.yml
:
1 | # Local Search |
数学公式
常⽤的Markdown编辑器都会集成Mathjax,⽤来渲染⽂档中的类Latex格式书写的数学公式
原因
Hexo 默认使⽤ hexo-renderer-marked 引擎渲染⽹页,该引擎会把⼀些特殊的 markdown 符号转换为相应的 html 标签,⽐如在markdown 语法中,下划线_
代表斜体,会被渲染引擎处理为<em>
标签。因为类 Latex 格式书写的数学公式下划线_
表⽰下标,有特殊的含义,如果被强制转换为<em>
标签,那么 MathJax 引擎在渲染数学公式的时候就会出错。类似的语义冲突的符号还包括*, {, }, \\
等
解决方法:
更换 Hexo 的 markdown 渲染引擎,hexo-renderer-kramed 引擎是在默认的渲染引擎 hexo-renderer-marked 的基础上修改了⼀些bug ,两者⽐较接近,也⽐较轻量级
1 | npm uninstall hexo-renderer-marked --save # 先卸载 hexo-renderer-marked |
再修改文件E:\yanglinqi_blog\node_modules\kramed\lib\rules\inline.js
修改第11行的
escape
1
2//escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,
escape: /^\\([`*\[\]()#$+\-.!_>])/,修改第20行的
em
1
2//em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
在next主题配置文件中开启MathJax
开关,_config.yml
文件
1 | mathjax: |
在想要渲染数学公式的md文件首加上 mathjax: true
行内代码
修改的文件E:\yanglinqi_blog\themes\next\source\css\_common\scaffolding\highlight\highlight.styl
修改code
如下
1 | code { |
展开目录
主题配置文件_config.yml
的toc
再把目录的下划线去掉,修改文件E:\yanglinqi_blog\themes\next\source\css\_common\outline\sidebar\sidebar-toc.styl
的 .post-toc > ol > a
标签
1 | a { |
或者在主题配置文件_config.yml
的toc
下增加border-bottom: none
文章置顶
1、卸载 hexo-generator-index
npm uninstall hexo-generator-index --save
2、安装 hexo-generator-index-pin-top
npm install hexo-generator-index-pin-top --save
3、在想要置顶的md文件首,添加top: 10
或top: true
,数字越大,级别越高
4、修改themes/next/layout/_macro/post.swig
⽂件
在<span class='post-time'>
标签下,插⼊以下代码:
1 | {% if post.top %} |
点击特效
下面是四个比较常用的鼠标点击特效脚本,我们可以把它们放置在 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); |
浮出文字特效
1 | var a_idx = 0; |
修改文件
然后我们在主题自定义布局文件hexo/source/_data/body-end.swig
中,没有则创建,添加以下代码:
1 | {# 鼠标点击特效 #} |
然后在 NexT 的配置文件 next.yml 中取消 body-end.swig
的注释:
1 | custom_file_path: |