Staticman Comments Module

Donate

Become a backer or sponsor to support our work.

Sponsors

The staticman comments module ships with flexible template for other modules, to generate comment form and show the nested comments.

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.

Features

  • Nested comments.
  • Truly static, the comments are stored on your Git repo and rendered statically.
  • reCaptcha.

Requirements

  • Staticman instance.

Template

1{{ partial "hb/modules/staticman-comments/index" site.Params.my_staticman }}

And then declare the default parameters.

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}

Template Parameters

ParameterTypeRequiredDescription
endpointstringYThe endpoint of Staticman instance, i.e. https://staticman.hugomods.com/.
servicestringYGit service provider: github, gitlab or onedev.
repostringYGit repo name, i.e. user/repo.
branchstringYThe branch name, such as main and master.
propertystringYThe name of Staticman property, for example, comments.
moderationbooleanYWhether to enable moderation, should be same as Staticman settings.
required_fieldsarrayExtra required fields, available options: email and url.
reCaptchaobjectreCaptcha v2.
reCaptcha.sitekeystringreCaptcha v2 site key.
reCaptcha.secretstringreCaptcha v2 encrypted1 secret.

Staticman Configuration

You also need to create the staticman.yml on your repo root, for example.

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. To encrypt sensitive data like reCaptcha secret, you need to navigate to the https://ennpoint/v3/encrypt/SECRET, i.e. https://staticman.hugomods.com/v3/encrypt/MY_SECRET↩︎

razonyang
Wednesday, November 13, 2024 Sunday, May 28, 2023