changeset 85:f3b73f970dd2

Added comments.
author Steve Kemp <steve@steve.org.uk>
date Wed, 12 Dec 2007 14:55:19 +0000
parents c7f71166bc90
children ad6136b094b8
files bin/chronicle themes/blocky/entry.template themes/copyrighteous/entry.template themes/default/comment-form.inc themes/default/comment-loop.inc themes/default/entry.template themes/default/index.template themes/default/month.template themes/default/tags.template
diffstat 9 files changed, 222 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/bin/chronicle	Tue Dec 11 23:07:00 2007 +0000
+++ b/bin/chronicle	Wed Dec 12 14:55:19 2007 +0000
@@ -11,6 +11,7 @@
 
   Path Options:
 
+   --comments       Specify the path to the optional comments directory.
    --config         Specify a configuration file to read.
    --input          Specify the input directory to use.
    --output         Specify the directory to write output to.
@@ -66,7 +67,7 @@
 
   The obvious deficiencies are:
 
-   * Lack of support for commenting.
+   * Lack of support for instant commenting.
 
    * Lack of pingback/trackback support.
 
@@ -178,6 +179,33 @@
 =cut
 
 
+=head1 OPTIONAL COMMENTING
+
+  Included with the chronicle code you should find the file
+ cgi-bin/comments.cgi.
+
+  This file is designed to write submitted comments to the local
+ filesystem of your webserver.  If you install that, and edit the
+ path at the start of teh script you should be able to include
+ comments in your blog.
+
+  In short there are three things you need to do:
+
+=over 8
+
+=item  Install the CGI script and edit the path at the start.
+
+=item  Copy the output comments to your local blog source.
+
+=item  Run this script again with --comments=./path/to/comments
+
+=back
+
+  This should include the comments in the static output.
+
+=cut
+
+
 =head1 AUTHOR
 
  Steve
@@ -418,6 +446,7 @@
     #  Text directory.
     #
     $CONFIG{'input'}      = "./blog";
+    $CONFIG{'comments'}   = '';
 
     #
     #  Output directory.
@@ -482,6 +511,7 @@
                "list-themes",  \$CONFIG{'list-themes'},
 
                # paths
+               "comments=s",   \$CONFIG{'comments'},
                "config=s",     \$CONFIG{'config'},
                "input=s",      \$CONFIG{'input'},
                "output=s",     \$CONFIG{'output'},
@@ -1248,6 +1278,28 @@
     #
     my $file = fileToTitle($title);
 
+
+    #
+    #  Get comments, if present.
+    #
+    if( !$CONFIG{'no-comments'} )
+    {
+        my $comments = getComments( $CONFIG{'comments'}, $file );
+
+        if ( defined($comments) )
+        {
+            my $count = scalar( @$comments );
+
+            $template->param( comments      => $comments,
+                              comment_count => $count );
+
+            $CONFIG{'verbose'} && print "$file [$filename] has $count comments\n";
+        }
+
+        $template->param( comments_enabled => 1 );
+    }
+
+
     #
     #  The entry.
     #
@@ -1468,6 +1520,7 @@
     $entry{'date'}  = $date;
     $entry{'tags'}  = $entryTags if ( $entryTags );
 
+
     #
     #  No title?
     #
@@ -1493,6 +1546,11 @@
     my $link = fileToTitle( $entry{'title'} );
     $entry{'link'}  = $link;
 
+    #
+    #  Count comments.
+    #
+    $entry{'comment_count' } = countComments( $CONFIG{'comments'}, $entry{'link'} );
+
 
     #
     #  Store the read file in the cache if we're using it.
@@ -1547,6 +1605,98 @@
 
 =begin doc
 
