-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixup.pl
92 lines (74 loc) · 2.38 KB
/
fixup.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/perl
use strict;
use warnings;
#
# Fix up the posterous to wrodpress export
#
#
# <a href="http://getfile8.posterous.com/getfile/files.posterous.com/temp-2012-0
8-03/AaFjbFGxJqequcjcJugzlzuyutEfscaCwhaimxjIbxJIAFjhhvIaDujiDuHy/IMG_1068.JPG.s
caled1000.jpg"><img alt="Img_1068" height="375" src=".scaled500.jpg" width="500"
/
#
# 1. replace http:.*/IMG....JPG... with blog_images/IMG...JPG...
# 2. any src=".scaled500.jpg" insert IMG...JPG
# 3. replace href="http://192.168.1.100/wordpress with
# 4. Make links around the blog end in index.html
my (@line, $img_1000, $img_500);
if ($#ARGV != 0) {
print "Supply a file name\n";
exit 1;
}
my $INDEX = $ARGV[0];
open(INDEX, $INDEX) or die "Cannot open $INDEX for reading: $!\n";
while (<INDEX>) {
$_ =~ s/^<base.*/<base href="file:\/\/\/\/\/Diskstation\/NAS\/blog\/" \/>/;
$_ =~ s#http://192.168.1.100/wordpress/##g;
$_=~ s/ldlionscopy/LD Lions 2012/g;
$_=~ s/Just another WordPress site/A copy of the LD Lions 2012 Blog/g;
$_ =~ s/href=\"\"/href=\"index.html\"/g;
if ($_ !~ / href=/i) {
print $_;
next;
}
if ($_ =~ /getfile/) {
@line = split('=', $_);
#print "<<<<<< ", join("\n",@line ), "\n";
($img_1000) = ($line[1] =~ /.*\/(.*)/);
($img_500) = ($line[4] =~ /.*\/(.*)/);
if ($line[1] eq '".scaled1000.jpg"><img alt') {
# uncommon case 2
$img_1000 = $img_500;
$img_1000 =~ s/500/1000/g;
$img_1000 =~ s/jpg\".*/jpg\"><img alt/;
}
$line[1] = "\"blog_images/" . $img_1000;
($img_500) = ($line[4] =~ /.*\/(.*)/);
if ($line[4] eq '".scaled500.jpg" width') {
# case 2
$img_500 = $img_1000;
$img_500 =~ s/1000/500/g;
$img_500 =~ s/jpg\".*/jpg\" width/g;
}
$line[4] = "\"blog_images/" . $img_500;
#print ">>>>>> $_\n";
#print "<<<<<< ", join("\n",@line ), "\n";
print join("=",@line );
}
elsif ($_ =~ /href=\"2012\/.*?\/\"/) {
# a href='2012/12/'
# case 4
$_ =~ s/(href=\"2012\/.*?\/)\"/${1}index.html\"/;
print $_;
}
elsif ($_ =~ /href=\'2012\/.*?\/\'/) {
# a href='2012/12/'
# case 4
$_ =~ s/(href=\'2012\/.*?\/)\'/${1}index.html\'/;
print $_;
}
else {
print $_;
}
}
close(INDEX);