#!/usr/bin/perl -CSD use warnings; use strict; use v5.22; use File::Path qw(make_path remove_tree); use DateTime; use DateTime::Format::ISO8601; use File::pushd; use Text::VimColor; my %output_dir = ( 'nekodev' => '../nekodev', 'blog.nekodev' => '../blog.nekodev', 'code.nekodev' => '../code.nekodev', '' => '../tmp', 'tmpdir' => '../tmp' ); my %src_dirs = ( 'code-tmp' => 'code-tmp', 'blog' => 'blog', 'web' => 'web' ); my $blog_index = $output_dir{'tmpdir'}.'/blog_index'; sub make { foreach(@_) { system($^X, '-CSD', "../webcc", $_) if (-f $_); #`perl -d webcc $_` if (-f $_); if (-d $_) { print "Processing directory $_\n"; my $dirGlob = $_.'/*'; make(glob $dirGlob); } } } sub make_code_highlight { foreach(@_) { if (-f $_) { #$highlighter->syntax_mark_file($_); # need to overwrite vim options, as nvim doesn't provide -X flag my @vim_opts = [qw( -RZ -i NONE -u NONE -N -n ), "+set nomodeline"]; my @extra_vim_opts = ['+setg number', '+set printoptions=number:y']; my $highlighter = Text::VimColor->new( file => $_, all_syntax_groups => 1, vim_command => 'nvim', vim_options => @vim_opts, extra_vim_options => @extra_vim_opts ); my $modDate = DateTime->from_epoch( epoch => (stat $_)[9])->iso8601(); my $outFileName = $_ =~ s/^code\//code-tmp\//r; $outFileName .= ".code"; my ($dir,$saneFileName) = $_ =~ /(.*)\/(.*)/; make_path($dir); print "outputting file $outFileName\n"; open my $out_file, '>', $outFileName or die "Can't open out file $outFileName: $!"; print {$out_file} "[title]\n$saneFileName\n[date]\n$modDate\n[content]\n
\n";
$saneFileName =~ s/\./_/g;
my $lineNr = 1;
foreach(split /^/, $highlighter->html) {
my $lineId = 'L'.$lineNr.$saneFileName;
print {$out_file} "$lineNr ".$_;
$lineNr++;
}
print {$out_file} "
\n";
close $out_file;
}
if (-d $_) {
print "Processing directory $_\n";
my $dirGlob = $_.'/*';
make_code_highlight(glob $dirGlob);
}
}
}
# setup tmpdirs
{
my $dir = pushd($src_dirs{'blog'});
remove_tree($output_dir{'tmpdir'});
make_path($output_dir{'tmpdir'});
}
make_code_highlight('code');
foreach(values %src_dirs)
{
my $dir = pushd($_);
make(glob '*');
}
#make(@ARGV);
# build blog.nekodex index.html
{
my $dir = pushd('tmp');
my %post2title;
my %post2date;
open (my $FH, '<', $blog_index) or die "can't open blog_index file, no blog post or serious error: $!";
while( my $post = <$FH> ) {
chomp $post;
chomp( my $title = <$FH>);
chomp( my $date = <$FH>);
if( $date ne '' and $title ne '' )
{
$post2title{$post} = $title;
$post2date{$post} = $date;
}
}
close $FH;
# traverse by date
my $date_index = <