Skip to content

Deploy

Publish public/ to GitHub Pages, Cloudflare Pages or any static host, with the right baseURL, CI settings, security policy, checks and rollback.

An OINK site builds to a directory of static files, so any host that serves files can serve it, with no Node runtime, server-side rendering or build plugin. Deploying comes down to three things: run the production build, publish public/, and set baseURL to the address readers will use. A site created from the OINK Starter already has GitHub Pages and Cloudflare Pages workflows that do all three.

Getting baseURL right

A wrong baseURL is the most common deployment fault, and a quiet one: pages open, but the search index returns 404, page-action links point elsewhere and some assets fail to load.

At the root of a domain:

hugo.yml
baseURL: https://docs.example.com

Under a subpath such as https://example.com/docs/, include the path:

hugo.yml
baseURL: https://example.com/docs/

You can also override it at build time, which lets one source tree deploy to several addresses:

Terminal
hugo --gc --minify --baseURL "https://example.com/docs/"
Do not fix a subpath with canonifyURLs

Leave canonifyURLs at Hugo’s default, false. OINK’s templates and content links resolve against baseURL, so a wrong path means a wrong baseURL. Turning on canonifyURLs also rewrites relative links that were already correct, which makes the fault harder to find.

With local search enabled, open search on the deployed site and watch the index request in the browser’s Network panel: it must carry the right language and subpath and return 200. Take the URL from the page’s data-td-index-src attribute instead of guessing it, because production filenames include a content hash (offline-search-index.<language>.<hash>.json).

Choosing a host

If the source lives on GitHub, one Actions workflow builds the site and publishes it through the Pages deployment API, with no gh-pages branch to maintain. The OINK Starter ships this file; copy it only when you assemble a site yourself.

.github/workflows/github-pages.yaml
 1name: Deploy to GitHub Pages
 2
 3on:
 4  push:
 5    branches: [main]
 6  workflow_dispatch:
 7
 8permissions:
 9  contents: read
10  pages: write
11  id-token: write
12
13concurrency:
14  group: github-pages
15  cancel-in-progress: false
16
17env:
18  # a workspace from a sibling checkout must never take part in a CI build
19  GOWORK: off
20  HUGO_MODULE_WORKSPACE: off
21  HUGO_CACHEDIR: ${{ github.workspace }}/.hugo_cache
22
23jobs:
24  build:
25    name: Build Pages artifact
26    runs-on: ubuntu-latest
27    steps:
28      - name: Check out source
29        uses: actions/checkout@v7
30        with:
31          fetch-depth: 0
32
33      - name: Set up Go
34        uses: actions/setup-go@v7
35        with:
36          go-version: stable
37          cache-dependency-path: go.sum
38
39      - name: Configure GitHub Pages
40        id: pages
41        uses: actions/configure-pages@v6
42
43      - name: Install Hugo
44        uses: peaceiris/actions-hugo@v3
45        with:
46          hugo-version: latest
47
48      - name: Record build tool versions
49        run: |
50          go version
51          hugo version
52
53      - name: Download OINK
54        run: go mod download github.com/pgsty/oink
55
56      - name: Build
57        run: |
58          hugo --cleanDestinationDir --gc --minify --environment production \
59            --printPathWarnings \
60            --baseURL "${{ steps.pages.outputs.base_url }}/"
61
62      - name: Upload Pages artifact
63        uses: actions/upload-pages-artifact@v5
64        with:
65          path: public
66
67  deploy:
68    name: Deploy
69    environment:
70      name: github-pages
71      url: ${{ steps.deployment.outputs.page_url }}
72    runs-on: ubuntu-latest
73    needs: build
74    steps:
75      - name: Publish
76        id: deployment
77        uses: actions/deploy-pages@v5

Build settings for CI explains each setting; keep them when you edit the file. One is specific to GitHub Pages: --baseURL takes the address that configure-pages computes, https://<OWNER>.github.io/<REPO>/ for a project site, so you never hard-code it.

