Hexo 安装与配置

0. 安装前提

Windows系统下安装 Hexo,需要先安装下列应用程序。

1. 安装、初始化 Hexo

1
2
3
4
5
6
$ npm install -g hexo-cli

# 创建博客主文件夹为: hexo
$ hexo init hexo
$ cd hexo
$ npm install

创建新 post,新建的 post 文件位于source/_posts文件夹内。

1
$ hexo new "My New Post"

2. 服务器

首先安装hexo-server,运行服务器。

1
2
$ npm install hexo-server --save
$ hexo server

网站会在 http://localhost:4000 下启动。

3. 更换主题

在终端窗口下,定位到 Hexo 站点目录下。使用 Git checkout 主题代码。

1
2
$ cd hexo
$ git clone https://github.com/theme-next/hexo-theme-next themes/next

打开站点配置文件blog/_config.yaml,找到 theme 字段,并将其值更改为 next。

1
theme: next

运行服务器,验证主题是否正确启用。

1
2
$ hexo clean
$ hexo server

3.1 主题配置

打开主题配置文件hexo/themes/next/_config.yml,更改Scheme字段。

1
2
3

#scheme: Mist
scheme: Pisces

3.2 更新主题

打开主题配置文件夹`hexo/themes/next’。

1
2
3
4
5
6
$ cd  themes/next
$ git pull

# 强制更新
$ git fetch --all大专栏  Hexo 安装与配置pan>
$ git reset --hard origin/master

4. 站点配置

打开站点配置文件._config.yaml,更改相关字段。

1
2
3
4
5
6
7
8
9
10
author: shen bo
language: zh-Hans
timezone: Asia/Shanghai

url: https://shenbo.github.io

deploy:
type: git
repo: [email protected]:shenbo/shenbo.github.io.git
branch: master

5. Git 配置

打开git bash,设置用户名,并生成ssh-key

1
2
3
4
5
6
$ git config --global user.name "shenbo"
$ git config --global user.email "[email protected]"

$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
$ eval $(ssh-agent -s)
$ ssh-add ~/.ssh/id_rsa

复制~/.ssh/id_rsa.pub,在 github 个人设置页面,点击新建或添加 SSH key,将id_rsa.pub内容复制进去。

测试 git 客户端与 github 是否连接成功。

1
$ ssh -T [email protected]

如果连接报错ssh: connect to host github.com port 22: Connection > refused

打开/新建~/.ssh/config,修改内容如下,重新测试。

1
2
3
4
5
6
Host github.com
User [email protected]
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

如果连接报错"Deployer not found: git",安装hexo-deployer-git。

1
$ npm install hexo-deployer-git --save

6. 生成 & 发布

1
2
$ hexo generate
$ hexo deploy

猜你喜欢

转载自www.cnblogs.com/wangziqiang123/p/11691308.html