aboutsummaryrefslogtreecommitdiff
path: root/ssg
diff options
context:
space:
mode:
Diffstat (limited to 'ssg')
-rwxr-xr-xssg64
1 files changed, 31 insertions, 33 deletions
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 = <FILE>;
- 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 = <<EOF
<!doctype html>
<html>
@@ -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 "<li><a $hl href='$path'>$str</a></li>";
+ # Higlight?
+ my $hl = "";
+ if($options->{hl} eq 1) {
+ $hl = "class='hl'";
}
+
+ return "<li><a $hl href='$path'>$str</a></li>";
}
}
@@ -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: $!";
}
}