Introduction
Statistics
Contact
Development
Disclaimer
Help
!/usr/pkg/bin/perl
phlogit - a perl clone of the 'mkgopherentry' shell script
Set the phlog directory below and call with a title and a
filename. You can optionally add a -w, which will format your text
to 68 columns. The script will update your gophermap in reverse
chronological order, with a short post intro and a link to the
full post. The intro is extracted from the top of the file up to
the first blank line. Each post is tagged with the current
date. Note the script expects the file to be in the phlog
directory before you run it.
GPLv3 or later
[email protected]
$Id: phlogit,v 1.9 2017/07/29 16:32:13 slugmax Exp $
se strict;
se warnings;
se Getopt::Long;
se Text::Wrap;
y $home = $ENV{'HOME'};
y $phlog_dir = qq{$home/gopher/phlog};
y($title,$file,$wrap);
etOptions(
"title=s" => \$title,
"file=s" => \$file,
"wrap!" => \$wrap
;
ub usage {
print qq{$0 --title|-t 'title' --file|-f 'file' --wrap|-w\n};
exit;
ub slurp_file {
my $infile = shift;
open( my $fh, "<", $infile ) or die "Unable to open $infile in _slurp_file: $!…
my $text = do { local( $/ ) ; <$fh> } ;
return \$text;
ub burp_file {
my $outfile = shift;
my $text_ref = shift;
my $append = shift;
my $wrap_text = shift;
my $fh;
if ( $wrap_text ) {
$Text::Wrap::columns=68;
$$text_ref = wrap('','',$$text_ref);
}
if ($outfile eq "STDOUT") {
print $$text_ref;
} else {
if ( $append ) {
open( $fh, ">>", "$outfile" ) or die "Unable to open $outfile in _burp…
} else {
open( $fh, ">", "$outfile" ) or die "Unable to open $outfile in _burp_…
}
print $fh $$text_ref ;
}
sage() if (!$title || !$file);
y $old_gmap = slurp_file("$phlog_dir/gophermap");
y $post_text = slurp_file("$phlog_dir/$file");
Intro is any text from the start of the text file until the first blank
line (or the end of the file if there are no blank lines)
y $intro = $1 if ( $post_text && $$post_text =~ m{(.+?)(?:^$|\Z)}ms );
y $DATE = qx(date "+%A, %B %d, %Y");
y $post_blurb = qq{+++ $title +++\n $DATE\n$intro\n0Continued...\t$file\n\n};
urp_file("$phlog_dir/gophermap",\$post_blurb,0,$wrap);
urp_file("$phlog_dir/gophermap",$old_gmap,1,0);
hmod 0754, "$phlog_dir/gophermap";
hmod 0754, "$phlog_dir/$file";