# Hosting

## Prerequisites

Before deploying, make sure your site builds locally with `hugo` without errors.

## Deploy to GitHub Pages

GitHub Pages builds your site using GitHub Actions. The workflow installs Hugo, runs Pagefind, and publishes the result. Your repository must be hosted on GitHub.

1. In your repository, go to **Settings > Pages**.

2. Under **Build and deployment**, set the source to **GitHub Actions**.

3. Create `.github/workflows/deploy.yml`. The workflow has two jobs: `build` checks out the repo, installs Hugo and Node dependencies, builds the site, runs Pagefind, and uploads the output as an artifact. `deploy` then publishes that artifact to GitHub Pages.

    ```yaml {title=".github/workflows/deploy.yml"}
    name: Deploy to GitHub Pages

    on:
      push:
        branches:
          - main
      workflow_dispatch:

    permissions:
      contents: read
      pages: write
      id-token: write

    concurrency:
      group: pages
      cancel-in-progress: false

    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
          - name: Checkout
            uses: actions/checkout@v6
            with:
              submodules: recursive
              fetch-depth: 0  # Optional, for enableGitInfo

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

          - name: Setup Pages
            id: pages
            uses: actions/configure-pages@v6

          - name: Setup NodeJS
            uses: actions/setup-node@v6
            with:
              node-version: '22'

          - name: Install dependencies
            run: npm install

          - name: Build site
            run: hugo --gc --minify --baseURL "${{ steps.pages.outputs.base_url }}"

          - name: Index with Pagefind
            run: npm run pagefind

          - uses: actions/upload-pages-artifact@v3
            with:
              path: public

      deploy:
        needs: build
        runs-on: ubuntu-latest
        environment:
          name: github-pages
          url: ${{ steps.deployment.outputs.page_url }}
        steps:
          - id: deployment
            uses: actions/deploy-pages@v4
    ```

4. Commit and push the file. GitHub Actions will trigger automatically.

## Deploy to Other Hosting Services

See Hugo's [official tutorial](https://gohugo.io/host-and-deploy/). Add `npm run pagefind` to your build step to generate the search index.
