Hexo 配置 NexT 主题配置流程(自用)
Hexo 部署
docker 版本一键安装
采用 appotry 的docker版本
1 | docker create --name=hexo \ |
SSH 部署
Docker会自动随机生成ssh key 在 /app/.ssh 目录下面。 1.将SSH 公钥复制到剪贴板。 2.在任何页面的右上角,单击您的个人资料照片,然后单击Settings(设置)。 3.在用户设置侧边栏中,单击SSH and GPG keys(SSH 和GPG 密钥)。 4.单击New SSH key(新SSH 密钥)或Add SSH key(添加SSH 密钥)。
运行
1 | docker exec -it hexo /bin/bash |
常用命令
1 | hexo server #启动本地服务器,用于预览主题。Hexo 会监视文件变动并自动更新,除修改站点配置文件外,无须重启服务器,直接刷新网页即可生效。 |
Hexo 配置
下载主题
1 | git clone https://github.com/next-theme/hexo-theme-next themes/next |
切换主题
修改 Hexo
根目录下的_config.yml的theme的值:theme: next
永久链接修改成短链
用 hexo-abbrlink 生成静态文章链接。
安装:
1 | npm install hexo-abbrlink --save |
修改 Hexo 根目录下的_config.yml文件中的如下内容:
1 | url: https://blog.tongorz.me |
文章设置
1 | # Writing |
一键部署到 github
1 | npm install hexo-deployer-git --save |
修改 Hexo 根目录下的_config.yml文件中的如下内容:
1 | deploy: |
配置代码样式
修改 Hexo 根目录下的_config.yml文件中的如下内容:
1 | code: |
NexT 主题配置
布局设置
切换主题,在NexT _config.yml文件中修改:
1 | # Schemes |
菜单栏设置
加入新的菜单栏,已有的取消注释,添加没有的需要修改两部分文件,_config.yml和languages。
在
themes/next/_config.yml文件中修改:1
2
3
4
5
6
7
8
9
10
11
12
13
14# Usage: `Key: /link/ || icon`
# Key is the name of menu item. If the translation for this item is available, the translated text will be loaded, otherwise the Key name will be used. Key is case-sensitive.
# Value before `||` delimiter is the target link, value after `||` delimiter is the name of Font Awesome icon.
# External url should start with http:// or https://
menu:
home: / || fa fa-home
#about: /about/ || fa fa-user
tags: /tags/ || fa fa-tags
categories: /categories/ || fa fa-th
archives: /archives/ || fa fa-archive
resources: /resources/ || fa fa-download # 加入新菜单
#schedule: /schedule/ || fa fa-calendar
#sitemap: /sitemap.xml || fa fa-sitemap
#commonweal: /404/ || fa fa-heartbeat在
/themes/next/languages路径下的zh-CN.yml和en.yml文件中分别修改:1
2
3
4
5
6
7
8
9
10
11menu:
home: 首页
archives: 归档
categories: 分类
tags: 标签
about: 关于
resources: 资源 # 加入翻译
search: 搜索
schedule: 日程表
sitemap: 站点地图
commonweal: 公益 4041
2
3
4
5
6
7
8
9
10
11menu:
home: Home
archives: Archives
categories: Categories
tags: Tags
about: About
resources: Resources # 加入翻译
search: Search
schedule: Schedule
sitemap: Sitemap
commonweal: Commonweal 404
在根目录下输入如下代码:
1 | hexo new page "categories" |
此时在根目录的 sources 文件夹下会生成 categories、tags、resources
三个文件,每个文件中有一个 index.md
文件,修改内容分别如下:
1 | --- |
1 | --- |
1 | --- |
如果有启用评论,默认页面带有评论。需要关闭的话,添加字段 comments 并将值设置为 false。
设置建站时间
在themes/next/_config.yml文件中修改:
1 | footer: |
新建文章模板修改
修改 Hexo
根目录下的scaffolds/post.md文件中的如下内容:
1 | --- |
代码高亮设置
需要修改两部分文件, Hexo 根目录下 _config.yml
文件还有主题下的themes/next/_config.yml文件。
修改 Hexo 根目录下的
_config.yml文件中的如下内容:1
2
3
4
5
6
7
8
9
10
11syntax_highlighter: highlight.js
highlight: # 代码块的设置
enable: true # 开启代码块高亮
line_number: true # 显示行数
auto_detect: false # 如果未指定语言,则启用自动检测
tab_replace: '' # 用 n 个空格替换 tabs;如果值为空,则不会替换 tabs
prismjs:
enable: false
preprocess: true
line_number: true
tab_replace: ''在
themes/next/_config.yml文件中修改:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19codeblock:
# Code Highlight theme
# All available themes: https://theme-next.js.org/highlight/
theme:
light: stackoverflow-light
dark: stackoverflow-dark
prism:
light: prism
dark: prism-dark
# Add copy button on codeblock
# 打开一键复制按钮
copy_button:
enable: true
# Available values: default | flat | mac
style: mac
# Fold code block
fold:
enable: false
height: 500
版权信息
在themes/next/_config.yml文件中修改:
1 | # Creative Commons 4.0 International License. |
加载进度条
在themes/next/_config.yml文件中修改:
1 | # Reading progress bar |
配置MathJax
卸载
hexo-math:npm un hexo-math下载pandoc:
1
brew install Pandoc
替换渲染:
1
2npm uninstall hexo-renderer-marked --save
npm install hexo-renderer-pandoc --save在
themes/next/_config.yml文件中修改:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15math:
# Default (false) will load mathjax / katex script on demand.
# That is it only render those page which has `mathjax: true` in front-matter.
# If you set it to true, it will load mathjax / katex script EVERY PAGE.
every_page: true
mathjax:
enable: true
# Available values: none | ams | all
tags: none
katex:
enable: false
# See: https://github.com/KaTeX/KaTeX/tree/master/contrib/copy-tex
copy_tex: falseevery_page表示是否自动渲染每一页,如果为false就只渲染配置块中包含mathjax: true的文章。在 Hexo 根目录下的
_config.yml文件中添加如下内容:1
2
3
4
5
6
7mathjax:
tags: none # 或 'ams' 或 'all'
single_dollars: true # 启用单个美元符号作为内联(行内)数学公式定界符
cjk_width: 0.9 # 相对 CJK 字符宽度
normal_width: 0.6 # 相对正常(等宽)宽度
append_css: true # 将 CSS 添加到每个页面
every_page: true # 如果为 true,那么无论每篇文章的前题中的 `mathjax` 设置如何,每页都将由 mathjax 呈现
搜索服务
下载:
1 | npm install hexo-generator-searchdb --save |
在 Hexo 根目录下的_config.yml文件中添加如下内容:
1 | search: |
在themes/next/_config.yml文件中修改:
1 | # Local Search |
字数统计
使用 hexo-word-counter 统计文章的字数以及预期阅读时间,完成配置后,可以在每篇文章开头和页面底部显示字数和阅读时间。
下载:
1 | npm install hexo-word-counter |
在 Hexo 根目录下的_config.yml文件中添加如下内容:
1 | #显示文章字数和阅读时长 |
在themes/next/_config.yml文件中修改:
1 | # Post wordcount display settings |
如果文章中大多中文,那么设置
awl为2,wpm为300比较合适
修改文章底部的带 # 号的标签
1 | # Use icon instead of the symbol # to indicate the tag at the bottom of the post |
配置返回顶部
在themes/next/_config.yml文件中修改:
1 | back2top: |
不蒜子统计
在themes/next/_config.yml文件中修改:
1 | # Show Views / Visitors of the website / page with busuanzi. |
在next/layout/_third-party/statistics/busuanzi-counter.njk文件中修改为第三方
API:
1 | {%- if theme.busuanzi_count.enable %} |
添加 Canvas_nest 动态背景
根据官方文档,在hexo/source/_data的目录下新建一个footer.mjk文件(如果_data目录不存在则创建一个)。
在themes/next/_config.yml文件中修改:
1 | # Define custom file paths. |
最后在配置文件里新增一段canvas_nest: true。
添加 Gitalk 评论系统
Gitalk是一个基于github开发的评论插件,它将文章评论以issues形式保存在github仓库中。
注册github应用:
进入github注册页面:Register a new OAuth
application
Application name:应用名Homepage URL:网站地址Application description:应用描述Authorization callback URL:网站地址
注册成功后会生成Client ID和Client Secret
在themes/next/_config.yml文件中修改:
1 | # Gitalk |
添加网站运行时间
方法来源于yifanstar
在themes/next/layout/_partials目录下新建一个time.njk文件,添加如下代码:
1 | {% if theme.footer.site_runtime.enable %} |
在 themes/next/layout/_layout.njk 文件 body
标签中添加如下代码:
1 | ... |
在themes/next/_config.yml文件中添加:
1 | footer: |
然后在文件 themes/next/languages/zh-CN.yml
中补全对应翻译:
1 | footer: |
页面特效
浮出爱心:
在themes/next/source/js/cursor目录下新建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); |
礼花特效:
在themes/next/source/js/cursor目录下新建firework.js文件,添加如下代码:
1 | class Circle { |
爆炸特效:
在themes/next/source/js/cursor目录下新建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)} |
浮出文字:
在themes/next/source/js/cursor目录下新建text.js文件,添加如下代码:
1 | var a_idx = 0; |
在themes/next/layout/_partials目录下新建一个page_effects.njk文件,添加如下代码:
1 | {# 鼠标点击特效 #} |
在 themes/next/layout/_layout.njk 文件 body
标签中添加如下代码:
1 | ... |
在themes/next/_config.yml文件中添加:
1 | # mouse click effect: fireworks | explosion | love | text |
参考
http://yifanstar.top/2020/07/19/hexo-blog-creat/
https://hexo-next.readthedocs.io/zh-cn/latest/
https://blog.17lai.site/posts/40300608/
https://zhuanlan.zhihu.com/p/618864711
https://blog.csdn.net/xq151750111/article/details/131101229