-
Notifications
You must be signed in to change notification settings - Fork 4
/
make_jekyll.pl
executable file
·131 lines (91 loc) · 3.14 KB
/
make_jekyll.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/local/bin/perl
# reads the movabletype sqlite database and creates jekyll templates
use DateTime;
use DBI;
use utf8;
require ("/home/stmargarets/cgi-bin/common.pl");
require ("/home/stmargarets/cgi-bin/common_text.pl");
my $blog_id = 1; # 9 is stmgrts.org.uk
my $dbh = DBI->connect("dbi:SQLite:dbname=/tmp/mt.db","","",{ PrintError => 1, AutoCommit => 0 });
&get_posts();
############################
sub get_comments {
my (@out,$sth, $author, $text, $date, $email) ="";
my $sth = $dbh->prepare(qq |select c.comment_author, c.comment_text, c.comment_created_on, c.comment_email
from mt_comment as c
left join mt_entry as e on e.entry_id = c.comment_entry_id
where
c.comment_blog_id = $blog_id and
c.comment_visible = 1 and
c.comment_junk_status > -1 and
c.comment_entry_id = ?
order by c.comment_created_on|);
$sth->execute($_[0]);
$sth->bind_columns (\$author, \$text, \$date, \$email);
while ( $sth->fetch ) {
$text = &processText(&clean4textile($text));
$text =~ s/^\s+|\s+$//g; # trim all leading and trailing whitepace
$text =~ s/\n//g; # remove newline
$text =~ s/ /+/g;
$author =~ s/ /+/g;
$date =~ s/ /+/g;
$email =~ s/@/%40/;
# commented on second run
push @out, "wget 'http://www.mahnke.net/cgi-bin/comments.cgi?name=$author&email=$email&comment=$text&a=comment&date=$date&page-id=";
}
return(@out);
}
sub get_posts {
my $sth = $dbh->prepare(qq|
select e.entry_id, e.entry_title, e.entry_basename, c.category_label, e.entry_created_on, entry_text, entry_text_more, entry_excerpt, entry_keywords
from mt_entry as e
left join mt_placement as p on e.entry_id = p.placement_entry_id
left join mt_category as c on p.placement_category_id = c.category_id
where
e.entry_blog_id=$blog_id |);
$sth->execute();
$sth->bind_columns (\$id, \$title, \$basename, \$category, \$date, \$body, \$more, \$excerpt, \$keywords);
my $i = 0;
while ( $sth->fetch ) {
my ($d, $t) = split (" ", $date);
my $filename = $d."-".$basename.".textile";
my $commentfilename = $d."-".$basename;
my ($y,$m,$dt) = split("-", $d);
my $permalink = "/archives/$y/$m/$basename".".html";
if ($excerpt) {
$excerpt =~ s/\n/\n /g;
$excerpt = "excerpt: |\n $excerpt\n";
}
$title =~ s/:/:/g;
$title =~ s/"/'/g;
my @comments = &get_comments($id);
my $out = qq |---
layout: post
title: "$title"
permalink: $permalink
commentfile: $commentfilename
category: $category
date: $date
$excerpt
---
$body
$more
|; # removed $comment_code
# all purpose textile clean-ups
$out =~ s/{L-}/£/g;
$out =~ s/\^(.[^\^]*)\^/<sup>$1<\/sup>/g;
$out =~ s/_\|/\|/g; # should go line by line and chang _| to |_. per that row for <th>
`mkdir -p /tmp/jekyll/_posts/$y`;
open (OUT, ">/tmp/jekyll/_posts/$y/$filename") || die "Can't open $filename\n";
print OUT $out;
close (OUT);
if (@comments) {
$commentfilename = "$commentfilename.textile";
for $url (@comments) {
`$url$commentfilename'`;
print qq|$url.$commentfilename\n\n|;
}
}
}
}
$dbh->disconnect();