-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
template and plugin for testing out static comments #83
Should add mechansim to extract comments from disqus exported xml and move into yaml database
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
{% case page.comment_count %} | ||
{% when 0 %} | ||
{% when 1 %} | ||
<h3>1 Comment</h3> | ||
{% else %} | ||
<h3>{{page.comment_count}} Comments</h3> | ||
{% endcase %} | ||
{% for c in page.comments %} | ||
<div class="comment {% cycle 'odd', 'even' %}"> | ||
<p class="comment_header"> | ||
From: {% if c.link and c.link != '' %} | ||
<a href="{{c.link}}">{{c.name}}</a> | ||
{% else %} | ||
{{c.name}} | ||
{% endif %} | ||
<br /> | ||
<span class="comment_date">{{c.date}}</span> | ||
</p> | ||
<p> | ||
{{c.comment | newline_to_br}} | ||
</p> | ||
</div> | ||
{% endfor %} | ||
|
||
<i class=icon-comments"></i> <a href="mailto:address?subject=Comment&body=%0D+From+post+{{ site.url | cgi_escape }}{{ page.url | cgi_escape }}", class="showtooltip", title="Comments are submitted by email and will appear when they are approved. Markdown & mathjax syntax welcome.">Leave a comment</a> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Store and render comments as a static part of a Jekyll site | ||
# | ||
# See README.mdwn for detailed documentation on this plugin. | ||
# | ||
# Homepage: http://theshed.hezmatt.org/jekyll-static-comments | ||
# | ||
# Copyright (C) 2011 Matt Palmer <[email protected]> | ||
# | ||
# This program is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU General Public License version 3, as | ||
# published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, but | ||
# WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, see <http://www.gnu.org/licences/> | ||
|
||
class Jekyll::Post | ||
alias :to_liquid_without_comments :to_liquid | ||
|
||
def to_liquid | ||
data = to_liquid_without_comments | ||
data['comments'] = StaticComments::find_for_post(self) | ||
data['comment_count'] = data['comments'].length | ||
data | ||
end | ||
end | ||
|
||
module StaticComments | ||
# Find all the comments for a post | ||
def self.find_for_post(post) | ||
@comments ||= read_comments(post.site.source) | ||
@comments[post.id] | ||
end | ||
|
||
# Read all the comments files in the site, and return them as a hash of | ||
# arrays containing the comments, where the key to the array is the value | ||
# of the 'post_id' field in the YAML data in the comments files. | ||
def self.read_comments(source) | ||
comments = Hash.new() { |h, k| h[k] = Array.new } | ||
|
||
Dir["#{source}/**/_comments/**/*"].sort.each do |comment| | ||
next unless File.file?(comment) and File.readable?(comment) | ||
yaml_data = YAML::load_file(comment) | ||
post_id = yaml_data.delete('post_id') | ||
comments[post_id] << yaml_data | ||
end | ||
|
||
comments | ||
end | ||
end |