Changeset 23757
- Timestamp:
- 11/15/08 14:25:21 (8 weeks ago)
- Location:
- lang/perl/blosxom
- Files:
-
- 11 added
- 2 modified
-
blosxom.nyarla.cgi (modified) (2 diffs)
-
plugins/chatlog (added)
-
plugins/configurable (added)
-
plugins/datemap (modified) (5 diffs)
-
plugins/datesection (added)
-
plugins/hidden (added)
-
plugins/lastmod (added)
-
plugins/lastmod_cache (added)
-
plugins/micromason (added)
-
plugins/pagination (added)
-
plugins/quote (added)
-
plugins/ttize (added)
-
plugins/variable (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/blosxom/blosxom.nyarla.cgi
r21831 r23757 132 132 133 133 $path_info_yr ||= q{}; 134 $path_info_mo ||= q{}; 134 135 $path_info_mo_num ||= q{}; 135 136 $path_info_da ||= q{}; … … 397 398 ( $hr, $min) = split m{:}, $ti; 398 399 ( $hr12, $ampm ) = ( $hr >= 12 ) ? ( $hr - 12,'pm' ) : ( $hr, 'am' ) ; 399 $hr12 =~ s{^0}{}; 400 $hr12 = 12 if ( $hr12 == 0 ); 400 $hr12 =~ s{^0}{}; 401 $hr12 ||= 0; 402 $hr12 = 12 if ( $hr12 == 0 ); 401 403 402 404 # Only stories from the right date -
lang/perl/blosxom/plugins/datemap
r7370 r23757 1 1 # Blosxom Plugin: datemap 2 2 # Author: Naoki Okamura (Nyarla) <thotep@nyarla.net> 3 # Version: 2008-0 3-024 # Lice sen: public domain3 # Version: 2008-04-15 4 # License: public domain 5 5 6 6 package datemap; … … 9 9 use warnings; 10 10 11 use FileHandle; 11 use YAML::Syck (); 12 use DateTime; 13 use DateTime::Format::W3CDTF; 12 14 13 15 # -- configurable variables ---------- # 14 16 15 my $file = "$blosxom::plugin_state_dir/datemap.dat"; 17 my $file = "$blosxom::plugin_state_dir/datemap.yaml"; 18 my $meta_prefix = 'meta-'; 19 my $meta_date = 'date'; 20 my $timezone = 'Asia/Tokyo'; 16 21 17 22 # -- package variables --------------- # 18 23 19 24 my $datemap = { files => {}, others => {} }; 25 my $save = 0; 26 my $format = DateTime::Format::W3CDTF->new; 20 27 my $fh = FileHandle->new; 21 28 … … 24 31 sub start { 25 32 if ( -f $file && -r _ ) { 26 $datemap = load($file);33 $datemap = YAML::Syck::LoadFile( $file ); 27 34 } 28 35 return 1; … … 37 44 mapping( $others, $datemap->{'others'} ); 38 45 39 save($file, $datemap);46 YAML::Syck::DumpFile( $file, $datemap ) if ( $save ); 40 47 41 48 return ( $files, $indexes, $others ); … … 44 51 45 52 sub mapping { 46 my ( $files, $ date ) =@_;53 my ( $files, $indexes ) = @_; 47 54 48 55 for my $path ( keys %{ $files } ) { 49 if ( exists $date->{$path} ) { 50 $files->{$path} = $date->{$path}; 56 my $key = $path; 57 $key =~ s{^$blosxom::datadir/}{}; 58 59 if ( 60 exists $indexes->{$key} 61 && $files->{$path} == $indexes->{$key}->{'lastmod'} 62 ) { 63 $files->{$path} = $indexes->{$key}->{'created'}; 51 64 } 52 65 else { 53 $date->{$path} = $files->{$path}; 66 my $created = extract_datetime( $path ); 67 if ( 68 defined $created 69 && exists $indexes->{$key} 70 && $created == $indexes->{$key}->{'created'} 71 ) { 72 $files->{$path} = $created; 73 next; 74 } 75 else { 76 my $lastmod = $files->{$path}; 77 $created = $files->{$path} if ( ! defined $created ); 78 79 $files->{$path} = $created; 80 $indexes->{$key} = { 81 created => $created, 82 lastmod => $lastmod, 83 }; 84 85 $save++; 86 write_datetime( $path, $created ); 87 } 54 88 } 55 89 } 56 90 57 for my $path ( keys %{ $date } ) { 58 delete $date->{$path} if ( ! exists $files->{$path} ); 91 for my $key ( keys %{ $indexes } ) { 92 my $path = "$blosxom::datadir/$key"; 93 if ( ! exists $files->{$path} ) { 94 delete $indexes->{$key}; 95 $save++; 96 } 97 delete $indexes->{$key} if ( ! exists $files->{$path} ); 59 98 } 60 61 99 } 62 100 63 sub load{101 sub extract_datetime { 64 102 my ( $file ) = @_; 65 103 66 my $data = { files => {}, others => {} }; 67 68 $fh->open( $file, '<' ) or die "Couldn't open file: $file: $!"; 69 while ( my $line = <$fh> ) { 104 $fh->open( $file, '<' ) or die "Failed to open file: $file: $!"; 105 my $line = <$fh>; 106 while ( $line = <$fh> ) { 70 107 chomp $line; 71 my ( $type, $mtime, $path ) = ( $line =~ m{^(\w+)[|](\d+)[|](.+)$} ); 72 $data->{$type}->{$path} = $mtime; 108 last if ( $line !~ m{^$meta_prefix} ); 109 if ( $line =~ m{^$meta_prefix$meta_date:\s*(.+?)\s*$} ) { 110 my $dt = eval { $format->parse_datetime( $1 ) }; 111 if ( defined $dt ) { 112 $fh->close; 113 return $dt->epoch(); 114 } 115 } 73 116 } 74 117 $fh->close; 75 118 76 return $data;119 return; 77 120 } 78 121 79 sub save { 80 my ( $file, $data ) = @_; 81 my $output = q{}; 122 sub write_datetime { 123 my ( $file, $mtime ) = @_; 82 124 83 for my $type ( keys %{ $data } ) { 84 for my $path ( keys %{ $data->{$type} } ) { 85 my $mtime = $data->{$type}->{$path}; 86 $output .= "${type}|$mtime|$path\n"; 125 my $output = q{}; 126 my $dt = DateTime->from_epoch( epoch => $mtime, time_zone => $timezone ); 127 my $w3cdtf = $format->format_datetime( $dt ); 128 my $meta = "${meta_prefix}${meta_date}: ${w3cdtf}\n"; 129 130 $fh->open( $file, '<' ) or die "Failed to open file: $file: $!"; 131 my $line = <$fh>; 132 $output .= "$line"; 133 my $add_meta = 0; 134 while ( $line = <$fh> ) { 135 if ( $line !~ m{^$meta_prefix} ) { 136 $output .= $meta if ( ! $add_meta ); 137 $output .= $line; 138 $output .= do { local $/; <$fh> }; 139 $fh->close; 140 last; 87 141 } 142 143 if ( $line =~ m{^$meta_prefix$meta_date} ) { 144 $output .= $meta; 145 $add_meta++; 146 } 147 else { 148 $output .= $line; 149 } 150 88 151 } 89 152 90 $fh->open( $file, '>' ) or die " Couldn'topen file: $file: $!";153 $fh->open( $file, '>' ) or die "Failed to open file: $file: $!"; 91 154 print $fh $output; 92 155 $fh->close;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)