/[socialtext-import]/tamtam/tamtam2socialtext.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /tamtam/tamtam2socialtext.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 13 by dpavlin, Wed Dec 12 17:14:58 2007 UTC revision 14 by dpavlin, Wed Dec 12 17:56:54 2007 UTC
# Line 30  find({ Line 30  find({
30    
31                  return if $name =~ m/^TamSystem/;                  return if $name =~ m/^TamSystem/;
32    
33                  my $date =  $ref->{meta}->{LastModified};                  my $date =  $ref->{meta}->{LastModified}->{value};
34                  if ( ! $date ) {                  if ( ! $date ) {
35                          warn "SKIP: no LastModified in $path $name";                          warn "SKIP: no LastModified in $path $name";
36                          return;                          return;
# Line 40  find({ Line 40  find({
40                          $ref->{widgets}->{widget}->{Body}->{data} ||                          $ref->{widgets}->{widget}->{Body}->{data} ||
41                          die "no data in $path ",dump( $ref );                          die "no data in $path ",dump( $ref );
42    
43                  $data .= qq{                  $page->{ $name } = {
44  ----                          content => convert_markup( $data ),
45                            date => time2str( $date ),
46  Original: http://www.razmjenavjestina.org/$path                  };
 };  
   
                 $page->{ $name } = [ $data, $date ];  
47    
48                  # strip path from page name                  # strip path from page name
49                  $name =~ s,^.+/([^/]+)$,$1,;                  $name =~ s,^.+/([^/]+)$,$1,;
# Line 92  sub pre { Line 89  sub pre {
89          return '.pre' . $text . '.pre';          return '.pre' . $text . '.pre';
90  }  }
91    
92  my $count = 0;  sub convert_markup {
93            my $body = shift;
 foreach my $name ( keys %$page ) {  
         last if $count++ == $max;  
   
         my ( $body, $date ) = @{ $page->{$name} };  
         $date = time2str( $date );  
94    
95          $body =~ s/\Q[[TableOfContents]]\E/{toc}/gs;          $body =~ s/\Q[[TableOfContents]]\E/{toc}/gs;
96          $body =~ s/\Q[[BR]]\E/\n/gs;          $body =~ s/\Q[[BR]]\E/\n/gs;
# Line 115  foreach my $name ( keys %$page ) { Line 107  foreach my $name ( keys %$page ) {
107          $body =~ s/\["([^"]+)"\]/[$1]/gs;          $body =~ s/\["([^"]+)"\]/[$1]/gs;
108          $body =~ s,\[(http://\S+)\s+([^\]]+)\],"$2"<$1>,gs;          $body =~ s,\[(http://\S+)\s+([^\]]+)\],"$2"<$1>,gs;
109          $body =~ s,\[(http://[^\]]+)\],$1,gs;          $body =~ s,\[(http://[^\]]+)\],$1,gs;
         $body =~ s,$page_link_re,[$1],gs;  
110    
111          Encode::_utf8_off( $body );          # fix hr
112            $body =~ s,(\S+)----,$1\n----,gs;
113            $body =~ s,----(\S+),----\n$1,gs;
114    
115            return $body;
116    }
117    
118    my $count = 0;
119    
120    foreach my $name ( keys %$page ) {
121            last if $count++ == $max;
122    
123            my $p = $page->{$name};
124            my $body = $p->{content} || die "no content?";
125            my $date = $p->{date} || die "no date?";
126    
127          my @tags = ( 'TamTam' );          my @tags = ( 'TamTam' );
128    
# Line 127  foreach my $name ( keys %$page ) { Line 132  foreach my $name ( keys %$page ) {
132                  push @tags, @page_tags;                  push @tags, @page_tags;
133          }          }
134    
135            # link named pages
136            $body =~ s,$page_link_re,[$1],gs;
137    
138            $body .= qq{
139    ----
140    
141    Original: http://www.razmjenavjestina.org/$name
142    };
143    
144            Encode::_utf8_off( $body );
145    
146          $Rester->put_page( $name, {          $Rester->put_page( $name, {
147                  content => $body,                  content => $body,
148                  date => $date,                  date => $date,
149          });          });
150          print "+ $name\n";          print "+ $name $date\n";
151          foreach ( @tags ) {          foreach ( @tags ) {
152                  $Rester->put_pagetag( $name, $_ );                  $Rester->put_pagetag( $name, $_ );
153                  print "+ $name [$_]\n";                  print "+ $name [$_]\n";

Legend:
Removed from v.13  
changed lines
  Added in v.14

  ViewVC Help
Powered by ViewVC 1.1.26