Count the comments!
2012/07/05 filed under /nanobloggerI'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!



Comments
Brian wrote at 2005-01-05 04:22:
kevin wrote at 2005-01-05 04:24:
Billy wrote at 2005-03-07 03:26: