diff --git a/exampleSite/content/tests/encrypt-content.md b/exampleSite/content/tests/encrypt-content.md new file mode 100644 index 00000000..f919c8a6 --- /dev/null +++ b/exampleSite/content/tests/encrypt-content.md @@ -0,0 +1,49 @@ +--- +title: "Encrypt Test" +date: 2022-05-21T22:31:22+08:00 +description: "Test for encrypting content" +type: 'posts' +draft: true +password: 1212 +message: password is 1212 + +tags: +- Test +- Encrypt +categories: +- Test + +menu: + main: + title: "Test for encrypting content" + parent: "tests" + pre: "" +--- + +I was shy, so I hid. + + + +## Shortcodes in encrypted Content + +{{< version 0.2.8 >}} + +`script` is a shortcode to insert custom **:(fa-brands fa-js fa-fw): Javascript** in your post. + +{{< admonition >}} +The script content can be guaranteed to be executed in order after all third-party libraries are loaded. So you are free to use third-party libraries. +{{< /admonition >}} + +Example `script` input: + +```go-html-template +{{}} +console.log('Hello FixIt!'); +{{}} +``` + +You can see the output in the console of the developer tool. + +{{< script >}} +console.log('Hello FixIt!'); +{{< /script >}} \ No newline at end of file diff --git a/layouts/partials/single/decrypt-form.html b/layouts/partials/single/decrypt-form.html new file mode 100644 index 00000000..674b9dc4 --- /dev/null +++ b/layouts/partials/single/decrypt-form.html @@ -0,0 +1,32 @@ +
+ +
+ + + \ No newline at end of file diff --git a/layouts/posts/single.html b/layouts/posts/single.html index 770d321b..2b041565 100644 --- a/layouts/posts/single.html +++ b/layouts/posts/single.html @@ -129,10 +129,30 @@ {{- end -}} {{- /* Content */ -}} -
- {{- /* Expiration Reminder */ -}} - {{- partial "single/expiration-reminder.html" . -}} - {{- dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}} + {{- $content := dict "Content" .Content "Ruby" $params.ruby "Fraction" $params.fraction "Fontawesome" $params.fontawesome | partial "function/content.html" | safeHTML -}} + {{- if $params.password -}} + {{- $saltLen := strings.RuneCount (trim $params.password "") -}} + {{- $saltLen = cond (eq (mod $saltLen 2) 0) (add $saltLen 1) $saltLen -}} + {{- $base64EncodeContent := $content | base64Encode -}} + {{- $content = printf "%v%v%v" + (substr $base64EncodeContent 0 $saltLen) + (substr (sha256 $params.password) $saltLen) + (substr $base64EncodeContent $saltLen) + -}} + {{- end -}} +
+ {{- if not $params.password -}} + {{- /* Expiration Reminder */ -}} + {{- partial "single/expiration-reminder.html" . -}} + {{- $content -}} + {{- else -}} + {{- partial "single/decrypt-form.html" $params -}} + {{- end -}}
{{- /* Footer */ -}}