Add another nanoblogger-to-nikola conversion script.
I can't believe I'd forgotten that I already wrote one, but this newer one is simpler and is what I actually used to migrate things.
This commit is contained in:
parent
475f734e15
commit
4392a451e3
90
nb2nikola-rev2.pl
Executable file
90
nb2nikola-rev2.pl
Executable file
|
@ -0,0 +1,90 @@
|
|||
#!/usr/bin/perl -w
|
||||
use strict;
|
||||
use Date::Manip;
|
||||
use Unicode::Normalize;
|
||||
|
||||
sub slugify($) {
|
||||
my ($input) = @_;
|
||||
|
||||
$input = NFKD($input); # Normalize the Unicode string
|
||||
$input =~ tr/\000-\177//cd; # Strip non-ASCII characters (>127)
|
||||
$input =~ s/[^\w\s-]//g; # Remove all characters that are not word characters (includes _), spaces, or hyphens
|
||||
$input =~ s/^\s+|\s+$//g; # Trim whitespace from both ends
|
||||
$input = lc($input);
|
||||
$input =~ s/[-\s]+/-/g; # Replace all occurrences of spaces and hyphens with a single hyphen
|
||||
|
||||
return $input;
|
||||
}
|
||||
|
||||
my %catlist = (
|
||||
1 => "photos",
|
||||
2 => "free_software",
|
||||
3 => "old_advogato",
|
||||
4 => "old_diaryland",
|
||||
5 => "life_and_bs",
|
||||
6 => "writings",
|
||||
7 => "project365",
|
||||
8 => "food"
|
||||
);
|
||||
|
||||
Date_Init();
|
||||
|
||||
while (<STDIN>) {
|
||||
chomp;
|
||||
|
||||
my ($fname, $cat) = split(/>/, $_);
|
||||
|
||||
my @cats = split(/,/, $cat);
|
||||
|
||||
for (my $i = 0; $i < scalar(@cats) ; $i++) {
|
||||
$cats[$i] = $catlist{$cats[$i]};
|
||||
}
|
||||
|
||||
my ($title, $date, $slug, $author, $desc, $format, $body);
|
||||
|
||||
$body = "";
|
||||
|
||||
open INFILE, "<$fname";
|
||||
while (<INFILE>) {
|
||||
if ($_ =~ /TITLE:\s*(.*)/) {
|
||||
$title = $1;
|
||||
$slug = slugify($title);
|
||||
} elsif ($_ =~ /DATE:\s*(.*)@(.*)/) {
|
||||
$date = new Date::Manip::Date;
|
||||
$date->parse("$1 $2");
|
||||
} elsif ($_ =~ /AUTHOR:\cs*(.*)/) {
|
||||
$author = $1;
|
||||
} elsif ($_ =~ /DESC:\s*(.*)/) {
|
||||
$desc = $1;
|
||||
} elsif ($_ =~ /FORMAT:\s*(.*)/) {
|
||||
$format = $1;
|
||||
} elsif ($_ =~ /BODY:\s*/) {
|
||||
# SKIP
|
||||
} elsif ($_ =~ /-----/) {
|
||||
# SKIP
|
||||
} elsif ($_ =~ /END-----/) {
|
||||
last;
|
||||
} else {
|
||||
$body .= $_;
|
||||
}
|
||||
}
|
||||
close INFILE;
|
||||
|
||||
$fname = $date->printf("%q");
|
||||
open OUTFILE, ">$fname-$slug.md";
|
||||
print OUTFILE "<!--\n";
|
||||
print OUTFILE ".. title: $title\n";
|
||||
print OUTFILE ".. slug: $fname-$slug\n";
|
||||
print OUTFILE ".. date: " . $date->printf("%Y-%m-%d %H:%M:%S UTC%z") . "\n";
|
||||
print OUTFILE ".. tags: " . join(",", @cats) . "\n";
|
||||
print OUTFILE ".. category: blog\n";
|
||||
print OUTFILE ".. link: \n";
|
||||
print OUTFILE ".. description: $desc\n";
|
||||
print OUTFILE ".. type: text\n";
|
||||
print OUTFILE "-->\n";
|
||||
print OUTFILE $body;
|
||||
close OUTFILE;
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue