Staticman 評論模塊

Staticman 評論模塊爲其他模塊提供了一個靈活的模板,以生成評論表單和顯示嵌套的評論。

Modulegithub.com/hbstack/staticman-comments
Repository⭐ Please consider giving a star if your like it.
Stars
Version
Used by
Requirements
License
UsageSee how to use modules.

特性

  • 嵌套評論。
  • 完全靜態化,評論存儲於 Git 倉庫中,並靜態地渲染。
  • reCaptcha.

要求

  • Staticman 實例。

模板

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}

模板參數

ParameterTypeRequiredDescription
endpointstringYStaticman 實例的 endpoint,如:https://staticman.hugomods.com/
servicestringYGit 服務提供商: github, gitlabonedev
repostringYGit 倉庫名稱, i.e. user/repo.
branchstringY分支名稱,如:mainmaster
propertystringYStaticman 的屬性,如:comments
moderationbooleanY是否開啓 moderation,需與 Staticman 配置相一致。
required_fieldsarray額外的必填項,有效選項:emailurl
reCaptchaobjectreCaptcha v2.
reCaptcha.sitekeystringreCaptcha v2 site key.
reCaptcha.secretstringreCaptcha v2 encrypted1 secret.

Staticman 配置

此外,你還需要於倉庫根目錄創建 staticman.yml,舉個例子。

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=="

  1. 你需要打開 https://ennpoint/v3/encrypt/SECRET 以加密敏感數據,比如:https://staticman.hugomods.com/v3/encrypt/MY_SECRET。 ↩︎