timestamp changes
This commit is contained in:
parent
e1b3cb1ea8
commit
df18376192
18
build.pl
18
build.pl
|
@ -6,6 +6,7 @@ use File::Copy::Recursive qw(dircopy);
|
||||||
use File::Find qw(finddepth);
|
use File::Find qw(finddepth);
|
||||||
use File::Path qw(make_path);
|
use File::Path qw(make_path);
|
||||||
use Markdent::Simple::Fragment;
|
use Markdent::Simple::Fragment;
|
||||||
|
use POSIX qw(strftime);
|
||||||
use Text::Template;
|
use Text::Template;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
@ -144,6 +145,12 @@ sub include_tmpl {
|
||||||
## End subroutines
|
## End subroutines
|
||||||
|
|
||||||
|
|
||||||
|
my %utils = {
|
||||||
|
strftime => \&strftime,
|
||||||
|
include_tmpl => \&include_tmpl,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
# make posts dir or die
|
# make posts dir or die
|
||||||
mkpath($postout_path) or die "Unable to create directory.";
|
mkpath($postout_path) or die "Unable to create directory.";
|
||||||
|
|
||||||
|
@ -155,7 +162,9 @@ foreach my $post (@posts) {
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
print " Processing $post->{fname}...\n";
|
print " Processing $post->{fname}...\n";
|
||||||
my $post_content = $post_tmpl->fill_in(HASH => { post => \$post, include_tmpl => \&include_tmpl });
|
my %post_hash = %utils;
|
||||||
|
$post_hash{post} = \$post;
|
||||||
|
my $post_content = $post_tmpl->fill_in(HASH => %post_hash);
|
||||||
if (defined($post_content)) {
|
if (defined($post_content)) {
|
||||||
open(POSTOUT, '>', "$postout_path/$post->{fname}.html") or die("Unable to write $post->{fname}.html: $!");
|
open(POSTOUT, '>', "$postout_path/$post->{fname}.html") or die("Unable to write $post->{fname}.html: $!");
|
||||||
print POSTOUT $post_content;
|
print POSTOUT $post_content;
|
||||||
|
@ -170,10 +179,9 @@ my @pages = all_pages_for_dir $pages_dir;
|
||||||
foreach my $pg (@pages) {
|
foreach my $pg (@pages) {
|
||||||
mkpath(dirname("$out_path/" . $pg->{fname})) or die "Unable to create directory.";
|
mkpath(dirname("$out_path/" . $pg->{fname})) or die "Unable to create directory.";
|
||||||
print " Processing $pg->{fname}...\n";
|
print " Processing $pg->{fname}...\n";
|
||||||
my $page_content = $pg->{tmpl}->fill_in(HASH => {
|
my %page_hash = %utils;
|
||||||
posts => \@posts,
|
$page_hash{posts} = \@posts;
|
||||||
include_tmpl => \&include_tmpl,
|
my $page_content = $pg->{tmpl}->fill_in(HASH => %page_hash);
|
||||||
});
|
|
||||||
if (defined($page_content)) {
|
if (defined($page_content)) {
|
||||||
open(PGOUT, '>', "$out_path/$pg->{fname}") or die("Unable to write $pg->{fname}: $!");
|
open(PGOUT, '>', "$out_path/$pg->{fname}") or die("Unable to write $pg->{fname}: $!");
|
||||||
print PGOUT $page_content;
|
print PGOUT $page_content;
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
use strict;
|
use strict;
|
||||||
use utf8;
|
use utf8;
|
||||||
use Getopt::Std;
|
use Getopt::Std;
|
||||||
use POSIX qw(strftime);
|
|
||||||
use Tie::File;
|
use Tie::File;
|
||||||
|
|
||||||
$::VERSION = "1.0.0";
|
$::VERSION = "1.0.0";
|
||||||
|
@ -21,18 +20,18 @@ if (defined $opts{n}) {
|
||||||
die "Neither -n[ew] nor -e[dited] are defined!";
|
die "Neither -n[ew] nor -e[dited] are defined!";
|
||||||
}
|
}
|
||||||
|
|
||||||
my $pretty_date = strftime "%Y-%m-%d %H:%M", localtime;
|
my $timestamp = localtime;
|
||||||
|
|
||||||
my $fname = shift @ARGV;
|
my $fname = shift @ARGV;
|
||||||
tie my @fharr, 'Tie::File', $fname or die $!;
|
tie my @fharr, 'Tie::File', $fname or die $!;
|
||||||
|
|
||||||
my $done = 0;
|
my $done = 0;
|
||||||
for (@fharr) {
|
for (@fharr) {
|
||||||
if (s/^$metavar=.+/$metavar=$pretty_date/) {
|
if (s/^$metavar=.+/$metavar=$timestamp/) {
|
||||||
print "$fname:$.: Overwriting existing \`$metavar\'\n";
|
print "$fname:$.: Overwriting existing \`$metavar\'\n";
|
||||||
$done++;
|
$done++;
|
||||||
}
|
}
|
||||||
if (s/^(---)$/$metavar=$pretty_date\n$1/) {
|
if (s/^(---)$/$metavar=$timestamp\n$1/) {
|
||||||
print "$fname:$.: Inserting new \`$metavar\'\n";
|
print "$fname:$.: Inserting new \`$metavar\'\n";
|
||||||
$done++;
|
$done++;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +40,7 @@ for (@fharr) {
|
||||||
|
|
||||||
if (!$done) {
|
if (!$done) {
|
||||||
print "$fname: No content and no \`$metavar\', inserting at end\n";
|
print "$fname: No content and no \`$metavar\', inserting at end\n";
|
||||||
push @fharr, "$metavar=$pretty_date";
|
push @fharr, "$metavar=$timestamp";
|
||||||
}
|
}
|
||||||
|
|
||||||
untie @fharr;
|
untie @fharr;
|
||||||
|
|
Loading…
Reference in a new issue