0%

如何使用Hexo发布博客到GitHub Pages

使用Hexo写博客,发布到GitHub Pages

  1. 安装Hexo

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    $ sudo npm install -g hexo-cli
    $ hexo -v
    hexo: 3.9.0
    hexo-cli: 1.0.2
    os: Linux 4.4.0-154-generic linux x64
    http_parser: 2.8.0
    node: 10.15.3
    v8: 6.8.275.32-node.51
    uv: 1.23.2
    zlib: 1.2.11
    ares: 1.15.0
    modules: 64
    nghttp2: 1.34.0
    napi: 3
    openssl: 1.1.0j
    icu: 62.1
    unicode: 11.0
    cldr: 33.1
    tz: 2018e
  2. 创建博客项目

    1
    2
    3
    4
    5
    6
    7
    8
    $ hexo init yt8yt.github.io
    $ cd yt8yt.github.io
    $ npm install

    3. 测试刚刚创建的项目

    ```shell
    hexo server

    使用浏览器访问本机4000端口。

  3. 更新博客配置信息

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    $ vi _config.yml
    # Site
    title: yt8yt's note
    subtitle:
    description: yt8yt's personal blog
    author: yt8yt
    language:
    timezone: Japan

    # URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: http://yt8yt.github.io/
    root: /
    permalink: :year/:month/:day/:title/
    permalink_defaults:
  4. 安装发布包

    1
    2
    3
    4
    5
    6
    7
    8
    $ sudo npm install hexo-deployer-git --save
    $ vi _config.yml
    # Deployment
    ## Docs: http://hexo.io/docs/deployment.html
    deploy:
    type: git
    repo: git@github.com:yt8yt/yt8yt.github.io.git
    branch: master
  5. 配置watch监控文件改动

    1
    $ hexo generate --watch
  6. 创建新博客文章

    1
    $ hexo new first-post
  7. 使用markdown语言编辑博客文章

  8. 删除source/_posts/hello-world.md

  9. 发布!

    1
    2
    $ hexo clean
    $ hexo deploy

    你应该会在GitHub Pages看到你的博客了,地址为http://****.github.io

  10. 改变主题
    例如,安装https://hexo.io/hexo-theme-light/主题。

    1
    2
    3
    4
    5
    6
    7
    8
    ## 安装
    $ cd yt8yt.github.io
    $ git clone git://github.com/tommy351/hexo-theme-light.git themes/light

    ## 改变配置文件
    $ cd yt8yt.github.io
    $ vi _config.yml
    theme: light
  11. 创建新页面
    1
    2
    3
    $ hexo new page aboutme
    $ cd source/aboutme
    $ vi index.md

原文地址。