+  Look for comments.
+
+=end doc
+
+=cut
+
+sub getComments
+{
+    my( $dir, $title ) = (@_);
+
+    my $results;
+
+    if ( $title  =~ /^(.*)\.([^.]+)$/ )
+    {
+        $title = $1;
+    }
+
+    foreach my $file ( sort( glob( $dir . "/" . $title . "*" ) ) )
+    {
+        my $date = "";
+        my $name = "";
+        my $body = "";
+        my $mail = "";
+
+        if ( $file =~ /^(.*)\.([^.]+)$/ )
+        {
+            $date = $2;
+        }
+        open( COMMENT, "<", $file )
+          or next;
+
+        foreach my $line ( <COMMENT> )
+        {
+            next if ( !defined( $line ) );
+
+            chomp( $line );
+            if ( !length( $name ) && $line =~ /^Name: (.*)/i )
+            {
+                $name = $1;
+            }
+            elsif ( !length( $mail ) && $line =~ /^Mail: (.*)/i )
+            {
+                $mail = $1;
+            }
+            else
+            {
+                $body .= $line . "\n";
+            }
+        }
+        close( COMMENT );
+
+        if ( length($name) &&
+             length($mail) &&
+             length($body) )
+        {
+            push( @$results,
+                { name => $name,
+                  mail => $mail,
+                  body => $body,
+                  date => $date } );
+
+        }
+    }
+    return( $results );
+}
+
+
+
+sub countComments
+{
+    my( $dir, $title ) = (@_);
+
+    return( 0 ) if ( $CONFIG{'no-comments'} );
+
+    if ( $title  =~ /^(.*)\.([^.]+)$/ )
+    {
+        $title = $1;
+    }
+
+    my $count = 0;
+    foreach my $f ( sort glob( $dir . "/" . $title . "*" ) )
+    {
+        $count += 1;
+    }
+
+    return( $count );
+}
+
+
+
+=begin doc
+
   Load a template file.
 
 =end doc
@@ -1574,7 +1724,6 @@
         $dir .= "/" . $CONFIG{'theme'} . "/";
     }
 
-
     #
     #  Make sure the file exists.
     #
--- a/themes/blocky/entry.template	Tue Dec 11 23:07:00 2007 +0000
+++ b/themes/blocky/entry.template	Wed Dec 12 14:55:19 2007 +0000
@@ -35,6 +35,19 @@
   </td><td align="right"><!-- tmpl_var name='date' --></td></tr></table>
  </fieldset>
 
+<!-- tmpl_if name='comments' -->
+ <h3>Comments On This Entry</h3>
+ <blockquote>
+ <!-- tmpl_loop name='comments' -->
+  <div class="entry">
+  <div class="title"><!-- tmpl_var name='name' --></div>
+  <div class="date"><!-- tmpl_var name='date' --></div>
+  <div class="body"><!-- tmpl_var name='body' --></div>
+  </div>
+ <!-- /tmpl_loop -->
+ </blockquote>
+<!-- /tmpl_if -->
+
 </td>
 <td width="20%" valign="top">
 <!-- tmpl_if name='datecloud' -->
--- a/themes/copyrighteous/entry.template	Tue Dec 11 23:07:00 2007 +0000
+++ b/themes/copyrighteous/entry.template	Wed Dec 12 14:55:19 2007 +0000
@@ -36,6 +36,19 @@
 </div>
 </div>
 
+<!-- tmpl_if name='comments' -->
+ <h3>Comments On This Entry</h3>
+ <blockquote>
+ <!-- tmpl_loop name='comments' -->
+  <div class="entry">
+  <div class="title"><!-- tmpl_var name='name' --></div>
+  <div class="date"><!-- tmpl_var name='date' --></div>
+  <div class="body"><!-- tmpl_var name='body' --></div>
+  </div>
+ <!-- /tmpl_loop -->
+ </blockquote>
+<!-- /tmpl_if -->
+
 <div id="rightmenu">
 <!-- tmpl_if name='datecloud' -->
 <span class="rightMenu">Archives</span><br />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/themes/default/comment-form.inc	Wed Dec 12 14:55:19 2007 +0000
