Preface

Remind me not to forget to STUDY.

TODO:

解决visitors && visits目前数目相同的问题

Install Hexo

Requirement

Install Git

Install Node.js

1
2
3
# environments
# # MBP M1 Pro
# # Sonoma 14.0

直接从Node.js下载安装包,会遇到EACCES的权限问题,npm Docs给出了指导

1
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash

repo被glone在~/.nvm当中,将环境变量添加到~/.zshrc

1
2
3
4
vim ~/.zshrc

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
  • Verify
1
2
command -v nvm
# output: nvm
  • Usage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Install latest release of node
nvm install node # "node" is an alias for the latest version

# Install a specific version
nvm install 14.7.0 # or 16.3.0, 12.22.1, etc

# The first version installed becomes the default. New shells will start with the default version of node
nvm alias default

# List available version
nvm ls-remote

# Use the installed version
nvm use node

# Where installed
nvm which 12.22
  • Check version npm and node.js
1
2
3
4
node -v
# v21.1.0
npm -v
10.2.0

Install

1
2
3
4
npm install -g hexo-cli

# Usage
npx hexo <command>

New Hexo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mkdir blog
cd blog

hexo init
npm install

# Tree
# # .
# # ├── _config.yml
# # ├── package.json
# # ├── scaffolds
# # ├── source
# # | ├── _drafts
# # | └── _posts
# # └── themes

Hexo常用命令

1
2
3
hexo clean
hexo g
hexo s

Themes

Choose Chic

1
2
cd blog/themes
git clone https://github.com/Siricee/hexo-theme-Chic.git Chic

Add Tag, Category etc.

1
2
3
4
5
6
7
8
9
hexo new page tag

cd source/tag

# source\tag\index.md
---
title: Tag
layout: tag
---

MathJax

Chic/_config.yml

1
2
3
4
5
6
7
8
# plugin functions
## Mathjax: Math Formula Support
## https://www.mathjax.org
mathjax:
enable: true
import: global # global or demand
## global: all pages will load mathjax,this will degrade performance and some grammers may be parsed wrong.
## demand: if your post need fomula, you can declare 'mathjax: true' in Front-matter
  • enable:默认开启

  • import:MathJax的加载方式,可以为globaldemand

    • global:全局,所有页面都加载,比较方便,但是可能导致部分markdown语法错误解析,比如连续的$$$$会解析为公式,在没有公式的页面浪费性能

    • demand:【推荐】,如果需要,在Front-matter中声明

      1
      2
      3
      4
      5
      6
      ---
      title: MathJax Test
      date: 2019-07-05 21:27:59
      tags:
      mathjax: true # 加入这个声明,这篇文章就会开启mathjax渲染
      ---

Deploy

Server

开启服务及端口

  • 首先在server端开启ssh
1
2
# 生成公私钥文件,指定算法、邮箱
ssh-keygen -t rsa -C "xxx"
  • 将client端的id_rsa.pub拷贝到server的authorized_key

  • 在client端的~/.ssh/config中添加配置

1
2
3
4
Host test  # 登录简称,与sever控制台设置的名称对应
HostName ip # 服务器ip
Port 22 # 登录服务器的端口
User root # 用户名

打开server端的端口规则

  • 云服务器ECS控制台

  • 网络与安全->安全组–>管理规则->(入方向)手动添加

Nginx && hook

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
# 1. ssh
# 2. install Git && nginx
apt-get update
apt-get install git nginx -y

# 3. repo
# # 3.1 make repo
mkdir /var/repo

# # 3.2 权限
chown -R $USER:$USER /var/repo/
chmod -R 755 /var/repo/

# # 3.3 init git
cd /var/repo
git init --bare blog.git

# 4. nginx
# # 4.1 make hexo
mkdir -p /var/www/hexo

# # 4.2 权限
chown -R $USER:$USER /var/www/hexo
chmod -R 755 /var/www/hexo

# # 4.3 修改 Nginx 的 default 文件使得 root 指向刚刚创建的 /var/www/hexo目录:
vim /etc/nginx/sites-available/default
#------------------------------------#
# Before: root /var/www/html
# After : root /var/www/hexo
#------------------------------------#

# # 4.4 Restart Nginx
service nginx restart
#------------------------------------#
# 输入公网ip可以测试结果
#------------------------------------#

# 5. Hooks
# # 5.1 在blog.git/hooks中新建hooks并添加内容
vim /var/repo/blog.git/hooks/post-receive
#-------------------------------------------------------------------------#
#!/bin/bash
git --work-tree=/var/www/hexo --git-dir=/var/repo/blog.git checkout -f
#-------------------------------------------------------------------------#

# # 5.2 添加权限
chmod +x /var/repo/blog.git/hooks/post-receive

Local

  • Install 插件
1
npm install hexo-deployer-git --save
  • blgo/_config.yml
1
2
3
4
5
deploy:
type: git
repo: <repository url> #https://bitbucket.org/JohnSmith/johnsmith.bitbucket.io
branch: [branch]
message: [message]/可选
  • 生成并推送
1
2
hexo clean
hexo g -d