Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Incorrect Staticman v3 form URL #28

Closed
VincentTam opened this issue Jul 4, 2019 · 5 comments

Comments

Projects
None yet
2 participants
@VincentTam
Copy link
Contributor

commented Jul 4, 2019

The code for Staticman integration confuses me.

  1. Should {{ with ... }} ... {{ end }} enclose the entire HTML form?
  2. What does /data represent in Staticman's v3 URL scheme in eduardoboucas/staticman#219? Even though I didn't tested the GitHub Apps functionality, which won't interest any evangelical free software users, AFAIK such theme remains valid. The /data part probably needs to be removed.

<h2>Say something</h2>
{{ with .Site.Params.staticman }}
<form class="post-new-comment" method="POST" action="https://dev.staticman.net/v3/entry/github/{{ .username }}/{{ .repo }}/{{ .branch }}/data/comments">
{{ end }}
<input type="hidden" name="options[redirect]" value="{{ .Site.BaseURL }}{{ .RelPermalink }}">
<input type="hidden" name="options[entryId]" value="{{ .UniqueID }}">
<input required name="fields[name]" type="text" placeholder="Your name (Required)">
<input name="fields[website]" type="text" placeholder="Your website">
<input required name="fields[email]" type="email" placeholder="Your email address (Required for Gravatar)">
<textarea required name="fields[body]" placeholder="Your message. Feel free to use Markdown (Google 'Markdown Cheat Sheet')." rows="10"></textarea>
{{ if .Site.Params.staticman.recaptcha.recaptcha }}
<input type="hidden" name="options[reCaptcha][siteKey]" value="{{ .Site.Params.staticman.recaptcha.sitekey }}">
<input type="hidden" name="options[reCaptcha][secret]" value="{{ .Site.Params.staticman.recaptcha.encryptedkey }}">
<input type="hidden" id="g-recaptcha-response" name="g-recaptcha-response">
{{ end }}
<input type="submit" value="Submit">
</form>
{{ if .Site.Params.staticman.recaptcha.recaptcha }}
<script>
grecaptcha.ready(function() {
grecaptcha.execute('{{ .Site.Params.staticman.recaptcha.sitekey }}', {action: 'homepage'})
.then(function(token) {
//console.log(token);
document.getElementByID('g-recaptcha-response').value=token;
});
});
</script>
{{ end }}

@VincentTam

This comment has been minimized.

Copy link
Contributor Author

commented Jul 4, 2019

For the first question, I've found the answer: the with captures .Site.Params.staticman. This looks odd, but it's a convenient shorthand. I shouldn't mess it up with .UniqueID below. Therefore, this question can be dropped. It remains the second problem, which can be solved by my PR.

@pacollins

This comment has been minimized.

Copy link
Owner

commented Jul 4, 2019

Data is a Hugo thing. See Data Templates.

@VincentTam

This comment has been minimized.

Copy link
Contributor Author

commented Jul 4, 2019

@pacollins So you can set it inside repo config instead of the POST URL. See the linked Staticman PR.

@pacollins

This comment has been minimized.

Copy link
Owner

commented Jul 4, 2019

I'm still confused on what you mean? My understanding is Hugo expects it to be in the data folder, so why not hardcode it?

@VincentTam

This comment has been minimized.

Copy link
Contributor Author

commented Jul 5, 2019

I'm still confused on what you mean? My understanding is Hugo expects it to be in the data folder, so why not hardcode it?

To makes things clear, there're two config files:

  1. site config file: config.xxxx
    • theme-specific
    • for sending form data
  2. repo config file: staticman.yml
    • must be root-level, file name can't be changed
    • for receiving data from a Staticman API instance

To get comments into Hugo's data/, the right place is path in the repo config file, and you've correctly done that.

# (*) REQUIRED
#
# Destination path (directory) for the data files. Accepts placeholders.
path: "data/comments/{options.entryId}"

In the linked Staticman PR, it's writen that

/entry endpoint

New URL pattern added:
/v3/entry/:service/:username/:repository/:branch/:property

Here, property means every unindented and uncommented line in the repo, as the top of the official sample file suggests.

# Name of the property. You can have multiple properties with completely
# different config blocks for different sections of your site.
# For example, you can have one property to handle comment submission and
# another one to handle posts.
comments:
# (*) REQUIRED
#
# Names of the fields the form is allowed to submit. If a field that is
# not here is part of the request, an error will be thrown.
allowedFields: ["name", "email", "website", "body"]

Therefore, line 3 of layouts/post/staticman.html (see the first post in this thread) has to be fixed, and I've done that in my PR.

@pacollins pacollins closed this in #31 Jul 5, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.