Protected posts

A protected post shows its title and a password field. After the build, a script encrypts the post and every file in its bundle. The reader’s browser decrypts them when the password is right. The Showcase has one to try, Protected post example; its hint gives the password away.

This keeps casual readers out, not determined ones: read How safe it is before you rely on it.

Protect a post

A protected post must be a leaf bundle: a directory with index.md and the files the post uses.

content/posts/secret/
├── index.md
├── photo.jpg
└── notes.pdf

Turn protection on in the front matter. Everything below the front matter, and every file in the directory, is encrypted.

content/posts/secret/index.md
+++
title = 'Secret'
date = 2026-11-21
[protected]
  enabled = true
  password = 'a long passphrase'
  hint = 'Shown above the password field'
+++
ParameterDefaultDescription
enabledfalsetrue turns protection on.
password—Required, or the build fails. Use a long passphrase.
hint—Shown above the password field. Public.

Only files inside the bundle are encrypted. Files in static/, assets/ or another page’s bundle, local copies of remote images, and remote audio or video stay public. Don’t give a protected post a cover image; it is never shown.

What stays public

PublicEncrypted
Title, date and hintThe content
The post’s line in archives, tag pages and the home pageEvery file in the bundle, with its resized versions
Comments and analytics, if enabled

A protected post has no table of contents, tags, cover, social image, copyright card or structured data. It is marked noindex and left out of search, feeds, the sitemap and the tag counts. To turn off comments or analytics on it too, set comments = false or analytics = false.

Warning

Never link to a protected post from a public page. With full-text RSS the link ends up in the feeds, and verify.mjs fails on any protected route it finds there. Mention the post by name instead.

Translations

On a multilingual site, protect every translation of a post, or none. Each translation needs its own [protected] table, and the passwords may differ. Translations share the bundle’s files, so protecting only some of them fails sealing or publishes the files unencrypted.

Seal and verify

Encryption is a step after hugo. Run these three commands locally and in CI:

sh
hugo --gc --minify --cleanDestinationDir
node themes/hugo-theme-icy/tools/protect/seal.mjs public
node themes/hugo-theme-icy/tools/protect/verify.mjs public
  • seal.mjs encrypts each protected post, deletes the plaintext, and removes tag pages that list only protected posts. --dry-run shows what it would do.
  • verify.mjs checks that every protected post is sealed and that no protected route appears in feeds, the sitemap or the search index. It exits with code 1 on any error.

Always build into a clean directory, or seal.mjs stops. It also stops, changing nothing, when a protected post is not a leaf bundle or a public page uses its files. Deployment has complete pipelines with these steps.

Preview the sealed site

hugo server doesn’t seal, so it can’t show real decryption. preview.mjs builds, seals, verifies and serves the result locally:

sh
node themes/hugo-theme-icy/tools/protect/preview.mjs
OptionDefaultDescription
--site DIRCurrent directoryThe Hugo site.
--destination DIR<site>/publicOutput directory, inside the site. It is cleaned.
--draftsOffInclude drafts and future posts.
--build-onlyOffStop after verifying.
--no-buildOffServe an existing sealed output.
--port N1313Port.
--host H127.0.0.1Address.

The build warning

A production build logs a warning for each protected post, reminding you to seal it:

WARN icy: /posts/secret/ is password-protected; run tools/protect/seal.mjs (and verify.mjs) on the output before deploying

A build with --panicOnWarning fails on it. Once every deployment seals and verifies, silence it:

hugo.toml
ignoreLogs = ['icy-protected-unsealed']

How safe it is

This hides content in the browser; it is not access control on the server. The encrypted file is public, so a weak password can be guessed offline, and anyone who unlocks the post can copy it. The password never leaves the browser and is not stored.

The format and the cryptography are explained in the author’s article Hugo 实现页面加密 (in Chinese).