如何搭建自己的博客

  1. 安装hexo
1
2
3
4
npm install hexo-cli -g
hexo init myBlog
cd myBlog
yarn install
  1. 安装自己喜欢的主题,拉取到本地:

    可以在这里选择:

    1
    2
    http://jekyllthemes.org/  # 点击文章标题可以获得github地址
    https://hexo.io/themes/ # 直接点进去就能看到github地址

然后:

1
2
cd myBlog/themes
git clone https://github.com/jangdelong/hexo-theme-xups.git # 这是你选择的主题的地址
  1. 配置默认主题:

    在myBlog下的_config.yml中:

    1
    theme: hexo-theme-xups # 主题的名字
  2. 运行:hexo s --watch

    1
    2
    3
    cd myBlog
    hexo generate
    hexo s --watch
  3. 发布到git上:

    (1) 创建一个仓库,仓库名与owner名相同:
    (2) 将自己的myBlog推到该仓库中即可(好像可以不要这一步直接第三步,大家可以试试,不行就走下这步):

    1
    2
    3
    git init
    git remote add origin https://github.com/yourcode/yourcode.github.io.git
    git push origin master #在这之前把你电脑的SSH_KEY加到仓库哈,这个不会google去

    (3) 配置deploy的东西-myblog/_config.yml中:

    1
    2
    3
    4
    5
    6
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
    type: git
    repository: https://github.com/yourcode/yourcode.github.io.git
    branch: master

    (4) hexo deploy 即可发布到github.

    1
    2
    3
    hexo clean
    hexo generate
    hexo deploy

    (5) 访问: https://yourcode.github.io 这个yourcode就是第一张图里的spcBackToLife对应地方的名。其实就是新建的仓库名。
    (6) https://github.com/spcBackToLife/spcBackToLife.github.io/settings 可以看到部署成功与否的状态。

    1. 如何让博客中有评论功能–githubcomment。

      此处选用的主题是:https://github.com/jangdelong/hexo-theme-xups
      这个人正好是用的git做的评论,其余模板有的不是用git,此处以这个为例子。
      (1)在themes/hexo-theme-xups的_config.yml中配置评论:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      #----------------------------
      # 是否开启评论
      #----------------------------
      comment:
      enable: true
      owner: spcBackToLife # 你自己的github名字
      repo: spcBackToLife.github.io # 就是我们刚才创建仓库的名字
      client_id: id # 是需要创建一个application 获得的id
      client_secret: secret # 是需要创建一个application 获得的secret

      (2)如何创建application:https://github.com/settings/applications/new:

      (3) 创建完了即可看到自己的id 和 secret, 也可以到https://github.com/settings/appsOAuth Apps看到。

  4. 如何插入图片:
    (1) yarn add hexo-asset-image
    (2) 我的版本是: v1.0.0,但是有bug,路径不对。去node_modules/hexo-asset-image/index.js修改下路径就好。

    (3) 可能你遇到的路径情况如果还有不同的话,反正就看着 hexo generate 时候打出的日志: update link as,去对应调整路径就好。不麻烦。

  5. 限制每篇文章摘要部分,只需要在相应的隔断地方加:

有问题欢迎加群沟通哦: