17 |
|
|
18 |
my $debug = 0; |
my $debug = 0; |
19 |
my $max = 999; |
my $max = 999; |
20 |
|
my $attachments = 0; |
21 |
|
|
22 |
GetOptions( |
GetOptions( |
23 |
'debug+' => \$debug, |
'debug+' => \$debug, |
24 |
'max=i' => \$max, |
'max=i' => \$max, |
25 |
|
'attachments' => \$attachments, |
26 |
); |
); |
27 |
|
|
28 |
my $page; |
my $page; |
30 |
|
|
31 |
my @page_names; |
my @page_names; |
32 |
|
|
33 |
print "Collecting pages...\n"; |
print "Importing $max pages", $attachments ? " with attachments" : "", "...\n"; |
34 |
|
|
35 |
find({ |
find({ |
36 |
wanted => sub { |
wanted => sub { |
43 |
'attachment' => '+name', |
'attachment' => '+name', |
44 |
'meta' => 'name', |
'meta' => 'name', |
45 |
}, |
}, |
46 |
ForceArray => [ 'attachment', 'widget' ], |
ForceArray => [ 'attachment', 'meta', 'widget' ], |
47 |
) || die "can't open $path: $!"; |
) || die "can't open $path: $!"; |
48 |
|
|
49 |
warn "## $path = ",dump( $ref ) if $debug; |
warn "## $path = ",dump( $ref ) if $debug; |
85 |
|
|
86 |
$page->{ $name } = { |
$page->{ $name } = { |
87 |
content => convert_markup( $data ), |
content => convert_markup( $data ), |
88 |
|
original => $data, |
89 |
date => convert_date( $date ), |
date => convert_date( $date ), |
90 |
attachments => $attachments, |
attachments => $attachments, |
91 |
}; |
}; |
134 |
|
|
135 |
sub pre { |
sub pre { |
136 |
my $text = shift; |
my $text = shift; |
137 |
$text =~ s/^{{{//; |
$text =~ s/^{{{\s*//s; |
138 |
$text =~ s/}}}$//; |
$text =~ s/\s*}}}$//s; |
139 |
return '.pre' . $text . '.pre'; |
return "\n.pre\n" . $text . "\n.pre\n"; |
140 |
} |
} |
141 |
|
|
142 |
sub convert_markup { |
sub convert_markup { |
198 |
$body =~ s,``,,gs; |
$body =~ s,``,,gs; |
199 |
|
|
200 |
$body .= qq{ |
$body .= qq{ |
201 |
|
|
202 |
---- |
---- |
203 |
|
|
204 |
"original"<http://www.razmjenavjestina.org/$full_name> {date: $date} |
"original"<http://www.razmjenavjestina.org/$full_name> {date: $date} |
206 |
|
|
207 |
Encode::_utf8_off( $body ); |
Encode::_utf8_off( $body ); |
208 |
|
|
|
$Rester->put_page( $name, { content => $body, date => $date }); |
|
209 |
print "$name $date\n"; |
print "$name $date\n"; |
210 |
|
|
211 |
|
# original markup |
212 |
|
$Rester->put_page( $name, { content => $p->{original}, date => $date }); |
213 |
|
|
214 |
foreach ( @tags ) { |
foreach ( @tags ) { |
215 |
$Rester->put_pagetag( $name, $_ ); |
$Rester->put_pagetag( $name, $_, { date => $date } ); |
216 |
print "+ tag $_\n"; |
print "+ tag $_\n"; |
217 |
} |
} |
218 |
foreach my $a ( @{ $p->{attachments} } ) { |
|
219 |
my $type = $m->get_mime( $a->{full_path} ); |
if ( $attachments ) { |
220 |
my $content = read_file( $a->{full_path} ); |
foreach my $a ( @{ $p->{attachments} } ) { |
221 |
print "+ attachment ", $a->{name}," $type ", length($content), " bytes\n"; |
my $type = $m->get_mime( $a->{full_path} ); |
222 |
$Rester->post_attachment($name, $a->{name}, $content, $type ); |
my $content = read_file( $a->{full_path} ); |
223 |
|
print "+ attachment ", $a->{name}," $type ", length($content), " bytes\n"; |
224 |
|
$Rester->post_attachment($name, $a->{name}, $content, $type ); |
225 |
|
} |
226 |
} |
} |
227 |
|
|
228 |
|
# converted page |
229 |
|
$Rester->put_page( $name, { content => $body, date => $date }); |
230 |
|
|
231 |
} |
} |
232 |
|
|