Skip to content

Instantly share code, notes, and snippets.

@hraftery
Created April 18, 2021 09:28
Show Gist options
  • Save hraftery/80ae4875dab5f5af3b7c456ed5923142 to your computer and use it in GitHub Desktop.
Save hraftery/80ae4875dab5f5af3b7c456ed5923142 to your computer and use it in GitHub Desktop.
Merge all the daily pages from Roam Research into one markdown file with date headings
#!/usr/bin/perl -w
use Time::Piece;
%dailies = ();
foreach my $daily (<*.md>)
{
my $fn = $daily; #store original for use later
$daily =~ s/\.[^.]+$//; # strip extension
# Argh! strptime chokes on ordinals, but regexs can't turn month words in month numbers!
# Opted to strip ordinals and use strptime rather than using a month word/number lookup.
$daily =~ s/(?<=[0-9])(?:st|nd|rd|th)//i;
#$daily =~ m/^(\w+) (\d+)\w{2}, (\d{4})/i or die("Failed to parse filename as date: $daily\n");
my $dt = Time::Piece->strptime($daily, "%B %d, %Y");
#print "$fn: " . $dt->ymd . "\n";
$dailies{$dt->ymd} = $fn;
}
#print %dailies;
# Now iterate through all the files (reverse) chronologically.
# Fortunately, in YYYY-MM-DD, alphabetically is chronologically!
foreach my $ymd (reverse sort keys %dailies)
{
my $fn = $dailies{$ymd};
#print "$ymd ==> $fn\n";
print "# $ymd\n\n";
open(FILE, '<', $fn) or die("Failed to open daily file: $fn\n");
print <FILE>;
close(FILE);
print "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment