把hugo自动部署到虚拟主机

· 默认分类

之前的hugo部署在github上,但是GitHub一直也不稳定,有时能上有时上不了。

这两天找到一个免费虚拟主机,也没有什么网站可以搭建,就想着把hugo同步到虚拟主机里。

然后今天就实现了。

就是利用gith的workflows,把生成的静态页面推送到虚拟主机。

name: Deploy Hugo

on:
  push:
    branches:
      - master   # master 更新触发

jobs:
  build-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      # 添加 Node.js 版本设置步骤
      - name: Setup Node.js
        uses: actions/setup-node@v4  # 官方 Node.js 环境配置 Action
        with:
          node-version: '18.x'  # 指定需要的 Node.js 版本(例如 16.x、18.x、20.x 等)

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v2
        with:
          hugo-version: '0.88.0'

      - name: Build 
        run: hugo

      - name: Deploy to GitHub Pages
        uses: peaceiris/actions-gh-pages@v3
        with:
          personal_token: ${{ secrets.personal_token }}
          PUBLISH_BRANCH: gh-pages
          PUBLISH_DIR: ./public
          commit_message: ${{ github.event.head_commit.message }}
      
      - name: Deploy to FTP (虚拟空间)
        uses: SamKirkland/FTP-Deploy-Action@v4.3.4
        with:
          server: ${{ secrets.FTP_SERVER }}
          username: ${{ secrets.FTP_USERNAME }}
          password: ${{ secrets.FTP_PASSWORD }}
          local-dir: ./public/
          server-dir: /
          delete-remote: true

这样就可以了。

找到几个二级域名,感觉还行。

gs.ye.gs

ww.god.sd

aabb.qzz.io