#!env perl

use YAML::XS 'LoadFile', 'Dump';
use File::Slurp 'read_file';

my @index = LoadFile('/home/peter/work/websites/peter/src/blog/index.yaml');

for my $doc (@index) {
    my $filename = delete $doc->{filename};
    my $html_file = delete $doc->{html_file};
    $html_file =~ s/html$/md/;
    my $output_file = 'content/posts/'.$html_file;
    print $output_file."\n";
    open my $fh, '>', $output_file;
    print {$fh} Dump($doc);
    print {$fh} "---\n\n";
    my $content = read_file('/home/peter/work/websites/peter/src/blog/'.$filename);
    print {$fh} $content;
    close $fh;
}
