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

Staticman form displayed when Staticman is disabled #21

Closed
VincentTam opened this issue Aug 6, 2019 · 0 comments

Comments

@VincentTam
Copy link
Collaborator

commented Aug 6, 2019

The partial template layouts/comments.html is loaded unconditionally.

<div class = 'post'>
<article class='post_content'>
{{ .Content }}
<div class = 'post_extra'>
<div class = 'copy'></div>
</div>
{{ partial "author.html" . }}
</article>
{{ partial "comments.html" . }}
<aside>
<h3>Recent Posts</h3>
<ul class='flex post_aside'>
{{ $title := .Params.title }}
{{ range first 2 .Site.RegularPages }}
{{ if not (eq .Title $title) }}
{{ partial "excerpt.html" . }}
{{ end }}
{{ end }}
</ul>
</aside>
</div>

This entire partial template file has no conditional statement to stop loading the comments section in case of absence of the Staticman section in config.toml.
<h3>Comments</h3>
<div class = 'comments'>
{{ $.Scratch.Add "hasComments" 0 }}
{{ $entryId := md5 .File.Path }}
{{ if .Site.Data.comments }}
{{ range $index, $comments := (index $.Site.Data.comments $entryId ) }}
{{ $.Scratch.Add "hasComments" 1 }}
<div class = 'comment'>
<img src = 'https://www.gravatar.com/avatar/{{ .email }}?s=100' alt = 'user icon' class = 'comment_pic'>
<div class = 'comment_meta'>
<div class = 'comment_heading pale' data-time = '{{ .date }}'></div>
<div class = 'comment_author comment_name'>{{ .name }}</div>
</div>
<p class = 'solo comment_bio pale'>{{ .comment | markdownify }}</p>
</div>
{{ end }}
{{ end }}
{{ if eq ($.Scratch.Get "hasComments") 0 }}
<p>Nothing yet.</p>
{{ end }}
{{ partial "comments-form.html" . }}
<article class = 'modal'>
<div class = 'modal_inner'>
<h2 class = 'modal_title'></h2>
<div class = 'modal_text'></div>
<button class = 'modal_close'>Close</button>
</div>
</article>
</div>

{{ $vs := .Site.Params.staticman }}
<span class = 'form_toggle btn'>Comment</span>
<form method = 'POST' action = '{{ $vs.endpoint | default "https://api.staticman.net" }}/v3/entry/{{ $vs.gitProvider }}/{{ $vs.username }}/{{ $vs.repository }}/{{ $vs.branch }}/comments' class = 'form form-comments' id = 'comments-form'>
<input name = 'options[slug]' type = 'hidden' value = '{{ md5 .File.Path }}'>
{{- if $vs.reCaptcha -}}
<input name = 'options[reCaptcha][siteKey]' type = 'hidden' value = '{{ $vs.reCaptcha.siteKey }}'>
<input name = 'options[reCaptcha][secret]' type = 'hidden' value = '{{ $vs.reCaptcha.secret }}'>
{{- end -}}
<label class = 'form_label'>Name</label>
<input name = 'fields[name]' type = 'text' placeholder = 'Name' class = 'form_input' required>
<label class = 'form_label'>E-mail</label>
<input name = 'fields[email]' type = 'email' placeholder = 'Email' class = 'form_input' required>
<label class = 'form_label'>Comment</label>
<textarea name = 'fields[comment]' placeholder = 'Type in a comment ...' class = 'form_input form_input-message' required></textarea>
{{- if $vs.reCaptcha -}}
<div class = 'g-recaptcha' data-sitekey = '{{ $vs.reCaptcha.siteKey }}' data-callback='enableSubmitComment'></div>
<script type="text/javascript">
function enableSubmitComment(){
document.getElementById('submitComment').disabled = false;
}
</script>
<script async src = 'https://www.google.com/recaptcha/api.js'></script>
{{- end -}}
<div>
<input type = 'submit' id = 'submitComment' value = 'Comment' class = 'btn form_input-submit' {{- if $vs.reCaptcha }} disabled {{- end }}>
</div>
</form>

It's better to hide comments section in case that Staticman is disabled.

@VincentTam VincentTam referenced this issue Aug 6, 2019

Merged

Improved internal links construction #22

2 of 4 tasks complete

@VincentTam VincentTam self-assigned this Aug 6, 2019

@VincentTam VincentTam added the bug label Aug 6, 2019

@onweru onweru closed this in #22 Aug 6, 2019

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