Hugo 11 Encrypted Document

Encrypted document password: password

文章的部分内容被密码保护:

Hugo-Encrypt

try golong version test in macgo get github.com/PuerkitoBio/goquery

introduction

  1. Installation and Usage

  2. Configuration

  3. Using the {{% hugo-encrypt %}} tag in your blog posts

Installation and Usage

1mkdir lib
2cd lin
3git clone  https://github.com/Izumiko/hugo-encrypt.git

Place shortcodes/hugo-encrypt.html in the shortcode directory of your blog:

1mkdir -p ~/layouts/shortcodes
2cd ~/layouts/shortcodes
3cp ../../lib/hugo-encrypt/shortcodes/hugo-encrypt.html .

Merge i18n translation files or add it to an existing language file. Remember to set language in your configuration .

1    $ cat i18n/en.toml >> $HUGO_BLOG/i18n/en-us.toml
2    $ cp -r i18n $HUGO_BLOG

Option A: Build it

  • Requirements: go 1.11+

  • Step 1: Install hugo-encrypt.

    (Optional) set the BINDIR to specify a custom install location (default: /usr/local/bin)

    goquery安装失败是缺少net依赖包。 获取 golang.org/x/net 包,其实只需要以下步骤:

1mkdir -p $GOPATH/src/golang.org/x 
2cd $GOPATH/src/golang.org/x 
3git clone https://github.com/golang/net.git
4git clone https://github.com/golang/crypto.git

go get github.com/PuerkitoBio/goquery

1make
2make install

Result:

1install -m755 hugo-encrypt /usr/local/bin/hugo-encrypt
  • Step 2: Use hugo-encrypt to encrypt content
1        $ hugo
2        $ hugo-encrypt -sitePath public

Option B: Use docker

  • Requirements: docker
1        $ hugo
2        $ docker run -it --rm \
3            -v $HUGO_BLOG/public:/data/site \
4            chaosbunker/hugo-encrypt hugo-encrypt -sitePath /data/site`

After generating the site with hugo and running hugo-encrypt all the private posts in your public directory are encrypted and the site can be published.

Configuration

Setting a global password

1[params.HugoEncrypt]
2    Password = "yourpassword"

Password storage

hugo-encrypt uses localStorage by default. This means the passphrase is permanently stored in the browser. By adding the hugoEncrypt.Storage param in your blog’s config file you can set the storage method to sessionStorage.

1[params.HugoEncrypt]
2    Storage = "session" # or "local"

localStorage:

Once a visitor entered the correct passphrase the authorization status will not expire. The visitor can read the article until the passphrase has been changed or the browser cache is cleared.

sessionStorage:

Once a visitor entered the correct passphrase the authorization will expire after the browser is closed.

Using the {{% hugo-encrypt %}} tag in your blog posts

If no password is specified in the shortcode, the password set in your config file will be used. If no password is set at all, generation of html with hugo fails.

 1---
 2title: "This Is An Encrypted Post"
 3---
 4
 5This content is visible to anyone.
 6
 7{{% hugo-encrypt "postspecificpassword" %}}
 8
 9This content will be encrypted!
10w~/Documents/GitHub/parkman
11{{% /hugo-encrypt %}}

Language

Use i18n to display content generated by hugo-Encrypt in the language of your choice by setting the following param in your config file. Make sure to set the Param DefaultContentLanguage and add the corresponding language file to the i18n folder.

1[params]
2    DefaultContentLanguage = "en-us"

Attention

Remember to keep the source files of your encrypted posts private. Never push your blog directory into a public repository as the encryption happens after generating the html files with hugo.

Remember to run hugo-encrypt after generating your site with hugo to encrypt the posts you want to be passphrase-protected. You might want to use a shell script instead of hugo to take care of both steps:

1#!/bin/bash
2hugo --cleanDestinationDir
3hugo-encrypt

Hugo encrypt ugly-success


700 Words|This article has been read times