Deploy
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:
Under a subpath such as https://example.com/docs/, include the path:
You can also override it at build time, which lets one source tree deploy to several addresses:
canonifyURLsLeave 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.
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.
- Create a Direct Upload Pages project. Its name defaults to the
repository name; to use another, set the repository variable
CLOUDFLARE_PROJECT_NAME. - Add the repository secrets
CLOUDFLARE_ACCOUNT_IDandCLOUDFLARE_API_TOKEN. The token needs Account → Cloudflare Pages → Edit. - Run Deploy to Cloudflare Pages once by hand. To deploy every push to
main, set the repository variableCLOUDFLARE_PAGES_ENABLED=true. - The canonical URL defaults to
https://<project>.pages.dev/. When a custom domain becomes production, setCLOUDFLARE_SITE_URLto 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:
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:
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:
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:
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:
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: 0on checkout — withenableGitInfo, 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 withsubmodules: recursiveinstead, and an offline archive is committed underthemes/oink/; either way, drop both Go steps. GOWORK: offandHUGO_MODULE_WORKSPACE: off— keep a developer’s Go workspace out of the build, so CI builds the release pinned ingo.modand nothing else.- Hugo
latest— OINK uses plain CSS and is tested on Hugo0.170+, so CI can follow current releases. A site still pinned to OINK 1.5.1 or older cannot; see Upgrade. --environment productionand the real--baseURL— the environment decides indexing and analytics (see below), andbaseURLevery 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--panicOnWarningorHUGO_PANICONWARNINGwould 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 emitnoindex, nofollow); - writes
Allow: /and aSitemap:line torobots.txt(other environments writeDisallow: /); - renders the Google Analytics snippet;
- fingerprints the theme’s scripts and stylesheets and adds SRI
integrityattributes.
hugo defaults to production, even on a preview host, so build pull-request
previews and staging sites with another environment:
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: trueare the site’s to review. - ECharts
$fn:callbacks and custom themes: the site registers its functions onwindow.OinkEchartsFunctionsand its themes onwindow.OinkEchartsThemes, so the registering script’s origin belongs inscript-src. - Analytics scripts: the script you insert, and the host it reports to.
- Local PlantUML rendering: same-origin scripts,
wasm-unsafe-evalinscript-srcto compile WebAssembly, andblob:inimg-src. No rendering-service origin is needed. - Remote API specifications and self-hosted diagram services: their origins in
connect-srcandimg-src. - giscus: both
script-srcandframe-src. - Interactive maps (
params.map): your tile anddark_tileshosts inimg-src. - Video platform players (
params.video_embeds): the enabled player origins (https://www.youtube-nocookie.com,https://player.bilibili.com,https://player.vimeo.com) inframe-src, plus any remote media, poster, subtitle track or social-avatar hosts inmedia-src,img-srcandconnect-src. - Duo view and ReDoc API references render in same-origin frames, so
frame-src(orchild-src) must allow'self', and responses must allow same-origin framing (noX-Frame-Options: DENYorframe-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
--printPathWarningsends withTotal in … baseURLis correct<link rel="canonical">in the page source points at the real production address, subpath includedSitemap<baseURL>/sitemap.xmlresolves; on a multilingual site it is an index pointing at/en/sitemap.xml,/zh/sitemap.xmland so onrobots<baseURL>/robots.txtreadsAllow: /with aSitemap:line; a preview deployment readsDisallow: /Search index- With local search enabled, the URL in
data-td-index-srcreturns 200, its filename carries a hash, and site search returns results Markdown output- Where the site enables
markdownunderoutputs.page, appendingindex.mdto a page URL returns plain text llms.txt- Where the site enables
LLMSunderoutputs.home, the root of every enabled language servesllms.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
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 Pagesrun under Actions and choose Re-run all jobs, orgit revertthe 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
currentback 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:
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.
Related
- Local preview — the production build, clearing caches and offline verification
- Troubleshooting — 404s, empty search and platform-specific faults
- Analytics and SEO — being indexed correctly after launch
- Upgrade — upgrading the theme and rolling it back
- Configuration —
baseURL,outputsand the other site keys