name: Deploy to Git-Pages
on:
  push:
    branches:
      - main

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4
        with:
          submodules: true

      - name: Setup Hugo
        uses: peaceiris/actions-hugo@v3
        with:
          hugo-version: 'latest'
          extended: true

      - name: Build Hugo
        run: hugo --minify

      - name: Deploy to 'pages' branch
        run: |
          # 1. Configure Git
          git config --global user.name "Gitea Actions"
          git config --global user.email "actions@gitea.com"

          # 2. Prepare the directory for a fresh branch
          # We move the contents of 'public' into a temporary folder
          mkdir ../temp_pages
          cp -r public/* ../temp_pages/
          
          # 3. Initialize a new git repository in the temp folder
          cd ../temp_pages
          git init
          git checkout -b pages
          
          # 4. Add files and commit
          git add .
          git commit -m "Deploy from Gitea Actions"
          
          # 5. Push to the pages branch
          # We use your personal access token (PAT) for authentication
          git push --force https://oauth2:${{ secrets.ACCESS_TOKEN }}@git.wompmacho.com/${{ github.repository }}.git pages