From 118e0b0eb6db115e12cd737d8286c3545ea95c3d Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Wed, 19 Jun 2024 17:21:59 -0300 Subject: Remove given statements and clean up some `open` files --- ssg | 64 +++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) (limited to 'ssg') diff --git a/ssg b/ssg index 4f39a06..cb125b2 100755 --- a/ssg +++ b/ssg @@ -1,9 +1,9 @@ #!/usr/bin/perl +use v5.38; use strict; use warnings; -use v5.22; -# Disable experimental warnings. -no warnings 'experimental'; + +use local::lib; use File::Path qw(make_path remove_tree); use Path::Class; @@ -38,9 +38,9 @@ EOF sub styles { # Unset $/, the Input Record Separator, to make <> give you the whole file at once. local $/=undef; - open FILE, "styles.css" or die "Cannot open file $!"; - my $styles = ; - close FILE; + open my $FILE, '<', "styles.css" or die "Cannot open file $!"; + my $styles = <$FILE>; + close $FILE; return $styles; } @@ -59,7 +59,7 @@ sub generate_page { $sidebar = transverse($indir, $file); } my $styles = styles; - my $body = markdown $file; + my $body = markdown($file); my $page = < @@ -103,36 +103,34 @@ sub generate_link { $options->{hl} = 0 if !exists($options->{hl}); # Exclude links - given($file) { - when(@exlude_files) { + if ($file) { + if (grep /^$file$/, @exlude_files) { say "excluding $file"; return ""; } - default { - my $path = $file->stringify; - my $str = $file->basename; - - if($path =~ /index\.md$/) { - return ""; - } + my $path = $file->stringify; + my $str = $file->basename; - # remove the input directory. - $path =~ s/^$indir//g; - if($file->is_dir()) { - $str = "$str/" if $file->is_dir(); - } else { - $path =~ s/\.md$/.html/g; - $str =~ s/\.md$//g; - } + if($path =~ /index\.md$/) { + return ""; + } - # Higlight? - my $hl = ""; - if($options->{hl} eq 1) { - $hl = "class='hl'"; - } + # remove the input directory. + $path =~ s/^$indir//g; + if($file->is_dir()) { + $str = "$str/" if $file->is_dir(); + } else { + $path =~ s/\.md$/.html/g; + $str =~ s/\.md$//g; + } - return "
  • $str
  • "; + # Higlight? + my $hl = ""; + if($options->{hl} eq 1) { + $hl = "class='hl'"; } + + return "
  • $str
  • "; } } @@ -197,11 +195,11 @@ sub run_on { print STDERR "* writing: " . file($outfile) . "\n"; my $contents = generate_page $file; - open FD, ">$outfile" or die " [ERROR] cannot open > $outfile: $!";; + open my $FD, '>', "$outfile" or die " [ERROR] cannot open > $outfile: $!";; - print FD $contents or die " [ERROR] Cannot write $outfile: $!"; + print $FD $contents or die " [ERROR] Cannot write $outfile: $!"; - close FD or die " [ERROR] Cannot close $outfile: $!"; + close $FD or die " [ERROR] Cannot close $outfile: $!"; } } -- cgit v1.2.3-70-g09d2