In the repository, set Settings → Pages → Build and deployment → Source to GitHub Actions, push to main, and watch the first run on the Actions tab.

For a custom domain, enter it under Custom domain on the same settings page, configure DNS as prompted, and set baseURL in hugo.yaml to the new domain. If your publishing process needs a CNAME file, put it at static/CNAME; Hugo copies it unchanged into public/.

The OINK Starter ships .github/workflows/cloudflare-pages.yaml, a Direct Upload workflow: the production build runs in GitHub Actions with the same build settings as the GitHub Pages workflow, and Wrangler uploads the resulting public/ to a Cloudflare Pages project. It is the recommended path for Starter sites.

  1. Create a Direct Upload Pages project. Its name defaults to the repository name; to use another, set the repository variable CLOUDFLARE_PROJECT_NAME.
  2. Add the repository secrets CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_API_TOKEN. The token needs Account → Cloudflare Pages → Edit.
  3. Run Deploy to Cloudflare Pages once by hand. To deploy every push to main, set the repository variable CLOUDFLARE_PAGES_ENABLED=true.
  4. The canonical URL defaults to https://<project>.pages.dev/. When a custom domain becomes production, set CLOUDFLARE_SITE_URL to it.

Cloudflare’s Git integration also works, with Cloudflare running the build: set the build command to hugo --gc --minify --printPathWarnings, the output directory to public, and HUGO_VERSION to a current release such as 0.170.1 (OINK is tested on 0.170+, while Cloudflare’s default image ships an older Hugo). Choose one mode per project, Git integration or the Direct Upload workflow, and build preview deployments with their own URL and a non-production environment.

On a custom domain, Cloudflare can mistake module@version in an install command for an email address. This documentation site adds no-transform to the HTML response’s Cache-Control header in static/_headers. After deploying, open an install example on the production domain with JavaScript disabled and copy the command. Cloudflare email obfuscation

Netlify — set the build command to hugo --gc --minify, the publish directory to public, and the HUGO_VERSION environment variable. The same settings can live in the repository:

netlify.toml
[build]
command = "hugo --gc --minify --printPathWarnings"
publish = "public"

[build.environment]
# override the platform's default with a current Hugo release (tested on 0.170+)
HUGO_VERSION = "0.170.1"

A theme installed as a submodule needs recursive submodule checkout enabled; one installed as a Hugo Module needs Git and Go in the build image. Build previews with the same Hugo release as production, unless the preview exists to test an upgrade.

Vercel — set the build command to hugo --gc --minify, the output directory to public, and the HUGO_VERSION environment variable. There is no npm install step.

Any static server (Nginx, Caddy) — serve an unchanged copy of public/. The example serves /var/www/oink/current, a symlink to a release directory that the offline packaging steps below create:

/etc/nginx/conf.d/docs.conf
server {
    listen 80;
    server_name docs.example.com;
    root /var/www/oink/current;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }

    error_page 404 /404.html;
}

The site is purely static, so there is nothing to proxy to an application server.

Object storage — Hugo’s deploy command uploads to S3, Google Cloud Storage or Azure. Name the target in the configuration:

hugo.yml
deployment:
  targets:
    - name: aws
      URL: 's3://www.your-domain.tld'
      cloudFrontDistributionID: E9RZ8T1EXAMPLEID

After a build, hugo deploy compares the bucket with public/, uploads only what changed, and invalidates the CDN cache when cloudFrontDistributionID is set. Without --target it uses the first target; run it with --dryRun first to see what it would change. The Hugo binary must be built withdeploy (check hugo version), and the cloud credentials come from the provider’s standard environment variables or configuration file; on AWS, confirm access with aws s3 ls first.

Offline packaging — for a network-isolated server, build on a connected machine with the target’s baseURL and carry the output over as one archive. Give every archive a new release name:

Terminal
hugo --cleanDestinationDir --gc --minify --baseURL "https://docs.internal.example.com/" &&
  tar -czf oink-site-20260929-01.tar.gz -C public .

