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 --- README.md | 4 +- ssg | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ swn.pl | 199 -------------------------------------------------------------- 3 files changed, 201 insertions(+), 201 deletions(-) create mode 100755 ssg delete mode 100755 swn.pl diff --git a/README.md b/README.md index b8f4b0a..aaded25 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# SWN +# SSG -Static webpage generator written in perl. +Static site generator written in perl. diff --git a/ssg b/ssg new file mode 100755 index 0000000..312999e --- /dev/null +++ b/ssg @@ -0,0 +1,199 @@ +#!/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; + 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