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

Add staticman support #31

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
4 changes: 4 additions & 0 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
{{ partial "theme-colors.css" . | safeCSS }}
</style>

{{ range .Site.Params.custom_css -}}
<link rel="stylesheet" href="{{ . | absURL }}">
{{- end }}

{{ template "_internal/google_analytics_async.html" . }}

<title>
Expand Down
12 changes: 11 additions & 1 deletion layouts/partials/postfooter.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,15 @@
</footer>

{{ if eq .Type "post" }}
{{ template "_internal/disqus.html" . }}

{{ if ne (default "undefined" .Site.Params.staticman) "undefined" }}
<hr>
<h2 id="Comments">
Comments
</h2>
{{ partial "staticman/create-comment" . }}
{{ partial "staticman/view-comments" . }}
{{ else }}
{{ template "_internal/disqus.html" . }}
{{ end }}
{{ end }}
17 changes: 17 additions & 0 deletions layouts/partials/staticman/create-comment.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<form class="comment" method="POST" action="https://{{ .Site.Params.staticman.domain }}/v{{ .Site.Params.staticman.api_version }}/entry/{{ .Site.Params.staticman.username }}/{{ .Site.Params.staticman.repository }}/{{ .Site.Params.staticman.branch }}/comments" class="flex-container flex-column">
<input type="hidden" name="options[redirect]" value="{{ .Permalink }}#comment-submitted">
<input type="hidden" name="options[slug]" value="{{ .Page.File.ContentBaseName }}">
<div class="flex-container flex-row">
<input name="fields[name]" type="text" placeholder="Your name" class="flex-item">
<input name="fields[email]" type="email" placeholder="Your email address" class="flex-item">
</div>
<div class="flex-container flex-row">
<textarea name="fields[message]" placeholder="Your message. Feel free to use Markdown." rows="10" class="flex-item"></textarea>
</div>
<div class="flex-container flex-row">
<input type="submit" value="Submit" class="flex-item">
</div>
</form>
<div id="comment-submitted">
Your comment has been submitted and is now pending moderation
</div>
24 changes: 24 additions & 0 deletions layouts/partials/staticman/view-comments.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{ $comments := readDir "data/comments" }}
{{ $.Scratch.Add "hasComments" 0 }}
{{ $entryId := .Page.File.ContentBaseName }}

{{ range $comments }}
{{ if eq .Name $entryId }}
{{ $.Scratch.Add "hasComments" 1 }}
{{ range $index, $comments := sort (index $.Site.Data.comments $entryId ) "date" "desc" }}
<blockquote class="comment">
<p>{{ .message | markdownify }}</p>
<cite class="flex-container flex-row flex-end">
<img class="flex-item avatar" src="https://www.gravatar.com/avatar/{{ .email }}?s=50&d=retro">
<div class="flex-container flex-column flex-item flex-center">
<strong>{{ .name }}</strong><br>{{ dateFormat "02/01/2006" .date }}
</div>
</cite>
</blockquote>
{{ end }}
{{ end }}
{{ end }}

{{ if eq ($.Scratch.Get "hasComments") 0 }}
<p>Be the first to comment on this article.</p>
{{ end }}
Loading