diff options
author | Matthew Lemon <y@yulqen.org> | 2024-05-25 22:08:48 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-05-25 22:08:48 +0100 |
commit | 6f09b154b168876129324349ced6cd0fa32d8213 (patch) | |
tree | a2b247b440a6103dd0b3fdf7dbb20c4bc5a68aaf | |
parent | 34af3f14728ef5a3565cd2f6fec46d6bf9c3a20f (diff) |
Adds perl script to update quicknotes on blog
-rwxr-xr-x | clear_and_post_quicknote.pl | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/clear_and_post_quicknote.pl b/clear_and_post_quicknote.pl new file mode 100755 index 0000000..4938b5e --- /dev/null +++ b/clear_and_post_quicknote.pl @@ -0,0 +1,75 @@ +#!/usr/bin/env -S perl + +use 5.010; +use warnings; +use strict; +use DateTime; +use File::Copy; +use Cwd qw(getcwd); + +my $description = $ARGV[0]; + +if (not defined $description) { + print "Please pass even a paltry introductory sentence in quotes. Thanks.\n"; + exit; +} + +sub get_quicknotes { + my $quicknote_file = "/home/lemon/Documents/Notes/quicknote.md"; + my $bak = "/home/lemon/Documents/Notes/quicknote.md-BAK"; + copy($quicknote_file, $bak) or die "Failed to make backup of file: $!"; + my @quicknotes; + open my $fh, "<", $quicknote_file or die "Cannot open quicknote.md file"; + while (<$fh>) { + if ($_ =~ /^- (.*)$/) { + push @quicknotes => "- $1\n"; + } + } + truncate $quicknote_file, 0; + return \@quicknotes; +} + + +my $now = DateTime->now; +my $day_name = $now->day_name; +my $day = $now->day; +my $month = $now->month_name; +my $year = $now->year; + +my $outfile = "/home/lemon/code/html/yulqen.org/content/techjournal/quicknote_capture_${day}_${month}_$year.md"; + +my $frontmatter = <<TEXT; +--- +title: "Quicknote capture $day_name $day $month $year" +date: $now +draft: false +categories: ["Tech"] +tags: ['quicknotes'] +--- + +$description + +TEXT + +my $qn_ref = get_quicknotes(); +open my $FH, ">>", $outfile or die $!; +print $FH $frontmatter; +foreach (@{$qn_ref}) { + print $FH $_; +} +close($FH); + +chdir "/home/lemon/code/html/yulqen.org"; +say getcwd(); +# my @gitstatuscmd = ("git", "status"); +my @gitaddcmd = ("git add -u"); +my @gitcommitcmd = ("git commit -m 'update'"); +my @gitpushcmd = ("git push"); +my @pushcmd = ("make push"); +system(@pushcmd) or die "Cannot push the file to the remote: $?"; +system(@gitaddcmd) or die "Cannot do git add $?"; +system(@gitcommitcmd) or die "Cannot do git commit: $?"; +system(@gitpushcmd) or die "Cannot do git push: $?"; + +say "Done!"; + |