Skip to content

Commit

Permalink
Refactor (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang authored Jun 15, 2023
1 parent 46b96b9 commit 4aaaf49
Show file tree
Hide file tree
Showing 42 changed files with 4,775 additions and 423 deletions.
11 changes: 0 additions & 11 deletions .github/dependabot.yml

This file was deleted.

27 changes: 9 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,7 @@ on:
workflow_dispatch:
release:
types: [published]
push:
branches:
- master
paths:
- "**/*.go"
- "go.mod"
- "go.sum"
- ".github/workflows/*.yml"
pull_request:
types: [opened, synchronize, reopened]
paths:
- "**/*.go"
- "go.mod"
- "go.sum"
- ".github/workflows/*.yml"

jobs:
build:
permissions:
Expand Down Expand Up @@ -89,39 +75,44 @@ jobs:
echo "ASSET_NAME=$_NAME" >> $GITHUB_ENV
- name: Set up Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: 1.19
check-latest: true

- name: Get project dependencies
run: go mod download
working-directory: ./commands/encrypt

- name: Build hugo encrypt
run: |
go build -v -o hugo-encrypt -trimpath -ldflags "-s -w -buildid=" .
working-directory: ./commands/encrypt

- name: Rename Windows hugo encrypt
if: matrix.goos == 'windows'
working-directory: ./commands/encrypt
run: |
mv hugo-encrypt hugo-encrypt.exe
- name: Change the name
working-directory: ./commands/encrypt
run: |
mv hugo-encrypt hugo-encrypt-${{ env.ASSET_NAME }} || mv hugo-encrypt.exe hugo-encrypt-${{ env.ASSET_NAME }}.exe
- name: Upload files to Artifacts
uses: actions/upload-artifact@v3
working-directory: ./commands/encrypt
with:
name: hugo-encrypt-${{ env.ASSET_NAME }}
path: |
./hugo-encrypt-${{ env.ASSET_NAME }}*
- name: Upload binaries to release
uses: svenstaro/upload-release-action@v2
working-directory: ./commands/encrypt
if: github.event_name == 'release'
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./hugo-encrypt-${{ env.ASSET_NAME }}*
file: ./commands/encrypt/hugo-encrypt-${{ env.ASSET_NAME }}*
tag: ${{ github.ref }}
file_glob: true
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
hugo-encrypt
resources/
public/
.hugo_build.lock
node_modules/
14 changes: 14 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pull_request_rules:
- name: Automatic merge for Renovate pull requests
conditions:
- author=renovate[bot]
actions:
merge:
method: rebase

- name: Automatic merge on approval
conditions:
- "#approved-reviews-by>=1"
actions:
merge:
method: rebase
15 changes: 15 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"bracketSameLine": true,
"goTemplateBracketSpacing": true,
"overrides": [
{
"files": [
"*.html"
],
"options": {
"parser": "go-template",
"bracketSameLine": true
}
}
]
}
1 change: 1 addition & 0 deletions .stylelintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/*.tmpl.scss
9 changes: 9 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "stylelint-config-standard-scss",
"rules": {
"at-rule-no-unknown": null,
"color-function-notation": null,
"scss/at-rule-no-unknown": true,
"scss/at-extend-no-missing-placeholder": null
}
}
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
MIT License

Copyright (c) 2023 Hugo Modules Authors
Copyright (c) 2023 Izumiko

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
148 changes: 5 additions & 143 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,144 +1,6 @@
## hugo-encrypt

`hugo-encrypt` is a golang port of [Hugo Encryptor](https://github.com/Li4n0/hugo_encryptor)

`hugo-encrypt` is a tool that encrpyts content in your [Hugo](https://gohugo.io) 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](#installation-and-usage)

2. [Configuration](#configuration)

3. [Using the `{{% hugo-encrypt %}}` tag in your blog posts](#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](#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](https://github.com/Izumiko/hugo-encrypt/releases/latest) 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

```toml
[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_.

```toml
[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.


```markdown
---
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.

```toml
[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
# Hugo Encrypt Module

[![Used By](https://img.shields.io/badge/dynamic/json?color=success&label=used+by&query=repositories_humanize&logo=hugo&style=flat-square&url=https://api.razonyang.com/v1/github/dependents/hugomods/encrypt)](https://github.com/hugomods/encrypt/network/dependents)
![Hugo Requirements](https://img.shields.io/badge/dynamic/json?color=important&label=requirements&query=requirements&logo=hugo&style=flat-square&url=https://api.razonyang.com/v1/hugo/modules/github.com/hugomods/encrypt)
[![License](https://img.shields.io/github/license/hugomods/encrypt?style=flat-square)](https://github.com/hugomods/encrypt/blob/main/LICENSE)
[![Version](https://img.shields.io/github/v/tag/hugomods/encrypt?label=version&style=flat-square)](https://github.com/hugomods/encrypt/tags)
Loading

0 comments on commit 4aaaf49

Please sign in to comment.