Coding Pages/Github 搭建 Hexo 静态博客

安装hexo

我的小窝:https://zelsonia.coding.me/ , https://zelsonia.github.io/

  • 准备:node.js(npm), git, coding账号或github账号
  1. npm install -g hexo 安装hexo

  2. 在本地sites(站点根目录)下新建空文件夹来放置hexo(随意起名) touch hexo

  3. 初始化 hexo init

  4. 本地打开查看是否运行成功

$ hexo g
$ hexo s 
这两行命令是下面两个的缩写
hexo generate
hexo server

网址输入localhost:4000 查看效果

部署到coding,github

  1. npm install --save hexo-deployer-git
    安装这个,要不之后会报错error deployer not found:git

  2. coding新创建项目,把ssh copy下来,修改根目录的配置文件_config.yml,注意缩进,还有冒号后的空格

deploy:
  type: git
  repository:
      github: [email protected]:zelsonia/zelsonia.github.io.git
      coding: [email protected]:zelsonia/zelsonia.git
  branch: master
  1. 在博客的source/目录下需要创建一个空白文件,至于原因,是因为 coding.net需要这个文件来作为以静态文件部署的标志。就是说看到这个Staticfile就知道按照静态文件来发布。
    coding还需要在根目录下建一个.nojekyll空文件(coding page 配置hexo报错 the xx theme not be found
    在根目录下建一个.nojekyll空文件就可以了,因为Coding默认支持Jekyll搭建网站)
cd source/
touch Staticfile 

cd ../
到hexo
touch .nojekyll

hexo clean
hexo d -g

  1. coding 上选择pages服务, 选master分支,他就自行部署了。成功后,若是没有样式,检查库名是否是github:用户名.github.io coding: 用户名,config里url,root可以注释掉。

ps: 整个这个文件夹目前不需要git init,push之类的操作,如果要用到travis ci之后会用到。

  1. 要部署到github只要创建 用户名.github.io库,然后config加上那行,再部署上去就行,不需要到page服务选择设置。

更新hexo

更新hexo:
npm update -g hexo

更新主题:
cd 到主题文件夹,执行命令:
git pull

更新插件:
npm update

你可能感兴趣的:(Coding Pages/Github 搭建 Hexo 静态博客)