Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
MunifTanjim committed Jul 5, 2019
1 parent b72b3bd commit 57277aa
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 26 deletions.
3 changes: 0 additions & 3 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ maxDepth = 2
username = "MunifTanjim"
repository = "minimo"
branch = "master"
enableReCaptcha = false
reCaptchaSiteKey = ""
reCaptchaSecret = ""

# Utterances: https://utteranc.es
[params.comments.utterances]
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/content/docs/comments-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Next, you'll need a Staticman Configuration File (`staticman.yml`) in the root o

**`staticman.yml`**

{{< file "content/docs/res/staticman.yml" >}}
{{< file "staticman.yml" >}}

##### Notes

Expand Down
17 changes: 0 additions & 17 deletions exampleSite/content/docs/res/staticman.yml

This file was deleted.

17 changes: 17 additions & 0 deletions exampleSite/staticman.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
comments:
allowedFields: ['author', 'content', 'email', 'parent_id', 'permalink', 'site']
branch: 'master'
commitMessage: "add [comment]: by {fields.author} <Staticman>\n\n{fields.permalink}#comment-{@id}"
filename: '{@id}'
format: 'yaml'
generatedFields:
date:
type: date
options:
format: 'timestamp'
moderation: false
name: 'Minimo'
path: 'data/comments/{options.postId}'
requiredFields: ['author', 'content', 'email', 'permalink']
transforms:
email: md5
19 changes: 14 additions & 5 deletions layouts/partials/comments/staticman/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

{{- $api := ( print $apiEndpoint "/" $username "/" $repo "/" $branch ) -}}

{{- $staticman := ( ( readFile "staticman.yml" ) | transform.Unmarshal ) -}}
{{- $reCaptcha := $staticman.comments.reCaptcha | default ( dict "enabled" false ) -}}

<div id='respond' class='comment-respond'>
<h4 class='comment-reply-title'>
{{- i18n "leaveAComment" -}}
Expand All @@ -26,6 +29,11 @@ <h4 class='comment-reply-title'>
<input type='hidden' name='fields[permalink]' value='{{ .RelPermalink }}'>
<input type='hidden' name='fields[parent_id]' value=''>

{{- if $reCaptcha.enabled -}}
<input type='hidden' name='options[reCaptcha][siteKey]' value='{{ $reCaptcha.siteKey }}'>
<input type='hidden' name='options[reCaptcha][secret]' value='{{ $reCaptcha.secret }}'>
{{- end -}}

<div>
<label for='comment'>{{ i18n "comment" }}*</label>
<textarea id='comment' name='fields[content]' required rows='3'></textarea>
Expand All @@ -42,11 +50,9 @@ <h4 class='comment-reply-title'>
<label for='url'>{{ i18n "website" }}</label>
<input id='url' name='fields[site]' type='url'>
</div>
{{- if $config.enableReCaptcha -}}
<input type='hidden' name='options[reCaptcha][siteKey]' value='{{ $config.reCaptchaSiteKey }}'>
<input type='hidden' name='options[reCaptcha][secret]' value='{{ $config.reCaptchaSecret }}'>

<div class='g-recaptcha' data-sitekey='{{ $config.reCaptchaSiteKey }}' data-callback="enableSubmitComment"></div>
{{- if $reCaptcha.enabled -}}
<div class='g-recaptcha' data-sitekey='{{ $reCaptcha.siteKey }}' data-callback="enableSubmitComment"></div>

<script type="text/javascript">
function enableSubmitComment(){
Expand All @@ -56,8 +62,11 @@ <h4 class='comment-reply-title'>

<script async src='https://www.google.com/recaptcha/api.js'></script>
{{- end -}}

<div>
<button type='submit' id="submitComment" {{- if $config.enableReCaptcha -}} disabled {{- end -}} >{{ i18n "submitComment" }}</button>
<button type='submit' id="submitComment" {{- with $reCaptcha.enabled }} disabled {{- end }}>
{{- i18n "submitComment" -}}
</button>
</div>
</form>
</div>

0 comments on commit 57277aa

Please sign in to comment.