comments.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. {% macro comments_styles() %}
  2. {% if PELICAN_COMMENT_SYSTEM %}
  3. {# NOTE:
  4. # Instead of using this macro copy these styles in your main css file
  5. # This marco is only here to allow a quickstart with nice styles
  6. #}
  7. <style>
  8. #pcs-comment-form input,
  9. #pcs-comment-form textarea {
  10. width: 100%;
  11. }
  12. #pcs-comment-form-display-replyto {
  13. border: solid 1px black;
  14. padding: 2px;
  15. }
  16. #pcs-comment-form-display-replyto p {
  17. margin-top: 0.5em;
  18. margin-bottom: 0.5em;
  19. }
  20. #pcs-comments ul {
  21. list-style: none;
  22. }
  23. #pcs-comments .comment-left {
  24. display: table-cell;
  25. padding-right: 10px;
  26. }
  27. #pcs-comments .comment-body {
  28. display: table-cell;
  29. vertical-align: top;
  30. width: 100%;
  31. }
  32. </style>
  33. {% endif %}
  34. {% endmacro %}
  35. {% macro comments_form() %}
  36. {% if PELICAN_COMMENT_SYSTEM %}
  37. <section>
  38. <form id="pcs-comment-form" action="#">
  39. <legend>Add a Comment</legend>
  40. <input type="hidden" id="pcs-comment-form-input-replyto">
  41. <fieldset>
  42. <label for="pcs-comment-form-input-name">Name</label>
  43. <input id="pcs-comment-form-input-name" type="text" placeholder="Enter your name or nickname" />
  44. </fieldset>
  45. <fieldset>
  46. <label for="pcs-comment-form-input-website">Website</label>
  47. <input id="pcs-comment-form-input-website" type="text" placeholder="Enter your website (optional)" />
  48. </fieldset>
  49. <fieldset>
  50. <label for="pcs-comment-form-input-textarea">Your Comment</label>
  51. <textarea id="pcs-comment-form-input-textarea" rows="5" style="resize:vertical;" placeholder="Your comment"></textarea>
  52. <p>You can use the <a href="https://en.wikipedia.org/wiki/Markdown">Markdown</a> syntax to format your comment.</p>
  53. <div style="display: none; " id="pcs-comment-form-display-replyto"></div>
  54. </fieldset>
  55. <button type="submit"
  56. id="pcs-comment-form-button-submit"
  57. {# Piwik Track click on comment button
  58. onclick="javascript:_paq.push(['trackEvent', 'comment', '{{ article.title }}', document.getElementById('pcs-comment-form-input-textarea').value]);" #}
  59. >Post via email</button>
  60. {% if PELICAN_COMMENT_SYSTEM_FEED and article %}
  61. <a href="{{ SITEURL }}/{{ PELICAN_COMMENT_SYSTEM_FEED|format(article.slug) }}">
  62. Comment Atom Feed
  63. </a>
  64. {% endif %}
  65. </form>
  66. </section>
  67. {% endif %}
  68. {% endmacro %}
  69. {% macro comments_with_form() %}
  70. {% if PELICAN_COMMENT_SYSTEM %}
  71. <section id="pcs-comments">
  72. <header>
  73. <h2>Comments</h2>
  74. <hr/>
  75. </header>
  76. {% if article.comments %}
  77. <ul>
  78. {% for comment in article.comments recursive %}
  79. <li id="comment-{{comment.slug}}">
  80. <div class="comment-left">
  81. <img src="{{ SITEURL }}/{{ comment.avatar }}"
  82. alt="Avatar"
  83. height="{{ PELICAN_COMMENT_SYSTEM_IDENTICON_SIZE }}"
  84. width="{{ PELICAN_COMMENT_SYSTEM_IDENTICON_SIZE }}">
  85. </div>
  86. <div class="comment-body">
  87. <div style="float:right;">
  88. <a role="button" href="{{ SITEURL }}/{{ article.url }}#comment-{{comment.slug}}" rel="bookmark" title="Permalink to this comment">Permalink</a>
  89. <button onclick="CommentSystem.setReply('{{comment.slug | urlencode}}', '{{comment.author | urlencode}}');">Reply</button>
  90. </div>
  91. <h4>
  92. {% if comment.metadata['website'] %}
  93. <a href="{{comment.metadata['website']}}">{{ comment.author }}</a>
  94. {% else %}
  95. {{ comment.author }}
  96. {% endif %}
  97. </h4>
  98. <p>
  99. Posted on
  100. <time datetime="{{ comment.date.isoformat() }}" title="{{ comment.date.isoformat() }}">{{ comment.locale_date }}</time>
  101. </p>
  102. <div class="pcs-comment-content" {# class used as id in comments.js#}>
  103. {{ comment.content }}
  104. </div>
  105. {% if comment.replies %}
  106. <hr>
  107. <ul>
  108. {{ loop(comment.replies) }}
  109. </ul>
  110. {% endif %}
  111. </div>
  112. </li>
  113. {% endfor %}
  114. </ul>
  115. {% else %}
  116. <p>There are no comments yet.</p>
  117. {% endif %}
  118. {{ comments_form() }}
  119. </section>
  120. {% endif %}
  121. {% endmacro %}
  122. {% macro comments_js(user, domain, includeJquery=True) %}
  123. {% if PELICAN_COMMENT_SYSTEM %}
  124. {% if includeJquery %}
  125. <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
  126. {% endif %}
  127. <script type="text/javascript" src="{{ SITEURL }}/{{ THEME_STATIC_DIR }}/js/comments.js"></script>
  128. <script type="text/javascript">
  129. $(document).ready(function() {
  130. CommentSystem.email_user = "{{ user }}";
  131. CommentSystem.email_domain = "{{ domain }}";
  132. CommentSystem.display_replyto_html = function(comment_content, article_slug, author) {
  133. return ''
  134. + '<button style="float:right;" onclick="CommentSystem.cancelReply(); return false;" title="Cancel the reply">'
  135. + '×'
  136. + '</button>'
  137. + '<p>This comment will be posted as a reply to \'<a title="'+comment_content+'" href="#comment-'+article_slug+'">'+author+'</a>\'</p>';
  138. };
  139. $('#pcs-comment-form').on("submit",
  140. function( event )
  141. {
  142. event.preventDefault();
  143. $(location).attr('href', CommentSystem.getMailtoLink("{{ article.slug }}"));
  144. }
  145. );
  146. });
  147. </script>
  148. {% endif %}
  149. {% endmacro %}
  150. {% macro comments_quickstart(user, domain) %}
  151. {{ comments_styles() }}
  152. {{ comments_with_form() }}
  153. {{ comments_js(user, domain) }}
  154. {% endmacro %}