平常工作忙,也没有大把时间好好的选个前端和后端来搭建一个个人的博客。偶然发现这个功能,快速搭建自己的简易博客,虽然功能不如自己定制的用着随心所欲,样式也只能选取固定的主题(其实Hexo的主题也很多),但是对于一个博客小白来说这篇文章再合适不过了。
环境及工具
1.Git
相应安装方法很多,windows,linux和macOS方法也不一样。
curl命令
$ /usr/bin/ruby -e "$(curl -fsSL [https://raw.githubusercontent.com/Homebrew/install/master/install](https://link.jianshu.com/?t=https://raw.githubusercontent.com/Homebrew/install/master/install))"
或者
homebrew命令
brew install git
2.node.js
curl命令
$ curl https://raw.github.com/creationix/nvm/master/install.sh | sh
homebrew命令
brew install node
3.Hexo
安装Hexo
sudo npm install hexo-cli -g
初始化
选择存放站点文件的位置,并执行命令
$ hexo init <folder> # folder文件夹即为存放你的站点的文件夹名字
$ cd <folder>
$ npm install
初始化后文件夹中结构如下
.
├── _config.yml # 站点配置文件
├── package.json
├── scaffolds
├── source # 存放博文
| ├── _drafts
| └── _posts
└── themes # 主题文件夹
在文件夹目录下执行
hexo server
可以看到博客已经在本地的4000端口了。至此博客已经在本地搭建成功。
部署推送
1.在github上创建仓库,仓库名为:<Github账号名称>.github.io
2.安装hexo-deployer-git插件
npm install hexo-deployer-git --save
3.更换个好看的主题
Hexo有很多好看的主题提供https://hexo.io/themes/
我使用的是https://github.com/fi3ework/hexo-theme-archer.git
很受欢迎的next主题用的人也比较多
进入themes文件夹执行git命令下载
git clone https://github.com/iissnan/hexo-theme-next.git
4.修改配置文件./_config.yml
注:改动yml文件别改错“:”后面有空格的!后面如果报错,很有可能是这块没有写好。
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site
title: I'm Peter // 博客的名字
keywords:
author: PeterPZ // 作者的名字
language: zh-Hans // 语言:中文
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: hexo-theme-archer // 博客使用的主题(下载后在themes文件夹下)
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git // 上传方式:git
repo: git@github.com:PeterPZhang/PeterPZhang.github.io.git // github账号/仓库的名称
branch: master
5.写文章并推送至远程仓库
进入站点文件夹下source/_posts目录
新建hello.md文件并用markdown书写吧。
---
title: hello
---
**my first blog**
在本地测试
$ hexo s
推送至github
$ hexo clean && hexo g && hexo d
浏览器输入:https://peterpzhang.github.io/就可以访问自己的博客啦。