Coder Social home page Coder Social logo

hugo-encrypt's Introduction

hugo-encrypt

hugo-encrypt is a golang port of Hugo Encryptor

hugo-encrypt is a tool that encrpyts content in your Hugo posts. It uses AES-256-GCM to encrypt the contents of your posts, and inserts the necessary javascript code into the encrypted posts that decrypts the content after the correct passphrase has been entered.

P.S. due to the usage of WebCrypto API, hugo-encrypt only support secure content (ie. HTTPS), so unsecure content cannot call crypto.subtle to decrypt post.

  1. Installation and Usage

  2. Configuration

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

Installation and Usage

$ export HUGO_BLOG=/path/to/hugo/blog

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

$ mkdir -p $HUGO_BLOG/layouts/shortcodes
$ cp shortcodes/hugo-encrypt.html $HUGO_BLOG/layouts/shortcodes

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

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

Option A: Use prebuilt binary

  • For local usage: Download hugo-encrypt and run it

      $ # If not in $PATH, add it first
      $ export PATH=/path/to/hugo-encrypt:$PATH
      $
      $ hugo
      $ hugo-encrypt -sitePath $HUGO_BLOG/public
    
  • For CI/CD usage (Vercel etc.): Customize install command and build command

      Install command: curl -L -o hugo-encrypt "https://github.com/Izumiko/hugo-encrypt/releases/download/v0.1.0/hugo-encrypt-linux-64" && chmod 755 hugo-encrypt
      
      Build command: hugo -D --gc && ./hugo-encrypt
    

Option B: 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)

      $ # export BINDIR=$HUGO_BLOG
      $
      $ # Then build and install
      $
      $ make
      $ make install
    
  • Step 2: Use hugo-encrypt to encrypt content

      $ # If not in $PATH, add it first
      $ export PATH=/path/to/hugo-encrypt:$PATH
      $
      $ hugo
      $ hugo-encrypt -sitePath $HUGO_BLOG/public
    

Option C: Use docker

  • Requirements: docker

      $ hugo
      $ docker run -it --rm \
          -v $HUGO_BLOG/public:/data/site \
          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

[params.HugoEncrypt]
    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.

[params.HugoEncrypt]
    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.

---
title: "This Is An Encrypted Post"
---

This content is visible to anyone.

{{% hugo-encrypt "postspecificpassword" %}}

This content will be encrypted!

{{% /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.

[params]
    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:

#!/bin/bash

hugo --cleanDestinationDir
hugo-encrypt
  • To prevent the accidental leaking of sensitive data, pay attention to whether the theme you used will output a summary or full text on the article list page or RSS page. If so, try adding a <!--more--> comment before the content to be encrypted (before {{% hugo-encrypt }}).

hugo-encrypt's People

Contributors

chaosbunker avatar dependabot[bot] avatar izumiko avatar jalvarezit avatar jszym avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

hugo-encrypt's Issues

Parse other shortcodes before encryption

When this shortcode is wrapped around other shortcode content, those shortcodes don't get parsed by hugo on build.

If this shortcode could be rewritten in such a way that nested shortcodes get parsed while still remaining hidden and being encrypted by the go script, that would make this a lot more useful.

Decryption not working.

After running password protected pages through this, the Decrypt button that is generated is not actually functioning. I see the SHA hashes being generated on the appropriate pages so I know it's processing the pages correctly, it just won't actually allow a user to decrypt.

加密后页面无法解密

作者你好。使用工具以后,能正常运行加密,但是无法进行页面的解密处理。另外 hugo-encrypt.html 上使用 i18n 异常。文本内容无法正确实现。是否在哪个环节操作错误?

运行环境

go version:1.14.12 windows/amd64
hugo version:v0.82.1-60618210+extended

运行命令:hugo --cleanDestinationDir --gc && hugo-encrypt -sitePath ./public

运行结果

$ hugo --cleanDestinationDir --gc && hugo-encrypt -sitePath ./public
Start building sites …

                   | EN
-------------------+------
  Pages            | 109
  Paginator pages  |  20
  Non-page files   |   0
  Static files     |  22
  Processed images |   0
  Aliases          |  11
  Sitemaps         |   1
  Cleaned          |   0

Total in 534 ms
Processing public\post\ff78fa4d\index.html, 0
SHA1: 8c 55 34 2a e3 1c 07 f8 9f 75 01 a3 9d 81 85 69 24 a6 a8 39

config.toml HugoEncrypt 配置

[params.HugoEncrypt]
    Password = "123"
    Storage = "local"	# or 'local'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.