Staticman 评论模块为其他模块提供了一个灵活的模板,以生成评论表单和显示嵌套的评论。
Module | github.com/hbstack/staticman-comments |
---|---|
Repository | ⭐ Please consider giving a star if your like it. |
Stars | |
Version | |
Used by | |
Requirements | |
License | |
Usage | See how to use modules. |
1{{ partial "hb/modules/staticman-comments/index" site.Params.my_staticman }}
然后声明默认的参数。
hugo.toml
1[params]
2 [params.my_staticman]
3 branch = 'main'
4 endpoint = 'https://staticman.hugomods.com/'
5 moderation = true
6 property = 'comments'
7 repo = 'user/repo'
8 required_fields = ['email', 'url']
9 service = 'github'
hugo.yaml
1params:
2 my_staticman:
3 branch: main
4 endpoint: https://staticman.hugomods.com/
5 moderation: true
6 property: comments
7 repo: user/repo
8 required_fields:
9 - email
10 - url
11 service: github
hugo.json
1{
2 "params": {
3 "my_staticman": {
4 "branch": "main",
5 "endpoint": "https://staticman.hugomods.com/",
6 "moderation": true,
7 "property": "comments",
8 "repo": "user/repo",
9 "required_fields": [
10 "email",
11 "url"
12 ],
13 "service": "github"
14 }
15 }
16}
my_staticman
替换为你自己的,以避免与其他模块相冲突。Parameter | Type | Required | Description |
---|---|---|---|
endpoint | string | Y | Staticman 实例的 endpoint,如:https://staticman.hugomods.com/ 。 |
service | string | Y | Git 服务提供商: github , gitlab 或 onedev 。 |
repo | string | Y | Git 仓库名称, i.e. user/repo . |
branch | string | Y | 分支名称,如:main 和 master 。 |
property | string | Y | Staticman 的属性,如:comments 。 |
moderation | boolean | Y | 是否开启 moderation ,需与 Staticman 配置相一致。 |
required_fields | array | 额外的必填项,有效选项:email 和 url 。 | |
reCaptcha | object | reCaptcha v2. | |
reCaptcha.sitekey | string | reCaptcha v2 site key. | |
reCaptcha.secret | string | reCaptcha v2 encrypted1 secret. |
此外,你还需要于仓库根目录创建 staticman.yml
,举个例子。
1# Name of the property. You can have multiple properties with completely
2# different config blocks for different sections of your site.
3# For example, you can have one property to handle comment submission and
4# another one to handle posts.
5comments:
6 # (*) REQUIRED
7 #
8 # Names of the fields the form is allowed to submit. If a field that is
9 # not here is part of the request, an error will be thrown.
10 allowedFields: ["name", "email", "url", "message", "reply_to", "root_id"]
11
12 # (*) REQUIRED
13 #
14 # Name of the branch being used. Must match the one sent in the URL of the
15 # request.
16 branch: "main"
17
18 # Text to use as the commit message or pull request title. Accepts placeholders.
19 commitMessage: "chore: add Staticman comment"
20
21 # (*) REQUIRED
22 #
23 # Destination path (filename) for the data files. Accepts placeholders.
24 filename: "{@id}"
25
26 # The format of the generated data files. Accepted values are "json", "yaml"
27 # or "frontmatter"
28 format: "yaml"
29
30 # List of fields to be populated automatically by Staticman and included in
31 # the data file. Keys are the name of the field. The value can be an object
32 # with a `type` property, which configures the generated field, or any value
33 # to be used directly (e.g. a string, number or array)
34 generatedFields:
35 date:
36 type: date
37 options:
38 format: "timestamp-seconds"
39
40 # Whether entries need to be appproved before they are published to the main
41 # branch. If set to `true`, a pull request will be created for your approval.
42 # Otherwise, entries will be published to the main branch automatically.
43 moderation: true
44
45 # Name of the site. Used in notification emails.
46 # name: "hbstack.dev"
47
48 # Notification settings. When enabled, users can choose to receive notifications
49 # via email when someone adds a reply or a new comment. This requires an account
50 # with Mailgun, which you can get for free at http://mailgun.com.
51 #notifications:
52 # Enable notifications
53 #enabled: true
54
55 # (!) ENCRYPTED
56 #
57 # Mailgun API key
58 #apiKey: "1q2w3e4r"
59
60 # (!) ENCRYPTED
61 #
62 # Mailgun domain (encrypted)
63 #domain: "4r3e2w1q"
64
65 # (*) REQUIRED
66 #
67 # Destination path (directory) for the data files. Accepts placeholders.
68 path: "data/comments/{options.slug}"
69
70 # Names of required fields. If any of these isn't in the request or is empty,
71 # an error will be thrown.
72 requiredFields: ["name", "message"]
73
74 # List of transformations to apply to any of the fields supplied. Keys are
75 # the name of the field and values are possible transformation types.
76 transforms:
77 email: md5
78
79 reCaptcha:
80 enabled: true
81 siteKey: 6LcWQH0gAAAAAJPZN9S-wrugRUukNOiHfxmFOSM5
82 secret: "Tba8b3unYkkAY2zaITA3Or1Jg0vjaW+2ZOfxBCb/IdivpOMLacJabaVhHeOYnSOwhNF668U3giPW0Z1qYuj6HiFoml/TIZcuevk7A+8vCUVAbVXMJBKAVM7ONIZ3EsURtAvU4BDUTVe/Cb3qvwlAZeCO6RE+xWJh2ixvaLG8WyACvs+7ank+UP+pmS93c+haXMcsatIX4XUl/uYBPWqVVobhDcjG2Sfaar0F+eqVp5bRbZKzJaPvrnWD7aVlBJ+bi/HL7U4fR+sDWmtMEe0KbEOihDs0rh13+KAhfWK83E1mbJeB3jumlqcTui2V+IyXDe5I8eQwt8o79tKr4VbmvQ=="
allowedFields
、path
和 file
为固定值。你需要打开 https://ennpoint/v3/encrypt/SECRET
以加密敏感数据,比如:https://staticman.hugomods.com/v3/encrypt/MY_SECRET
。 ↩︎