本篇文章主要讲了我在搭建个人博客时遇到的一些问题,以及使用github + hexo 搭建个人博客的大致方向,希望可以帮助到有需要的人。

GitHub

1、使用GitHub 账号创建一个new repository

create a new repository

  • 重点: 创建new repository 的 name 格式必须为{userName}.github.io, 其中userName为github账号的用户名

2、拉代码创建index.html

  • 将github的代码down 下来 然后创建一个index.html 并先输入一些内容进行相关显示用于后续检查是否创建并上传成功成功
  • 创建好后 提交代码 便可以访问 http://userName.github.io 检查是否成功

3、HEXO

1
2
hexo init // 创建一个空文件并使用hexo 初始化
hexo new [layout] <title> // 创建一个新文件
  • 具体命令可详见官网 https://hexo.io/docs/commands
  • 还可对一些基本配置进行修改 文件: _config.yml
  • 可以在官网选择自己喜欢的主题 进入相对应的github 地址进行clone 然后在hexo文件进行安装 npm install ****.git 会相对应生成一个主题文件 需要在_config.ymltheme 属性修改为新安装的主题名称

4、 hexo 与 github 进行连接

  • _config.yml 中修改下列属性 repository 为github 的SSH(必须只能是SSH)、branch 为分支
    1
    2
    3
    4
    deploy:
    type: git
    repository: git@github.com:liuchuanyang65/liuchuanyang65.github.io.git
    branch: master

修改成功后 hexo d -g 即可直接上传到github 并可查看http://userName.github.io 观察效果

5、 在 hexo 编辑中上传本地图片

  • 1
    npm install https://github.com/CodeFalling/hexo-asset-image --save  // 安装插件
  • 1
    hexo n other // 新建一个other的文件 同时会生成一个other文件夹 将图片放置在other文件夹即可
  • 1
    ![图片无法加载时显示的文案](文件夹名/图片名) // 引入图片格式