RSS

Count the comments!

2012/07/05 filed under /nanoblogger

I'm very new to NanoBlogger, yet impressed by it's power and coolness.

After installing CGIComment I realized there's no counter of comments per post. There's of course comment_cnt.sh by dams, but I didn't really fancy the idea of using wget for this task. The .db files didn't look that hard to parse, so here's the overkill-oneliner-that-should-have-been-shorter.

First you will have to edit the blog.conf and add CGICOMMENT_DIR="" with the path to your CGIComment directory:

# CGIComment directory
CGICOMMENT_DIR="$BLOG_DIR/cgicomment"

After that, create the file comment_count.sh in your $BASE_URL/plugins/entry/ directory:

# NanoBlogger plugin to get number of (cgicomment) comments without wget
# by B10m, 2005 (http://menno.b10m.net/)

NB_EntryCommentCount=$(grep -c "^$(sed -ne \
  "s/^\([0-9]*\)|archives\/$permalink_entry$/\\1/p" \
  $CGICOMMENT_DIR/comments/articles.db 2>/dev/null)|" \
  $CGICOMMENT_DIR/comments/comments.db 2>/dev/null) 

if [[ -z $NB_EntryCommentCount ]]; then NB_EntryCommentCount=0; fi

(UPDATE: Removed the `echo` calls to prevent unwanted output in archives/index.html)

To be compatible with comment_cnt.sh, I used the same variable $NB_EntryCommentCount,so (if not already done) alter your templates (entry.html, permalink_entry.html) accordingly:

<a href="$BLOG_URL_ACTION$ARCHIVES_DIR/$permalink_entry#comments">Comments</a>
 ($NB_EntryCommentCount)

Final note: as with comment_cnt.sh, the counter will only be updated each time you rebuild your blog!

Posted by: B10m | permanent link | comments (3)

Comments

Brian wrote at 2005-01-05 04:22:

This is nice but another alternative is Reblogger at http://jsoft.ca/reblogger/ which I also use with nanoblogger. I refer the look of cgicomment but the dynamic comment counting of rebloger, plus it's ability to send an e-mail notification when you get a comment are really nice.

kevin wrote at 2005-01-05 04:24:

I totally agree with you, that wget shouldn't be used for each entry. However, your method only works well if the comments are stored locally. Fortunately, it wouldn't be hard to modify your plugin to optionally use wget to fetch cgicomments/*.db.

Thanks for your contribution! I have a plugin tracker on nanoblogger's project page at sourceforge.net, if you'd like to upload your plugin there.

Billy wrote at 2005-03-07 03:26:

nice!

Comments are closed for this story.
Trackbacks are closed for this story.
return-member