From 9c337f164b076d664da75aba9361d0dfff94732c Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 21 Feb 2016 22:52:43 -0300 Subject: Rename swn to SSG --- swn.pl | 199 ----------------------------------------------------------------- 1 file changed, 199 deletions(-) delete mode 100755 swn.pl (limited to 'swn.pl') diff --git a/swn.pl b/swn.pl deleted file mode 100755 index 312999e..0000000 --- a/swn.pl +++ /dev/null @@ -1,199 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -use File::Path qw(make_path remove_tree); -use Path::Class; -use Getopt::Std; - -# Root in directory. -my $dir; -my $VERSION = "v0.1"; - -sub help { - print< give you the whole file at once. - local $/=undef; - open FILE, "styles.css" or die "Cannot open file $!"; - my $styles = ; - close FILE; - - return $styles; -} - -sub markdown { - my ($file) = @_; - my $filename = "$file"; - $filename =~ s/\.html$/.md/g; - return `markdown "$filename"`; -} - -sub generate_page { - my $file = $_[0]; - my $sidebar = transverse($dir, $file); - my $styles = styles; - my $body = markdown $file; - my $page = < - - -Deprecated - - - - - -
-

-Deprecated Just coding for fun -

-
- - - -
-$body -
- - - - - -EOF -; - return $page; -} - -sub generate_link { - my ($file, $options) = @_; - $options->{hl} = 0 if !exists($options->{hl}); - - # Get the path. - my $path = $file->stringify; - $path =~ s/^$dir//g; - $path =~ s/\.md$/.html/g; - - # String to show - my $str = $file->basename; - $str =~ s/\.md$//g; - - # Higlight? - my $hl = ""; - if($options->{hl} eq 1) { - $hl = "class='hl'"; - } - - return "
  • $str
  • "; -} - -sub transverse { - my ($directory, $file_needed) = @_; - my $retval = ""; - - $retval = "
      "; - while(my $file = $directory->next) { - my $filename = $file->stringify; - - # Some conditions - next if $filename =~ /(\.|\.\.)$/; - next if $filename eq $directory; - - if($file_needed eq $file) { - $retval = "$retval" . generate_link($file, { hl => 1 }); - } else { - $retval = "$retval" . generate_link($file); - } - - if($file->is_dir()) { - my $d = $file_needed->dir->stringify; - if($file =~ /$d/ and !($d eq $directory)) { - $retval = "$retval" . transverse($file, $file_needed); - } - } - } - $retval = "$retval
    "; - - return $retval; -} - -sub run_on { - my $mddir = $_[0] || dir($dir); - remove_tree $mddir; - - while(my $file = $mddir->next) { - my $outfile = $file->stringify; - - # Some conditions - next if $outfile =~ /(\.|\.\.)$/; - next if $outfile eq $mddir; - - $outfile =~ s/$dir\//out\//g; - !($outfile =~ m/^$dir/) or die "$outfile =~ m/$dir/"; - - if($file->is_dir()) { - # make a directory - make_path $outfile; - run_on($file); - next; - } - - $outfile =~ s/md$/html/g; - print STDERR "* writing: $outfile\n"; - my $contents = generate_page $file; - - open FD, ">$outfile"; - - print FD $contents; - - close FD; - } -} - -sub main { - my %opts = ( - 'v' => 0, - 'h' => 0, - 'd' => "in" - ); - getopts('vhd:', \%opts); - - if($opts{h}) - { - help; - exit 0; - } - elsif($opts{v}) - { - version; - exit 0; - } - elsif($opts{d}) - { - $dir = dir $opts{d}; - } - - run_on dir($dir); -} - -main @ARGV; - -- cgit v1.2.3-70-g09d2