github+hexo+mac建博客

由于板瓦工升级,之前的wordpress弃坑,转hexo+github方案

一 安装node.js

  1. 安装node
1
2
3
brew link node
brew uninstall node
brew install node
  1. 验证node
1
2
npm -v
node -v
  1. 卸载node
1
brew uninstall node

二 配置ssh免密登陆

  1. 配置免密登陆
1
github->setting->SSH And GPG keys->New SSH Key
  1. 验证配置成功
1
ssh -T git@github.com

输入yes

显示:

1
2
Warning: Permanently added 'github.com,192.30.252.130' (RSA) to the list of known hosts.
You've successfully authenticated, but GitHub does not provide shell access.

三 安装hexo,部署项目

  1. 安装hexo
1
npm install -g hexo-cli
  1. 创建项目
1
2
3
hexo init <folder>
cd <folder>
npm install
  1. 本地部署
1
2
3
hexo generate
本地部署:
hexo server
  1. 部署到github
1
vim _config.yml

进入文件最后部分

1
2
3
4
deploy:
type: git
repository: https://github.com/qingzhouzhen/qingzhouzhen.github.io
branch: master

部署:

1
2
hexo g
hexo d

若执行hexo g出错则执行npm install hexo --save,若执行hexo d出错则执行npm install hexo-deployer-git --save。错误修正后再次执行hexo ghexo d上传到服务器。

  1. 更换next主题,进入到项目根目录
1
git clone https://github.com/iissnan/hexo-theme-next themes/next

四 绑定域名

  1. github端

在项目主题中source文件夹中创建CNAME文件,没有后缀名,然后将个人域名huanghanqing.com添加进CNAME文件即可,然后通过hexo g hexo d重新部署网站。

  1. 域名解析

登陆域名解析商:https://www.dnspod.cn/console/dns/huanghanqing.com

  • 记录类型:CNAME
  • 主机记录:@
  • 解析线路:默认
  • 记录值:qingzhouzhen.github.io

重新建一个记录,因为我之前指向了板瓦工端ip,这里指向了CNAME,把之前存在的cname记录删掉重新建一个

next 主题设置

文章只显示预览,themes->next->_config.yml

1
2
3
4
5
# Automatically Excerpt. Not recommand.
# Please use <!-- more --> in the post to control excerpt accurately.
auto_excerpt:
enable: false
length: 150

false改为true

参考:

https://zhuanlan.zhihu.com/p/34654952

https://www.jianshu.com/p/5031134c374e