changeset 144:571c8d4310f0

Removed redundent reading of entries, to speed up and simplify the code.
author Steve Kemp <steve@steve.org.uk>
date Wed, 26 Dec 2007 15:28:45 +0000
parents 55c15e6aebd6
children 68f470cd5388
files bin/chronicle
diffstat 1 files changed, 24 insertions(+), 92 deletions(-) [+]
line wrap: on
line diff
--- a/bin/chronicle	Wed Dec 26 15:16:16 2007 +0000
+++ b/bin/chronicle	Wed Dec 26 15:28:45 2007 +0000
@@ -329,7 +329,6 @@
 my %all_tags;
 %all_tags = findAllTags() unless( $CONFIG{'no-tags'} );
 
-
 #
 #  Find each unique month + year we've used.
 #
@@ -577,7 +576,6 @@
     #  Did the user override the default pattern?
     #
     my $pattern = $CONFIG{'pattern'} || "*";
-    my $count   = 0;
 
     foreach my $file ( sort( glob( $CONFIG{'input'} . "/" . $pattern ) ) )
     {
@@ -586,87 +584,17 @@
         #
         next if ( -d $file );
 
-        my $tags    = '';
-        my $title   = '';
-        my $date    = '';
-        my $private = 0;
-
-        my @tags;
-
-        open( INPUT, "<", $file ) or die "Failed to open blog file $file - $!";
-        while( my $line = <INPUT> )
-        {
-            #
-            #  Get the tags
-            #
-            if ( ( $line =~ /^tags:(.*)/i ) && !length($tags) )
-            {
-                $tags = $1;
-                foreach my $t ( split( /,/, $tags ) )
-                {
-                    # strip leading and trailing space.
-                    $t =~ s/^\s+//;
-                    $t =~ s/\s+$//;
-
-                    # skip empty tags.
-                    next if ( !length($t) );
-
-                    # lowercase and store the tags.
-                    $t = lc($t);
-                    push ( @tags, $t );
-                }
-            }
-            elsif (( $line =~ /^title:(.*)/i ) && !length($title) )
-            {
-                #
-                #  Get the title.
-                #
-                $title = $1;
-
-                # strip leading and trailing space.
-                $title =~ s/^\s+// if ( length $title );
-                $title =~ s/\s+$// if ( length $title );
-            }
-            elsif (( $line =~ /^date:(.*)/i ) && !length($date) )
-            {
-                #
-                #  Get the date.
-                #
-                $date = $1;
-
-                # strip leading and trailing space.
-                $date =~ s/^\s+// if ( $date );
-                $date =~ s/\s+$// if ( $date );
-
-            }
-            elsif ( $line =~ /^status:(.*)/i )
-            {
-                #
-                #  The security level.
-                #
-
-                my $level = $1;
-
-                # strip leading and trailing space.
-                $level =~ s/^\s+// if ( $level );
-                $level =~ s/\s+$// if ( $level );
-
-                $private = 1 if ( $level =~ /private/i);
-            }
-        }
-        close( INPUT );
-
-        $results{$file} = { tags => \@tags,
-                            title => $title,
-                            date  => $date } unless( $private );
-
-        $count += 1;
+        #
+        #  Read the entry and store all the data away as a
+        # hash element keyed upon the (unique) filename.
+        #
+        $results{$file} = readBlogEntry( $file);
     }
 
     #
     #  Make sure we found some entries.
     #
-    if ( $count < 1 )
+    if ( scalar(keys(%results))< 1 )
     {
         print <<EOF;
 
@@ -703,7 +631,10 @@
         my $tags = $h->{'tags'} || undef;
         foreach my $t ( @$tags )
         {
-            $allTags{$t}+=1;
+            if ( $t->{'tag'} )
+            {
+                $allTags{$t->{'tag'}}+=1;
+            }
         }
     }
 
@@ -999,10 +930,11 @@
         my $tags = $h->{'tags'} || undef;
         foreach my $t ( @$tags )
         {
-            $allTags{$t}+=1;
-            my $a = $tagEntries{$t};
+            my $name = $t->{'tag'};
+            $allTags{$name}+=1;
+            my $a = $tagEntries{$name};
             push @$a, $f ;
-            $tagEntries{$t}= $a;
+            $tagEntries{$name}= $a;
         }
     }
 
@@ -1359,8 +1291,6 @@
     my $tags   = "";   # entry tags.
     my $body   = "";   # entry body.
     my $date   = "";   # entry date
-    my $status = "";   # entry privacy/security.
-
 
     open( ENTRY, "<", $filename ) or die "Failed to read $filename $!";
     while( my $line = <ENTRY> )
@@ -1394,13 +1324,6 @@
             $date =~ s/^\s+// if ( length $date );
             $date =~ s/\s+$// if ( length $date );
         }
-        elsif (( $line =~ /^status:(.*)/ ) && !length ( $status ) )
-        {
-            #
-            #  Security level?
-            #
-            $status = $1;
-        }
         else
         {
             #
@@ -1598,7 +1521,8 @@
 
 =begin doc
 
-  Look for comments.
+  Look for comments, for the given entry.  Return any found in a format
+ suitable for the insertion into the output templates.
 
 =end doc
 
@@ -1680,6 +1604,14 @@
 
 
 
+=begin doc
+
+  Count the number of comments associated with a given post.
+
+=end doc
+
+=cut
+
 sub countComments
 {
     my( $dir, $title ) = (@_);