Become a backer or sponsor to support our work.
The encrypt module allows encrypting or protecting partial contents.
| Module | github.com/hugomods/encrypt |
|---|---|
| Stats |
This module ships with a shortcode and a CLI tool, to walk though the Hugo generated files and encrypt the content in AES-256-GCM.
graph TD; content[Protect content via shortcode `encrypt`]-->build; build[Build site, i.e. `hugo --minify --gc ...`]-->encrypt[Encrypt content via `$HOME/go/bin/encrypt`];
The difference between this and normal build is that, you need to combine the CLI tool with Hugo, i.e.
1hugo && $HOME/go/bin/encrypt
There are some stuff you should pay attention to.
To get the CLI tool, you can either download from the releases or install from source.
1go install github.com/hugomods/encrypt/commands/encrypt@latest
Then you’re able to access the command
1$HOME/go/bin/encrypt
This section is for developers to integrate this module into their themes.
hugo.yaml
1module:
2 imports:
3 - path: github.com/hugomods/encrypt
hugo.toml
1[module]
2 [[module.imports]]
3 path = 'github.com/hugomods/encrypt'
hugo.json
1{
2 "module": {
3 "imports": [
4 {
5 "path": "github.com/hugomods/encrypt"
6 }
7 ]
8 }
9}
Note
Please skip this step if your theme supports HugoPress, such as HB Framework themes.
1{{ partial "encrypt/assets/css" . }}
Note
Please skip this step if your theme supports HugoPress, such as HB Framework themes.
1{{ partial "encrypt/assets/js" . }}
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
password | string | Y | - | The default password. |
storage | string | Y | session | session (SessionStorage) or local (LocalStorage). |
hugo.yaml
1params:
2 encrypt:
3 password: DEFAULT_PASSWORD
4 storage: session
hugo.toml
1[params]
2 [params.encrypt]
3 password = 'DEFAULT_PASSWORD'
4 storage = 'session'
hugo.json
1{
2 "params": {
3 "encrypt": {
4 "password": "DEFAULT_PASSWORD",
5 "storage": "session"
6 }
7 }
8}
This section shows users how to protect their contents, please make sure you’ve imported the module.
Default password:
hugomods.com.
1{{< encrypt >}}
2Hello World!
3{{< /encrypt >}}
The following content is protected.
1{{% encrypt %}}
2**Hello World!**
3{{% /encrypt %}}
The following content is protected.
1{{% encrypt foo %}}
2**Bar!**
3{{% /encrypt %}}
The following content is protected.
Since the command must be executed after building the site, that is, it won’t work with the hugo server.
Firstly, build the site and encrypt the content.
1hugo -b http://localhost:8081 && $HOME/go/bin/encrypt
And then setup a HTTP server to serve the encrypted contents, such as http-server and PHP built-in server.
-b http://localhost:8081 to override the baseURL for testing.To get the http-server by executing npm install --global http-server.
1http-server -p 8081 public
If you’ve PHP installation on your environment.
1php -S 0.0.0.0:8081 -t public
It’s a fork of Hugo Encrypt, and port it for Hugo modules.