使用hexo搭建博客,托管于github
配置环境: node + git
hexo
安装hexo
npm install hexo -g
初始化hexo
hexo init 或 hexo init <文件名>
注:不加文件名会在当前目录下下载初始文件
生成静态页面
hexo generate 或 hexo g
本地启动服务
hexo server 或 hexo s
浏览器输入http://localhost:4000可以看到主页,默认主题landscape
github
新建项目
项目名称与git账号名称一致
复制项目ssh地址
配置hexo+git
在本地hexo初始化后的文件找到 _config.yml
在文件中找到
deploy:
修改为
deploy:
type: git
repo: [email protected]:yourname/yourname.github.io.git //复制的ssh地址,yourname为账户名
branch: master
部署
部署前要先安装自动部署工具
npm install hexo-deployer-git --save
部署
hexo d
浏览器输入 yourname.github.io可以看到博客的主页了(yourname为git账户名)
hexo 命令
hexo init //初始化项目
hexo generate //生成静态页面
hexo clean //清除生成静态页面
hexo server //启动本地服务
hexo deploy //部署
hexo new page 'example' //新建名为example页面
hexo new 'example' //新建名为example文章
报错处理
ERROR Deployer not found: git
解决方法:
npm install hexo-deployer-git –save
接下来就可以开启博客之旅啦!^_^