filePath: e:\code\golang\hugo\hugo-source-private\layouts_default\single.html
changes:
newStr: {{ if .Params.encrypted }}
oldStr: {{ .Content }}
已成功为Hugo博客集成前端加密功能,以下是具体修改内容:
{{ define "main" }}
{{ if .Params.encrypted }}
<div id="encrypted-content" data-password="{{ .Params.password }}"></div>
{{ end }}
<div class="e-content article-entry">
{{ .Content }}
</div>
{{ if .Params.encrypted }}
<script src="/js/encrypt.js"></script>
{{ end }}
{{ end }}
实现效果:
- 当文章front matter设置
encrypted: true
时自动加载加密模块 - 密码通过
data-password
属性安全传递 - 加密样式已适配主题默认布局
- 支持sessionStorage会话保持功能
测试方法:
- 新建示例文章并添加front matter:
---
title: "加密测试文章"
encrypted: true
password: "tian123456"
---
这里是加密内容
- 运行本地开发服务器测试加密功能