step1. 安装hexo
安装nodejs git Nginx hexo
Linux
1 2 3 4 5 6 7 8 9 10
| sudo apt update && sudo apt upgrade -y
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - sudo apt install -y nodejs
node -v npm -v
sudo npm install -g hexo-cli
|
Windows
windows不用安装Nginx
访问 Node.js 官网 下载Node.js
1 2 3 4 5
| node -v npm -v
npm install -g hexo-cli
|
初始化hexo, 安装butterfly主题
1 2 3 4 5 6
| mkdir BLOG && cd BLOG
hexo init
git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
|
安装必要插件
必装插件
1 2
| npm install hexo-deployer-git --save npm install hexo-renderer-pug hexo-renderer-stylus --save
|
选装插件
1 2 3 4 5 6 7 8 9
| npm install hexo-wordcount --save
npm install hexo-generator-search --save
npm un hexo-renderer-marked --save npm un hexo-renderer-kramed --save npm i hexo-renderer-markdown-it --save npm install katex @renbaoshuo/markdown-it-katex
|
[!NOTE]
选装插件装完之后还需要在配置文档中进行配置,详情见后续配置部分
选装插件装完之后还需要在配置文档中进行配置,详情见后续配置部分
step2. 部署到服务器
1 2 3 4 5 6
| sudo apt update && sudo apt upgrade -y
sudo apt install -y curl git nginx
mkdir BLOG && cd BLOG
|
配置git仓库
1 2 3 4
| git init --bare BLOG.git
vim BLOG.git/hooks/post-receive
|
1 2
| git --work-tree=/var/www/BLOG --git-dir=/root/BLOG/BLOG.git checkout -f
|
赋予脚本执行权限:
1
| chmod +x BLOG.git/hooks/post-receive
|
在_config.yml
中添加如下代码(ip与地址需自行更改)
1 2 3 4
| deploy: type: git repo: root@<ip>:/root/BLOG/BLOG.git branch: master
|
配置nginx
1 2 3
| mkdir -p /var/www/BLOG sudo chmod -R 755 /var/www/BLOG sudo vim /etc/nginx/sites-available/BLOG
|
进行如下设置,其中server_name
部分要填写域名或ip地址,多个地址用空格隔开:
1 2 3 4 5 6 7 8 9 10
| server { listen 80; server_name <your server name>; root /var/www/BLOG; index index.html;
location / { try_files $uri $uri/ =404; } }
|
1 2 3
| sudo ln -s /etc/nginx/sites-available/BLOG /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx
|
step3. 配置butterfly主题
以下为linux操作,window同理
[!NOTE]
[option]
由于升级主题会覆盖配置文件,所以建议将配置文件复制一份到hexo的根目录下(和config.yml
一起):
1 2 3 4
| touch _config.butterfly.yml
cp themes/butterfly/_config.yml _config.butterfly.yml
|
[option]
由于升级主题会覆盖配置文件,所以建议将配置文件复制一份到hexo的根目录下(和config.yml
一起):
1 2 3 4
| touch _config.butterfly.yml
cp themes/butterfly/_config.yml _config.butterfly.yml
|
新建标签页、分类页
标签页
1 2 3 4
| hexo new page tags
vim source/tags/index.md
|
1 2 3 4 5 6 7
| --- title: 标签 date: 2018-01-05 00:00:00 type: 'tags' orderby: length order: -1 ---
|
参数见:Butterfly 文檔(二) 主題頁面 | Butterfly
分类页
1 2 3 4
| hexo new page categories
vim source/categories/index.md
|
1 2 3 4 5
| --- title: 分类 date: 2018-01-05 00:00:00 type: 'categories' ---
|
设置404页面(_config.butterfly.yml
)
将enable 从 false
改为true
,自定义subtitle 和 background。
background的位置是相对于source目录的位置
1 2
| vim _config.butterfly.yml
|
1 2 3 4 5
| error_404: enable: true subtitle: 'Page Not Found' background: /img/error-page.png
|
更改语言、网站资料(_config.yml
)
主要改title
,author
,language
三个参数
正常显示latex公式(_config.yml
)
参考官方文档
step1.(安装插件时已做过)
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 katex @renbaoshuo/markdown-it-katex
|
step2.
1 2 3
| markdown: plugins: - '@renbaoshuo/markdown-it-katex'
|
[!IMPORTANT]
在更更改完之后使用
使更改生效
未完待续…