博客启动!

blog.mornw.com!

为什么写博客?

看见舍友的网站是在是好看,羡慕之余,自然也想自己做一个。

做个什么样的网站?

问:越简单越好不是吗?
答:轻量级博客,静态网站、方便的整理自己的文章。让我找到了HEXO。

问:需要评论功能吗?
答:不需要,也没人看不是吗(当然我也想让人看啦!T.T)

问:图床用什么呀?
答:我是十分倾向于选择 github 的,很多人都说 github 访问速度慢,目前就使用 CDN 加速吧。

开始博客搭建

想写博客,当然是先搭建图床啦!

1. 图床

  1. 在 github 上创建一个公开的图床仓库。

  2. 下载 PicGO。

  • github 生成自己的 token 时,需要勾选 repo 项。

  • 设置 CDN 加速

2. 安装 hexo + hexo-theme-melody

  1. 在 github 上创建一个 github pages。
    比如我的是: onlywant.github.io

  2. 安装 nodejs 和 npm。

  3. 创建一个博客文件夹

  4. npm install hexo --save

  5. npm install hexo-theme-melody --save

  6. 即可使用hexo -g && hexo -s,生成自己的博客,本地查看。

  7. 推送到远端仓库

    • 设置博客根目录中的_config.yml中的deploy项为自己的 github pages 地址。

    • 即可使用hexo -d推送到远端。

3. 使用github actions自动编译发布网站

  1. 在 github 上创建 blog 源代码仓库,上传自己的源代码。

  2. 设置两个仓库的沟通桥梁

    • 使用 ssh-keygen 生成一对公私钥。
    • 在源代码仓库settings->secrets->actions中添加 HEXO_DEPLOY_PRI,内容为私钥。
    • 在 pages 仓库settings->deploy keys中添加 HEXO_DEPLOY_PUB, 内容为公钥。
  3. 在仓库根目录下添加.github/workflow/deploy.yml文件。内容如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    name: CI

    on:
    push:
    branches:
    - master

    env:
    GIT_USER: 你的名字
    GIT_EMAIL: 你的email地址
    DEPLOY_REPO: 推送到的仓库
    DEPLOY_BRANCH: 仓库分支

    jobs:
    build:
    name: Build on node ${{ matrix.node_version }} and ${{ matrix.os }}
    runs-on: ubuntu-latest
    strategy:
    matrix:
    os: [ubuntu-latest]
    node_version: [12.x]

    steps:
    - name: Checkout
    uses: actions/checkout@v2

    - name: Checkout deploy repo
    uses: actions/checkout@v2
    with:
    repository: ${{ env.DEPLOY_REPO }}
    ref: ${{ env.DEPLOY_BRANCH }}
    path: .deploy_git

    - name: Use Node.js ${{ matrix.node_version }}
    uses: actions/setup-node@v1
    with:
    node-version: ${{ matrix.node_version }}

    - name: Configuration environment
    env:
    HEXO_DEPLOY_PRI: ${{secrets.HEXO_DEPLOY_PRI}}
    run: |
    sudo timedatectl set-timezone "Asia/Shanghai"
    mkdir -p ~/.ssh/
    echo "$HEXO_DEPLOY_PRI" > ~/.ssh/id_rsa
    chmod 600 ~/.ssh/id_rsa
    ssh-keyscan github.com >> ~/.ssh/known_hosts
    git config --global user.name $GIT_USER
    git config --global user.email $GIT_EMAIL
    - name: Install dependencies
    run: |
    npm install
    - name: Deploy hexo
    run: |
    npm run clean
    npm run build
    npm run deploy

博客启动!
http://blog.mornw.com/2021/06/16/日记/hexo_write/
作者
朝霞换夕阳
发布于
2021年6月16日
许可协议