spsp

Repository for the "Simplified Perl Status Poster" (SPSP).
git clone git://git.samirparikh.com/spsp
Log | Files | Refs | README

commit 07ca50aa203f1cfa597c4aaeab9d52385241fe05
parent e067ee37d5427acdfc4cbd19c3ba44627a6a02b6
Author: Samir Parikh <noreply@samirparikh.com>
Date:   Fri, 10 Feb 2023 23:15:35 +0000

convert %post hash to  hash reference

Diffstat:
Mcgi/spsp.cgi | 22++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/cgi/spsp.cgi b/cgi/spsp.cgi @@ -80,10 +80,6 @@ sub generate_post_id ( $id_length ) return join '', map $characters[ rand @characters ], 1 .. $id_length; } -### slurp the input into a scalar -### https://www.perl.com/article/21/2013/4/21/Read-an-entire-file-into-a-string/ -#chomp( my $status = do { local $/; <> } ); - ### check to see if post_data file exists. If not, create it unless ( -e $POST_DATA_FILENAME ) { @@ -108,15 +104,15 @@ my @posts = do { close $post_data_filehandle or die "Cannot close $POST_DATA_FILENAME: $!\n"; ### assemble the new post into a hash -my %post = ( +my $new_post = { $ID => generate_post_id( $ID_LENGTH ), $TITLE => scalar $cgi->param( $TITLE ), $STATUS => scalar $cgi->param( $STATUS ), $TIMESTAMP => strftime "%a %d %b %Y %H:%M %Z", localtime, -); +}; ### prepend new post to the array of posts -unshift @posts => \%post; +unshift @posts => $new_post; # write updated posts to temporary file ### open temporary file for writing @@ -167,7 +163,6 @@ foreach my $post ( @posts ) { print "<p><strong><a href=\"$post->{ $ID }.html\">$post->{ $TITLE }</a></strong>\n" unless ( $post->{ $TITLE } eq '' ); - #print "<p>$post->{ $STATUS }\n"; my $html = $markdown_to_html->markdown( $post->{ $STATUS } ); print $html, "\n"; print "<p><a href=\"$post->{ $ID }.html\">$post->{ $TIMESTAMP }</a>\n"; @@ -192,7 +187,7 @@ rename $POSTS_TEMP_HTML_FILENAME, $POSTS_HTML_FILENAME or die "Cannot rename $POSTS_TEMP_HTML_FILENAME to $POSTS_HTML_FILENAME: $!\n"; ### open filehandle to create HTML file for new post -my $new_post_html = catfile( $NEW_POST_HTML_PATH, "$post{ $ID }.html" ); +my $new_post_html = catfile( $NEW_POST_HTML_PATH, "$new_post->{ $ID }.html" ); open my $new_post_filehandle, '>', $new_post_html or die "Cannot open $new_post_html for writing: $!\n"; @@ -218,12 +213,11 @@ print <<"EOF"; <hr> EOF -print "<p><strong><a href=\"$post{ $ID }.html\">$post{ $TITLE }</a></strong>\n" - unless ( $post{ $TITLE } eq '' ); -#print "<p>$post{ $STATUS }\n"; -my $html = $markdown_to_html->markdown( $post{ $STATUS } ); +print "<p><strong><a href=\"$new_post->{ $ID }.html\">$new_post->{ $TITLE }</a></strong>\n" + unless ( $new_post->{ $TITLE } eq '' ); +my $html = $markdown_to_html->markdown( $new_post->{ $STATUS } ); print $html, "\n"; -print "<p><a href=\"$post{ $ID }.html\">$post{ $TIMESTAMP }</a>\n"; +print "<p><a href=\"$new_post->{ $ID }.html\">$new_post->{ $TIMESTAMP }</a>\n"; print "<hr>\n"; print "</body>\n";