0%

Hexo博客搭建

起因

旧的博客站数据丢失,导致各种东西找不回,重新搭建一个新的博客觉得太费时,找到了Hexo

配置环境

  • Node
  • Git

开始配置

Node安装

Windows

官网下载
https://nodejs.org/en/
我用的是v6.10
安装完使用 node -v 验证下

Mac

  1. 安装 homebrew
1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  1. brew 升级
1
brew update
  1. 确保brew安全可靠
1
brew doctor
  1. 修复警告

  2. 通过brew安装node和npm

1
2
3
brew link node
brew uninstall node
brew install node
  1. 测试node和npm安装是否成功
1
npm install -g grunt-cli

安装hexo

1
npm install -g hexo

博客初始化

1
2
3
4
5
cd $work
mkdir blog
hexo init
hexo generate (hexo g 简写)
hexo server(hexo s简写)

完成后 浏览器输入http://localhost:4000

使用github委托

1.需要在github上注册帐号
2.如果你的github用户名为${your_name},仓库名必须为${your_name}.github.io
3.配置_config.yml建立github 和hexo网站的关联

1
vi _config.xml

修改最下面

1
2
3
4
deploy:
type: git
repository: https://github.com/${your_name}/${your_name}.github.io.git
branch: master

执行命令完成git 部署

1
npm install hexo-deployer-git --save

然后发布到github上

1
hexo deploy(hexo d 简写)

发布完以后可以到地址访问

hexo 部署相关

以后每次部署都可以按这个来

1
2
3
hexo clean
hexo generate
hexo deploy

列出常用的 hexo 命令

1
2
3
4
5
6
7
hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #将.deploy目录部署到GitHub
hexo help #查看帮助
hexo version #查看Hexo的版本

一些不错的主题列表

 Cover - A chic theme with facebook-like cover photo
 Oishi - A white theme based on Landscape plus and Writing.
 Sidebar - Another theme based on Light with a simple sidebar
 TKL - A responsive design theme for Hexo.
 Tinnypp - A clean, simple theme based on Tinny
 Writing - A small and simple hexo theme based on Light
 Yilia - Responsive and simple style 优雅简洁响应式主题,我用得就是这个。
 Pacman voidy - A theme with dynamic tagcloud and dynamic snow

使用其他域名委托

可能你有自己的域名
这里可以使用 CNAME 指向

1
2
3
4
5
cd source
echo 'www.yourdomain.com'>CNAME
#重新发布
hexo g
hexo d

hexo插件

1
2
3
4
5
6
npm install --save hexo-filter-flowchart #流程图插件
npm install --save hexo-generator-amp #amp
npm install --save hexo-generator-mip #mip
npm install --save hexo-generator-feed #feed
npm install --save hexo-generator-baidu-sitemap #sitemap

修改域名委托
我是万网的

添加新的解析记录

记录类型为 CNAME
主机记录为 www,如果是子域名这里修改为子域名, blog.yourdomain.com ,这里则填写 blog
记录值为 ${your_name}.github.io

参考

http://www.jianshu.com/p/834d7cc0668d
http://leopardpan.github.io/

Hexo博客系列

欢迎关注我的其它发布渠道