On the Linux host you need write access to /var/www/oink and GNU mv; current must be absent or a symlink, and current.next must not exist. Unpack each release into a new directory and switch current to it:

Linux host
release_dir=/var/www/oink/releases/20260929-01
mkdir -p /var/www/oink/releases
mkdir "$release_dir" &&
  tar -xzf oink-site-20260929-01.tar.gz -C "$release_dir" &&
  test -f "$release_dir/index.html" &&
  ln -s "$release_dir" /var/www/oink/current.next &&
  mv -Tf /var/www/oink/current.next /var/www/oink/current

The chain switches current only after the directory was created, the archive extracted and index.html found, and the final mv replaces the link in one step, so readers never see a half-written site. Never unpack over an existing release directory, and keep the previous one: it is your rollback. A different baseURL means a new build, not an edit of the output.

A host without Go — a theme installed as a Hugo Module needs Go in the build environment. Where the platform has none, install the theme as a Git submodule (run git submodule update --init before the build) or commit an offline archive under themes/oink/; see From scratch and other install methods.

Build settings for CI

These settings belong in any CI build of an OINK site, whichever host receives the output. The Starter’s workflows already contain them.

  • fetch-depth: 0 on checkout — with enableGitInfo, last-modified dates and contributor lists come from Git history, and a shallow clone gives every page the same date.
  • Go, then go mod download github.com/pgsty/oink — Hugo needs Go to fetch a theme installed as a Hugo Module. A submodule install checks out with submodules: recursive instead, and an offline archive is committed under themes/oink/; either way, drop both Go steps.
  • GOWORK: off and HUGO_MODULE_WORKSPACE: off — keep a developer’s Go workspace out of the build, so CI builds the release pinned in go.mod and nothing else.
  • Hugo latest — OINK uses plain CSS and is tested on Hugo 0.170+, so CI can follow current releases. A site still pinned to OINK 1.5.1 or older cannot; see Upgrade.
  • --environment production and the real --baseURL — the environment decides indexing and analytics (see below), and baseURL every absolute link.
  • --printPathWarnings, and no --panicOnWarning — OINK’s warnings are deliberate: a mistyped key or an incomplete integration warns and falls back to a safe default so the site still builds. Turning warnings into errors with --panicOnWarning or HUGO_PANICONWARNING would fail builds that are fine. Read the warnings in the build log instead.

Keeping preview deployments unindexed

Hugo’s -e / --environment changes how OINK builds, not what the site contains. Only a production build:

  • emits <meta name="robots" content="index, follow"> (other environments emit noindex, nofollow);
  • writes Allow: / and a Sitemap: line to robots.txt (other environments write Disallow: /);
  • renders the Google Analytics snippet;
  • fingerprints the theme’s scripts and stylesheets and adds SRI integrity attributes.

hugo defaults to production, even on a preview host, so build pull-request previews and staging sites with another environment:

Terminal
hugo --gc --minify --environment staging --baseURL "$PREVIEW_URL"

The output then asks search engines to stay away and sends nothing to an analytics service.

Content Security Policy

The theme’s scripts, fonts and icons are all served from your own origin, but script-src 'self'; style-src 'self' alone still blocks parts of an ordinary OINK page. The theme writes small inline scripts that set the color mode and the page shell’s state before the first paint, inline styles for the initial canvas, theme colors and font roles, and style attributes on some components; Markmap adds inline configuration and styles. OINK ships no ready-made policy, CSP hashes or nonce injection, so derive the policy from your own built output.

