Prerequisites
工具安装
-
安装npm
-
安装hexo
1
| npm install install hexo-cli -g
|
仓库搭建
- 创建github仓库
仓库的格式必须为:<username>.github.io
- 配置免密连接github
-
生成ssh密钥
1
| ssh-keygen -t ed25519 -f github_id_ed25519 -C "github"
|
-
复制公钥到github中
1
| xclip -sel clip < ~/.ssh/xxx.pub
|
-
测试连接
如果在生成ssh密钥那一步生成的文件名不是默认的,在测试连接的时候可能会出错,这其中牵扯到openssh中ssh连接时的一些原理,这里不细将,感兴趣的小伙伴可以查看相关资料,通常我的解决办法是使用「~/.ssh/config」文件来管理所有的ssh连接。
1 2 3 4 5
| Host github.com Hostname github.com User git preferredAuthentications publickey IdentityFile ~/.ssh/github_id_ed25519
|
命令教程
- hexo常见命令
-
初始化
-
新建文章
1
| hexo new[n] [layout] <title>
|
hexo中支持三种不同的layout,分别为post
,page
,draft
,不同的layout将创建不同目录的文件,默认的layout是post
,你可以在_config.yml
中设置默认的layout。
Layout |
Path |
post |
source/_posts |
page |
source |
draft |
source/_drafts |
-
草稿发布为正式文章
将【source/_drafts/】下的文章移动到【source/_posts】中
-
清理缓存
-
启动本地服务器
-p
选项,制定服务器端口,默认为4000
-i
选项,指定服务器IP,默认为0.0.0.0
-
生成静态文件
-
部署网站
- npm常见命令
1 2
| npm install[i] npm uninstall[un]
|
博客安装
初始化项目
- 创建博客目录
- 安装相关依赖
主题配置
- 安装
butterfly
主题
1
| npm i hexo-theme-butterfly
|
- 应用主题
-
修改根目录下的_config.yml
优化:删除hexo自带的主题配置文件_config.landscape.yml
,以及对应的主题插件
1
| npm un hexo-theme-landscape --save
|
-
安装pug
以及stylus
渲染器
1
| npm install hexo-renderer-pug hexo-renderer-stylus --save
|
- 升级建议
为了减少升级主题后带来的不便,可以将主题文件夹中的_config.yml
文件复制到hexo根目录中,同时重新命名为_config.butterfly.yml
。以后只需要对_config.butterfly.yml
进行配置即可生效。
在下文中,站点配置文件将指代_config.yml
,主题配置文件将指代_config.butterfly.yml
页面配置
标签页
- 创建「source/tags/」目录以及
index.md
文件
- 修改「source/tags/index.md」,添加
type: "tags"
1 2 3 4 5
| --- title: 标签 date: xxxx-xx-xx xx:xx:xx type: "tags" ---
|
分类页
- 创建「source/categories/」目录以及
index.md
文件
1
| hexo new page categories
|
- 修改「source/categories/index.md」,添加
type: "categories"
1 2 3 4 5
| --- title: 分类 date: xxxx-xx-xx xx:xx:xx type: "categories" ---
|
友情链接
- 创建「source/link/」目录以及
index.md
文件
- 修改「source/link/index.md」,添加
type: "link"
1 2 3 4 5
| --- title: 友情链接 date: xxxx-xx-xx xx:xx:xx type: "link" ---
|
- 前往「source/_data」创建
link.yml
(如果没有_data
目录,请自行创建)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| - class_name: 技術支持 🦾 class_desc: 博客搭建过程中参考的网站 link_list: - name: Hexo link: https://hexo.io/ avatar: https://raw.githubusercontent.com/hexojs/logo/master/hexo-logo-avatar.png descr: A fast, simple & powerful blog framework - name: Jerry link: https://butterfly.js.org/ avatar: https://butterfly.js.org/img/avatar.png descr: A Simple and Card UI Design theme for Hexo - class_name: 技術博客 🤖 class_desc: 技术分享 link_list: - name: Jinming Hu link: https://conanhujinming.github.io/ avatar: https://conanhujinming.github.io/authors/admin/avatar_hubd2169f75411e26c6f08e041cf104953_98411_270x270_fill_q90_lanczos_center.jpg descr: Software Engineer - name: Images link: https://imageslr.com/ avatar: https://i.loli.net/2020/02/17/vY49QcyqRlbtB78.jpg descr: Images' Blog
|
插件推荐
网站部署
点击查看教程
- 安装
hexo-deployer-git Public
插件
1
| npm install hexo-deployer-git --save
|
- 修改站点配置文件
1 2 3 4 5
| deploy: type: git repo: <repository url> branch: [branch] message: [message]
|
LATEX
点击查看教程
hexo中支持MathJax
和KaTex
,其中MathJax
支持的功能多,但是渲染时间长,而KaTex
小巧轻快,所以推荐使用KaTex
- 更换插件
1 2 3 4
| npm un hexo-renderer-marked --save npm un hexo-renderer-kramed --save npm i hexo-renderer-markdown-it --save npm install @neilsustc/markdown-it-katex --save
|
- 修改主题配置文件
1 2 3 4
| katex: enable: true per_page: false hide_scrollbar: true
|
- 追加以下选项到站点配置文件
1 2 3 4 5 6
| markdown: plugins: - plugin: name: '@neilsustc/markdown-it-katex' options: strict: false
|
由于第二步中设置的per_page: false
,所以我们在需要渲染LATEX的文章开头添加katex: true
外挂标签 👍
点击查看教程
详见:Tag Plugins Plus
- 安装
hexo-butterfly-tag-plugins-plus
插件
1
| npm install hexo-butterfly-tag-plugins-plus --save
|
考虑到hexo自带的markdown渲染插件hexo-renderer-marked
与外挂标签语法的兼容性较差,建议您将其替换成hexo-renderer-kramed
1 2
| npm uninstall hexo-renderer-marked --save npm install hexo-renderer-kramed --save
|
- 添加配置信息到站点配置文件或主题配置文件中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
tag_plugins: enable: true priority: 5 issues: false link: placeholder: /img/link.png CDN: anima: https://unpkg.zhimg.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/font-awesome-animation.min.css jquery: https://unpkg.zhimg.com/jquery@latest/dist/jquery.min.js issues: https://unpkg.zhimg.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/issues.js iconfont: //at.alicdn.com/t/font_2032782_8d5kxvn09md.js carousel: https://unpkg.zhimg.com/hexo-butterfly-tag-plugins-plus@latest/lib/assets/carousel-touch.js tag_plugins_css: https://unpkg.zhimg.com/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.css
|
具体样式和写法可见:基于Butterfly的外挂标签引入以及Butterfly 安装文档(三) 主题配置-1
本地搜索
点击查看教程
- 安装
hexo-generator-search
插件
1
| npm install hexo-generator-search --save
|
- 修改站点配置文件
_config.yml
1 2 3 4
| search: path: search.xml field: post content: true
|
- 在主题配置文件
_config.butterfly.yml
中开启搜索
1 2 3
| local_search: - enable: false + enable: true
|
点击查看教程
- 安装
hexo-generator-feed
插件
1
| npm install hexo-generator-feed --save
|
- 配置
_config.yml
1 2 3 4
| feed: type: atom path: atom.xml limit: 20
|
- 配置
_config.butterfly.yml
文章链接
点击查看教程
- 安装
hexo-abbrlink
插件
1
| npm install hexo-abbrlink --save
|
- 修改站点配置文件
_config.yml
中的permalink
属性
1 2 3 4
| permalink: posts/:abbrlink.html abbrlink: alg: crc32 rep: hex
|
字数统计
点击查看教程
- 安装
hexo-wordcount
插件
1
| npm install hexo-wordcount --save
|
- 修改主题配置文件
1 2 3 4 5
| wordcount: enable: true post_wordcount: true min2read: true total_wordcount: true
|
Customization
页面美化 👗
一图流 👈
点击查看教程
- 配置自定义样式文件【source/css/custom.css】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #footer { background: transparent !important; } #page-header { background: transparent !important; }
#footer::before { background: transparent !important; } #page-header::before { background: transparent !important; }
[data-theme="dark"] #footer::before { background: transparent !important; } [data-theme="dark"] #page-header::before { background: transparent !important; }
|
- 配置站点配置文件
1 2 3 4 5
| index_img:
footer_bg: false
|
1
| background: url(image_address)
|
个人卡片渐变色
点击查看教程
在【source/css/custom.css】自定义样式文件中引入下面的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| #aside-content > .card-widget.card-info { background: linear-gradient( -45deg, #e8d8b9, #eccec5, #a3e9eb, #bdbdf0, #eec1ea ); box-shadow: 0 0 5px rgb(66, 68, 68); position: relative; background-size: 400% 400%; -webkit-animation: Gradient 10s ease infinite; -moz-animation: Gradient 10s ease infinite; animation: Gradient 10s ease infinite !important; } @-webkit-keyframes Gradient { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } } @-moz-keyframes Gradient { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } } @keyframes Gradient { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
[data-theme="dark"] #aside-content > .card-widget.card-info { background: #191919ee; }
#aside-content > .card-widget.card-info > #card-info-btn { background-color: #3eb8be; border-radius: 8px; }
|
文章双侧栏显示
点击查看教程
- 安装
hexo-butterfly-article-double-row
插件
1
| npm i hexo-butterfly-article-double-row --save
|
- 在网站配置文件中添加以下项
1 2
| butterfly_article_double_row: enable: true
|
- 修复显示bug:在自定义样式文件
custom.css
中添加以下代码
1 2 3 4 5
| #pagination { width: 100%; margin: auto; }
|
wowjs动画
点击查看教程
- 安装
hexo-butterfly-wowjs
插件
1
| npm install hexo-butterfly-wowjs --save
|
- 在站点配置文件或主题配置文件中添加以下选项
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| wowjs: enable: true priority: 10 mobile: false animateitem: - class: recent-post-item style: animate__zoomIn duration: 2s delay: 1s offset: 100 iteration: 1 - class: card-widget style: animate__zoomIn animate_css: https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/animate.min.css wow_js: https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/wow.min.js wow_init_js: https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/wow_init.js
|
小修小补
设置文章大标题前面的图标
1 2 3 4 5
| beautify: enable: true field: site title-prefix-icon: '\f863' title-prefix-icon-color: '#F47466'
|
设置水平分割线图标
1 2 3 4
| hr_icon: enable: true icon: '\f2dc' icon-top: -10px
|
设置通知弹窗
1 2 3
| snackbar: enable: true position: top-left
|
设置中英文之间添加空格
1 2 3
| pangu: enable: true field: site
|
打开字数统计(需安装hexo-wordcount
插件)
1 2
| wordcount: enable: true
|
代码块显示编程语言类型文字居中
1 2 3
| #article-container figure.highlight .highlight-tools .code-lang { left: 50%; }
|
设置在阅读文章时侧边栏只显示toc
- 全局设置:配置站点配置文件
1 2
| toc: style_simple: true
|
- 特定的文章配置:设置文章的
front matter
将导航栏中的搜索图标位置放在右边
1 2 3
| #nav #search-button { float: right; }
|
关闭鼠标靠近头像时头像旋转效果
1 2 3
| .avatar-img img:hover { transform: unset; }
|
设置夜间模式专用背景
1 2 3 4 5 6 7 8 9 10 11
| [data-theme="dark"] #web_bg { position: fixed; z-index: -999; width: 100%; height: 100%; background: url(/img/dark.jpg); background-attachment: local; background-position: center; background-size: cover; background-repeat: no-repeat; }
|