0. 安装前提
Windows系统下安装 Hexo,需要先安装下列应用程序。
1. 安装、初始化 Hexo
1 2 3 4 5 6
知识兔td> | $ npm install -g hexo-cli
# 创建博客主文件夹为: hexo $ hexo init hexo $ cd hexo $ npm install
知识兔td> |
创建新 post,新建的 post 文件位于source/_posts
文件夹内。
1
知识兔td> | $ hexo new "My New Post"
知识兔td> |
2. 服务器
首先安装hexo-server,运行服务器。
1 2
知识兔td> | $ npm install hexo-server --save $ hexo server
知识兔td> |
网站会在 http://localhost:4000 下启动。
3. 更换主题
在终端窗口下,定位到 Hexo 站点目录下。使用 Git checkout 主题代码。
1 2
知识兔td> | $ cd hexo $ git clone https://github.com/theme-next/hexo-theme-next themes/next
知识兔td> |
打开站点配置文件blog/_config.yaml
,找到 theme 字段,并将其值更改为 next。
运行服务器,验证主题是否正确启用。
1 2
知识兔td> | $ hexo clean $ hexo server
知识兔td> |
3.1 主题配置
打开主题配置文件hexo/themes/next/_config.yml
,更改Scheme字段。
1 2 3
知识兔td> |
scheme: Pisces
知识兔td> |
3.2 更新主题
打开主题配置文件夹`hexo/themes/next’。
1 2 3 4 5 6
知识兔td> | $ cd themes/next $ git pull
$ git fetch --all大专栏 Hexo 安装与配置pan> $ git reset --hard origin/master
知识兔td> |
4. 站点配置
打开站点配置文件._config.yaml
,更改相关字段。
1 2 3 4 5 6 7 8 9 10
知识兔td> | author: shen bo language: zh-Hans timezone: Asia/Shanghai
url: https://shenbo.github.io
deploy: type: git repo: 该邮件地址已受到反垃圾邮件插件保护。要显示它需要在浏览器中启用 JavaScript。:shenbo/shenbo.github.io.git branch: master
知识兔td> |
5. Git 配置
打开git bash,设置用户名,并生成ssh-key
。
1 2 3 4 5 6
知识兔td> | $ git config --global user.name "shenbo" $ git config --global user.email "该邮件地址已受到反垃圾邮件插件保护。要显示它需要在浏览器中启用 JavaScript。"
$ ssh-keygen -t rsa -b 4096 -C "该邮件地址已受到反垃圾邮件插件保护。要显示它需要在浏览器中启用 JavaScript。" $ eval $(ssh-agent -s) $ ssh-add ~/.ssh/id_rsa
知识兔td> |
复制~/.ssh/id_rsa.pub
,在 github 个人设置页面,点击新建或添加 SSH key,将id_rsa.pub
内容复制进去。
测试 git 客户端与 github 是否连接成功。
1
知识兔td> | $ ssh -T 该邮件地址已受到反垃圾邮件插件保护。要显示它需要在浏览器中启用 JavaScript。
知识兔td> |
如果连接报错ssh: connect to host github.com port 22: Connection > refused
打开/新建~/.ssh/config
,修改内容如下,重新测试。
1 2 3 4 5 6
知识兔td> | Host github.com User 该邮件地址已受到反垃圾邮件插件保护。要显示它需要在浏览器中启用 JavaScript。 Hostname ssh.github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa Port 443
知识兔td> |
如果连接报错"Deployer not found: git"
,安装hexo-deployer-git。
1
知识兔td> | $ npm install hexo-deployer-git --save
知识兔td> |
6. 生成 & 发布
1 2
知识兔td> | $ hexo generate $ hexo deploy
知识兔td> |