# HG changeset patch # User Steve Kemp # Date 1197471319 0 # Node ID f3b73f970dd258278bd322d6f150129b00d0cc1b # Parent c7f71166bc90541e3e49048ff72d58aee6c28d2c Added comments. diff -r c7f71166bc90 -r f3b73f970dd2 bin/chronicle --- 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 ( ) + { + 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. # diff -r c7f71166bc90 -r f3b73f970dd2 themes/blocky/entry.template --- 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 @@ + +

Comments On This Entry

+
+ +
+
+
+
+
+ +
+ + diff -r c7f71166bc90 -r f3b73f970dd2 themes/copyrighteous/entry.template --- 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 @@ + +

Comments On This Entry

+
+ +
+
+
+
+
+ +
+ +
Archives
diff -r c7f71166bc90 -r f3b73f970dd2 themes/default/comment-form.inc --- /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 @@ + +

Add A Comment

+
+
+ + + + + + +
Your Name
Your Name
Your Comment
+ +
+
+
+ diff -r c7f71166bc90 -r f3b73f970dd2 themes/default/comment-loop.inc --- /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 @@ + +

Comments On This Entry

+
+ +
+
+
+
+
+ +
+ diff -r c7f71166bc90 -r f3b73f970dd2 themes/default/entry.template --- 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 @@
+ + +