timestamp changes

This commit is contained in:
snow flurry 2022-03-04 19:29:34 -08:00
parent e1b3cb1ea8
commit df18376192
2 changed files with 17 additions and 10 deletions

View file

@ -6,6 +6,7 @@ use File::Copy::Recursive qw(dircopy);
use File::Find qw(finddepth);
use File::Path qw(make_path);
use Markdent::Simple::Fragment;
use POSIX qw(strftime);
use Text::Template;
use strict;
@ -144,6 +145,12 @@ sub include_tmpl {
## End subroutines
my %utils = {
strftime => \&strftime,
include_tmpl => \&include_tmpl,
};
# make posts dir or die
mkpath($postout_path) or die "Unable to create directory.";
@ -155,7 +162,9 @@ foreach my $post (@posts) {
next;
}
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)) {
open(POSTOUT, '>', "$postout_path/$post->{fname}.html") or die("Unable to write $post->{fname}.html: $!");
print POSTOUT $post_content;
@ -170,10 +179,9 @@ my @pages = all_pages_for_dir $pages_dir;
foreach my $pg (@pages) {
mkpath(dirname("$out_path/" . $pg->{fname})) or die "Unable to create directory.";
print " Processing $pg->{fname}...\n";
my $page_content = $pg->{tmpl}->fill_in(HASH => {
posts => \@posts,
include_tmpl => \&include_tmpl,
});
my %page_hash = %utils;
$page_hash{posts} = \@posts;
my $page_content = $pg->{tmpl}->fill_in(HASH => %page_hash);
if (defined($page_content)) {
open(PGOUT, '>', "$out_path/$pg->{fname}") or die("Unable to write $pg->{fname}: $!");
print PGOUT $page_content;

View file

@ -3,7 +3,6 @@
use strict;
use utf8;
use Getopt::Std;
use POSIX qw(strftime);
use Tie::File;
$::VERSION = "1.0.0";
@ -21,18 +20,18 @@ if (defined $opts{n}) {
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;
tie my @fharr, 'Tie::File', $fname or die $!;
my $done = 0;
for (@fharr) {
if (s/^$metavar=.+/$metavar=$pretty_date/) {
if (s/^$metavar=.+/$metavar=$timestamp/) {
print "$fname:$.: Overwriting existing \`$metavar\'\n";
$done++;
}
if (s/^(---)$/$metavar=$pretty_date\n$1/) {
if (s/^(---)$/$metavar=$timestamp\n$1/) {
print "$fname:$.: Inserting new \`$metavar\'\n";
$done++;
}
@ -41,7 +40,7 @@ for (@fharr) {
if (!$done) {
print "$fname: No content and no \`$metavar\', inserting at end\n";
push @fharr, "$metavar=$pretty_date";
push @fharr, "$metavar=$timestamp";
}
untie @fharr;