0. 安装前提
Windows系统下安装 Hexo,需要先安装下列应用程序。
1. 安装、初始化 Hexo
123456 | $ 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,运行服务器。
12 | $ npm install hexo-server --save$ hexo server |
网站会在 http://localhost:4000 下启动。
3. 更换主题
在终端窗口下,定位到 Hexo 站点目录下。使用 Git checkout 主题代码。
12 | $ cd hexo$ git clone https://github.com/theme-next/hexo-theme-next themes/next |
打开站点配置文件blog/_config.yaml
,找到 theme 字段,并将其值更改为 next。
1 | theme: next |
运行服务器,验证主题是否正确启用。
12 | $ hexo clean$ hexo server |
3.1 主题配置
打开主题配置文件hexo/themes/next/_config.yml
,更改Scheme字段。
123 | #scheme: Mistscheme: Pisces |
3.2 更新主题
打开主题配置文件夹`hexo/themes/next’。
123456 | $ cd themes/next$ git pull# 强制更新$ git fetch --all大专栏 Hexo 安装与配置pan>$ git reset --hard origin/master |
4. 站点配置
打开站点配置文件._config.yaml
,更改相关字段。
12345678910 | author: shen bolanguage: zh-Hanstimezone: Asia/Shanghaiurl: https://shenbo.github.iodeploy: type: git repo: git@github.com:shenbo/shenbo.github.io.git branch: master |
5. Git 配置
打开git bash,设置用户名,并生成ssh-key
。
123456 | $ git config --global user.name "shenbo"$ git config --global user.email "shenbo@hotmail.com"$ ssh-keygen -t rsa -b 4096 -C "shenbo@hotmail.com"$ eval $(ssh-agent -s)$ ssh-add ~/.ssh/id_rsa |
复制~/.ssh/id_rsa.pub
,在 github 个人设置页面,点击新建或添加 SSH key,将id_rsa.pub
内容复制进去。
测试 git 客户端与 github 是否连接成功。
1 | $ ssh -T git@github.com |
如果连接报错ssh: connect to host github.com port 22: Connection > refused
打开/新建~/.ssh/config
,修改内容如下,重新测试。
123456 | Host github.comUser shenbo@hotmail.comHostname ssh.github.comPreferredAuthentications publickeyIdentityFile ~/.ssh/id_rsaPort 443 |
如果连接报错"Deployer not found: git"
,安装hexo-deployer-git。
1 | $ npm install hexo-deployer-git --save |
6. 生成 & 发布
12 | $ hexo generate$ hexo deploy |