8 |
use Regexp::Common qw/balanced/; |
use Regexp::Common qw/balanced/; |
9 |
use Socialtext::Resting; |
use Socialtext::Resting; |
10 |
use Encode; |
use Encode; |
11 |
|
use HTTP::Date; |
12 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
13 |
|
|
14 |
|
my $max = 2; |
15 |
|
|
16 |
my $page; |
my $page; |
17 |
|
my $page_date; |
18 |
|
|
19 |
find({ |
find({ |
20 |
wanted => sub { |
wanted => sub { |
21 |
my $path = $File::Find::name; |
my $path = $File::Find::name; |
22 |
return unless -f $path; |
return unless -f $path; |
23 |
|
|
24 |
warn "# $path\n"; |
warn "# $path\n"; |
25 |
my $ref = XMLin( $path ) || die "can't open $path: $!"; |
my $ref = XMLin( $path ) || die "can't open $path: $!"; |
26 |
$page->{ $ref->{name} } = $ref->{widgets}->{widget}->{data}; |
|
27 |
warn dump( $ref->{widgets}->{widget}->{data} ); |
my $name = $ref->{name} || die "no name in $path"; |
28 |
|
my $date = $ref->{meta}->{LastModified}; |
29 |
|
if ( ! $date ) { |
30 |
|
warn "SKIP: no LastModified in $path $name"; |
31 |
|
return; |
32 |
|
} |
33 |
|
my $data = |
34 |
|
$ref->{widgets}->{widget}->{data} || |
35 |
|
$ref->{widgets}->{widget}->{Body}->{data} || |
36 |
|
die "no data in $path ",dump( $ref ); |
37 |
|
|
38 |
|
$page->{ $name } = [ $data, $date ]; |
39 |
|
|
40 |
|
#warn dump( $ref ); |
41 |
}, |
}, |
42 |
}, shift @ARGV || '.'); |
}, shift @ARGV || '.'); |
43 |
|
|
44 |
|
my @pages = ( keys %$page ); |
45 |
|
|
46 |
warn "found following pages: ", join(", ", keys %$page),"\n"; |
warn "found following pages: ", join(", ", @pages),"\n"; |
47 |
|
|
48 |
my $Rester = Socialtext::Resting->new( |
my $Rester = Socialtext::Resting->new( |
49 |
username => 'tamtam', |
username => 'tamtam', |
68 |
return $with . $what . $with; |
return $with . $what . $with; |
69 |
} |
} |
70 |
|
|
71 |
|
my $count = 0; |
72 |
|
|
73 |
foreach my $name ( keys %$page ) { |
foreach my $name ( keys %$page ) { |
74 |
my $body = $page->{$name} || die "no content for page $name"; |
last if $count++ == $max; |
75 |
|
|
76 |
|
my ( $body, $date ) = @{ $page->{$name} }; |
77 |
|
$date = time2str( $date ); |
78 |
|
|
79 |
$body =~ s/\Q[[TableOfContents]]\E/{toc}/gs; |
$body =~ s/\Q[[TableOfContents]]\E/{toc}/gs; |
80 |
$body =~ s/\Q[[BR]]\E/\n/gs; |
$body =~ s/\Q[[BR]]\E/\n/gs; |
83 |
$body =~ s/'''(.+?)'''/surround('*',$1)/gse; |
$body =~ s/'''(.+?)'''/surround('*',$1)/gse; |
84 |
$body =~ s/''(.+?)''/surround('_',$1)/gse; |
$body =~ s/''(.+?)''/surround('_',$1)/gse; |
85 |
|
|
86 |
|
$body =~ s/^\s+([\*])/$1/gm; |
87 |
|
|
88 |
Encode::_utf8_off( $body ); |
Encode::_utf8_off( $body ); |
89 |
|
|
90 |
$Rester->put_page( $name, $body ); |
my @tags = ( 'TamTam' ); |
91 |
$Rester->put_pagetag( $name, 'TamTam' ); |
|
92 |
|
if ( $name =~ m!/! ) { |
93 |
|
my @page_tags = split(m!/!, $name); |
94 |
|
pop @page_tags; # remove page name |
95 |
|
push @tags, @page_tags; |
96 |
|
$name =~ s!/!_!g; |
97 |
|
} |
98 |
|
|
99 |
|
$Rester->put_page( $name, { |
100 |
|
content => $body, |
101 |
|
date => $date, |
102 |
|
}); |
103 |
print "+ $name\n"; |
print "+ $name\n"; |
104 |
|
foreach ( @tags ) { |
105 |
|
$Rester->put_pagetag( $name, $_ ); |
106 |
|
print "+ $name [$_]\n"; |
107 |
|
} |
108 |
|
|
109 |
} |
} |
110 |
|
|