当前位置

网站首页> 程序设计 > 开源项目 > 程序开发 > 浏览文章

hexo在github和gitcafe搭建个人博客 - 心如止水

作者:小梦 来源: 网络 时间: 2024-05-23 阅读:

1.准备工作

  1. 安装nodejs

    • 去官网下载nodejs安装(推荐安装0.12.x),安装之后在命令行 node -v,如果成功说明node环境ok,不成功就去环境变量配置一下.

  2. 安装hexo

    • 使用命令 npm install hexo -g,执行hexo -v 查看版本,本教程适合3.1.1版本

  3. 安装git

    • 去官网下载git安装,不会自行百度

  4. 配置git

    • 配置ssh私钥,上传到github上

2.github-pages和gitcafe-page的说明

  1. github有两种主页,一种是github-page(个人主页),一种是项目主页,本教程针对个人主页

  2. gitcafe-page的个人主页只是在项目下有一个gitcafe-pages的分支,部署成功后访问主页即可

  3. github-page需要将hexo博客发布到repository的master(主干)即可

  4. gitcafe需要将hexo博客发布到repository的gitcafe-pages的分支

3.使用hexo写博客

- 新建一个文件夹myblog,- 右键git bash here使用git的shell- 在shell中输入hexo init,回车执行- 在shell中输入hexo g ,回车- 在shell中hexo s,回车- 去浏览器访问http://localhost:4000,访问到主页,然后在shell中ctrl c停止- 在shell中hexo new "first-blog",回车- 在shell中hexo g ,回车- 在shell中hexo s ,回车,在访问- ok,在本地测试就没问题了

4.发布到github和gitcafe

- 打开项目根部录下的.config.yml,找到deploy,修改如下:
   deploy:    - type: git      repo: git@github.com:yourname/yourname.github.io.git,master    - type: git       repo: git@gitcafe.com:yourname/yourname.git,gitcafe-pages
- 如果只发布到github或者gitcafe上,修改如下:git的branch是master,gitcafe的是gitcafe-pages
deploy:  type: git  repo: <repository url>  branch: [branch]  message: [message]

5.常见问题

  1. 部署时出现git not found

    • npm install hexo-deployer-git --save 安装依赖包

博客效果可以看我的个人博客 我的个人博客