@@ -0,0 +1,17 @@
+<!-- tmpl_if name='comments_enabled' -->
+<h3>Add A Comment</h3>
+<blockquote>
+<form action="/cgi-bin/comments.cgi" method="post">
+<table>
+<tr><td>Your Name</td>
+    <td><input type="text" size="55" name="name"></td></tr>
+<tr><td>Your Name</td>
+    <td><input type="text" size="55" name="name"></td></tr>
+<tr><td colspan="2">Your Comment<br />
+<textarea name="body" rows="10" cols="60">
+</textarea>
+<tr><td></td><td><input type="submit"></td></tr>
+</table>
+</form>
+</blockquote>
+<!-- /tmpl_if -->
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/themes/default/comment-loop.inc	Wed Dec 12 14:55:19 2007 +0000
@@ -0,0 +1,12 @@
+<!-- tmpl_if name='comments' -->
+ <h3>Comments On This Entry</h3>
+ <blockquote>
+ <!-- tmpl_loop name='comments' -->
+  <div class="entry">
+  <div class="title"><!-- tmpl_var name='name' --></div>
+  <div class="date"><!-- tmpl_var name='date' --></div>
+  <div class="body"><!-- tmpl_var name='body' --></div>
+  </div>
+ <!-- /tmpl_loop -->
+ </blockquote>
+<!-- /tmpl_if -->
--- a/themes/default/entry.template	Tue Dec 11 23:07:00 2007 +0000
+++ b/themes/default/entry.template	Wed Dec 12 14:55:19 2007 +0000
@@ -29,6 +29,9 @@
    <!-- /tmpl_if -->
   </div>
 
+<!-- tmpl_include name="comment-loop.inc" -->
+<!-- tmpl_include name="comment-form.inc" -->
+
 <div id="sidebar">
 <!-- tmpl_if name='datecloud' -->
 <h2>Archive</h2>
--- a/themes/default/index.template	Tue Dec 11 23:07:00 2007 +0000
+++ b/themes/default/index.template	Wed Dec 12 14:55:19 2007 +0000
@@ -28,6 +28,10 @@
   <div class="date"><!-- tmpl_var name='date' --></div>
   <div class="body"><!-- tmpl_var name='body' --></div>
   <div class="tags">
+   <!-- tmpl_if name='comment_count' -->
+   <!-- tmpl_var name='comment_count' --> comments.  
+   <!-- /tmpl_if -->
+
    <!-- tmpl_if name='tags' -->
    Tags: <!-- tmpl_loop name='tags' --><a href="<!-- tmpl_var name='top' -->tags/<!-- tmpl_var name='tag' -->"><!-- tmpl_var name='tag' --></a><!-- tmpl_if name="__last__" -->.<!-- tmpl_else -->, <!-- /tmpl_if --><!-- /tmpl_loop --> 
   <!-- tmpl_else -->
--- a/themes/default/month.template	Tue Dec 11 23:07:00 2007 +0000
+++ b/themes/default/month.template	Wed Dec 12 14:55:19 2007 +0000
@@ -36,6 +36,10 @@
   <!-- tmpl_var name='body' -->
  </div>
  <div class="tags">
+ <!-- tmpl_if name='comment_count' -->
+   <!-- tmpl_var name='comment_count' --> comments.  
+ <!-- /tmpl_if -->
+
  <!-- tmpl_if name='tags' -->
   Tags: <!-- tmpl_loop name='tags' --><a href="<!-- tmpl_var name='top' -->tags/<!-- tmpl_var name='tag' -->"><!-- tmpl_var name='tag' --></a><!-- tmpl_if name="__last__" -->.<!-- tmpl_else -->, <!-- /tmpl_if --><!-- /tmpl_loop -->
  <!-- tmpl_else -->
--- a/themes/default/tags.template	Tue Dec 11 23:07:00 2007 +0000
+++ b/themes/default/tags.template	Wed Dec 12 14:55:19 2007 +0000
@@ -36,11 +36,14 @@
  <div class="body">
   <!-- tmpl_var name='body' -->
  </div>
+ <div class="tags">
+ <!-- tmpl_if name='comment_count' -->
+   <!-- tmpl_var name='comment_count' --> comments.  
+ <!-- /tmpl_if -->
  <!-- tmpl_if name='tags' -->
- <div class="tags">
   Tags: <!-- tmpl_loop name='tags' --><a href="<!-- tmpl_var name='top' -->tags/<!-- tmpl_var name='tag' -->"><!-- tmpl_var name='tag' --></a><!-- tmpl_if name="__last__" -->.<!-- tmpl_else -->, <!-- /tmpl_if --><!-- /tmpl_loop -->
+ <!-- /tmpl_if -->
  </div>
- <!-- /tmpl_if -->
 </div>
 <div class="padding"></div>
 <!-- /tmpl_loop -->