Hexo 03 - 部署到Git上

1. deployer发布

  1. 将项目上传到git
  2. 项目内安装hexo deployernpm install hexo-deployer-git --save
  3. 编辑_config.yml,新增deploy,并且更改url地址
    1
    2
    3
    4
    5
    6
    7
    8
    9
    # URL
    ## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
    url: https://umino-natsusou.github.io/<项目名>

    deploy:
    type: git
    repo: https://github.com/<username>/<project>
    # example, https://github.com/hexojs/hexojs.github.io
    branch: gh-pages
  4. 输入 hexo d 发布

2. 公共仓库和私有仓库协同发布

  1. hexo源码上传到私有仓库,令建一个公共仓库用来发布page
  2. 用github工作流来简化发布流程:.github/workflows目录下新建自定义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
    name: Deploy Site
    on:
    push:
    branches: [ main ]

    jobs:
    build:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
    uses: actions/checkout@v3
    with:
    persist-credentials: true # false 是用 personal token,true 是使用 GitHub token
    fetch-depth: 0

    # ... TODO Build your site

    # <work-dir> 静态资源所在的目录
    # <domain> 需要 github.io 绑定的域名
    # <username> git commit 用户名
    # <mail> git commit 邮箱
    # <message> git commit 的 message
    # <secrets_name> Secrets 名称
    # <github_username> github 的用户名(公开仓库)
    # <repo> 公开仓库名
    # 添加域名的在run下添加一行: echo "<domain>" > CNAME
    # secrets是github的全域变量,test是在源码仓库Settings的Secrets里定义的,填上Settings -> Developer settings里的token
    - name: Commit and Push
    working-directory: public
    run: |
    git init
    git checkout -b gh-pages
    git add -A
    git -c user.name='umino-natsusou' -c user.email='uminonatsusou@gmail.com' commit -m 'deploy site'
    git remote add origin https://${{secrets.test}}@github.com/umino-natsusou/AncientreesDeploy.git
    git push origin gh-pages -f -q