GitHub + Hexo 个人博客再搭建

写在前面

去年年中的时候,用 GitHub Page 和 Hexo 搭建过个人的博客,后来因为麻烦就搁置了。今天重新搭建配置了一下,记录下过程。

前期准备

安装 Hexo

  • 先本地建一个博客目录,然后 cd 到该目录下
  • 使用 npm i -g hexo 命令安装 Hexo
  • 然后使用 hexo init 进行初始化操作

搭建博客

  • 在 Github Page 的页面,创建 name.github.io 页面
  • 然后在本地博客根目录下的 _config.yml 文件中,进行如下配置:
    1
    2
    3
    4
    5
    6
    7
    # URL
    ## If your site is put in a subdirectory,
    ## set url as 'http://yoursite.com/child' and root as '/child/'
    url: http://caoqi95.github.io/
    root: /
    permalink: :year/:month/:day/:title/
    permalink_defaults:
1
2
3
4
5
6
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: git@github.com:caoqi95/caoqi95.github.io.git
branch: master

P.S: 这里需要注意,冒号后面要空一格,最好用编辑器打开

  • 执行以下命令,复制给出的链接在浏览器中打开,即可预览博客
    1
    2
    3
    hexo clean
    hexo generate # or hexo g
    hexo server # or hexo s

部署博客

  • 先执行以下命令,安装一些依赖的工具

    1
    npm install hexo-deployer-git --save
  • 在执行以下命令,进行部署

    1
    2
    3
    hexo clean
    hexo generate # or hexo g
    hexo deploy

等待几分钟,就可以进入个人的 github.io 的页面了。

优化博客

默认的主题比较中规中矩,不合口味的话,可以进入 Themes | Hexo 页面,然后根据自己的喜好更换主题。我选择了 lite 这个主题,效果如下所示。具体的配置过程,各个主题都会有教程的,一步步按照着来即可。

我的博客链接:https://caoqi95.github.io

发布文章

  • 在终端中,进入博客的根目录,然后执行以下命令:

    1
    hexo new "文章题目"
  • 然后在 myBlog\source\_posts 目录下,会出现新建的 .md 文件

  • 写完再进行部署即可。