Features you enable add their own requirements:

  • Inline HTML and scripts that authors write under renderer.unsafe: true are the site’s to review.
  • ECharts $fn: callbacks and custom themes: the site registers its functions on window.OinkEchartsFunctions and its themes on window.OinkEchartsThemes, so the registering script’s origin belongs in script-src.
  • Analytics scripts: the script you insert, and the host it reports to.
  • Local PlantUML rendering: same-origin scripts, wasm-unsafe-eval in script-src to compile WebAssembly, and blob: in img-src. No rendering-service origin is needed.
  • Remote API specifications and self-hosted diagram services: their origins in connect-src and img-src.
  • giscus: both script-src and frame-src.
  • Interactive maps (params.map): your tile and dark_tiles hosts in img-src.
  • Video platform players (params.video_embeds): the enabled player origins (https://www.youtube-nocookie.com, https://player.bilibili.com, https://player.vimeo.com) in frame-src, plus any remote media, poster, subtitle track or social-avatar hosts in media-src, img-src and connect-src.
  • Duo view and ReDoc API references render in same-origin frames, so frame-src (or child-src) must allow 'self', and responses must allow same-origin framing (no X-Frame-Options: DENY or frame-ancestors 'none'). Duo view also adds an inline bootstrap script to every HTML page, which changes the script hashes.

Hash each inline script and style block you allow from the final deployed bytes, or have the host inject a fresh nonce into both the policy header and the matching tags on every response. A <style> nonce does not cover style="…" attributes, which need style-src-attr of their own. Hashes change with content, configuration, minification and theme upgrades, so recompute them after each.

Start from a minimal policy that covers only the features you have reviewed, and add permissions one at a time: keep ECharts options as pure data when no callback is needed, review author-written inline scripts, and add a remote origin only for an integration the site explicitly enabled. The output checker in Verifying an offline build lists every subresource origin, which is a good starting inventory. Ship the policy as Content-Security-Policy-Report-Only first, and enforce it only after light/dark startup, shell state, menus and every enabled component work in the browser.

Acceptance checklist

Go through this table after each deployment. The first four rows can be checked in the build output; the rest need the real URL.

The build succeeded and you read its warnings
The log of a build with --printPathWarnings ends with Total in …
baseURL is correct
<link rel="canonical"> in the page source points at the real production address, subpath included
Sitemap
<baseURL>/sitemap.xml resolves; on a multilingual site it is an index pointing at /en/sitemap.xml, /zh/sitemap.xml and so on
robots
<baseURL>/robots.txt reads Allow: / with a Sitemap: line; a preview deployment reads Disallow: /
Search index
With local search enabled, the URL in data-td-index-src returns 200, its filename carries a hash, and site search returns results
Markdown output
Where the site enables markdown under outputs.page, appending index.md to a page URL returns plain text
llms.txt
Where the site enables LLMS under outputs.home, the root of every enabled language serves llms.txt
Every language
Documentation, blog and home pages open in each, and the language switcher lands on the matching page rather than the home page
Appearance and interaction
The light/dark toggle, the print view and common components (callouts, tabs, code-block copy) work
404
A path that does not exist shows the site’s own 404 page

The switches for sitemap.xml, robots.txt, .md and llms.txt are in Configuration, and the agent-facing outputs are described in AI-agent support.

Rollback

Roll back a static site by publishing the last known-good build again. Never patch files on the production host, because the next deploy silently undoes the patch and nothing records what changed.

  • GitHub Pages: find the last successful Deploy to GitHub Pages run under Actions and choose Re-run all jobs, or git revert the faulty commit and push.
  • Cloudflare Pages, Netlify, Vercel: pick the last good deployment in the platform’s list and promote it with Rollback or Publish deploy.
  • Your own static server: point current back at the previous release directory kept by offline packaging. Do not extract the old archive over the new files; paths that only the newer release added would stay live.

On the Linux host, with the same symlink and GNU mv prerequisites as above, replace the example with the release you kept:

Terminal
previous_release=/var/www/oink/releases/20260928-01
test -d "$previous_release" &&
  ln -s "$previous_release" /var/www/oink/current.next &&
  mv -Tf /var/www/oink/current.next /var/www/oink/current

Then open an old page at the public URL, and confirm that a path only the rejected release added is gone.

If a theme upgrade caused the problem, roll back the version pin in go.mod instead; see Upgrade.