From e1ec346da17585737f16be9f8f71425b5fe51662 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 21 Feb 2016 20:31:39 -0300 Subject: Initial commit --- .gitignore | 4 ++ README.md | 3 + styles.css | 104 ++++++++++++++++++++++++++++++++ swn.pl | 199 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test.pl | 35 +++++++++++ 5 files changed, 345 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 styles.css create mode 100755 swn.pl create mode 100755 test.pl diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..574e169 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +in/ +out/ +*.md +!README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b8f4b0a --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# SWN + +Static webpage generator written in perl. diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..be7a838 --- /dev/null +++ b/styles.css @@ -0,0 +1,104 @@ +/* Based on werc.cat-v.org, suckless.org and garbe.us */ + +/* General */ +body { + color: #aaa; + font-family: sans-serif; + font-size: 80%; + margin: 0; + padding: 0; +} + +html { +} + +/* Header */ +.header { background-color: #2c3e50; border: 0; } +.header a { border: 0; color: #bdc3c7; text-decoration: none; } +.midHeader img { border: 0; } + +.headerTitle { font-size: 1.6em; font-weight: bold; margin: 0 0 0 0.5em; padding: 0.5em; } +.headerTitle a { border: 0; text-decoration: none; } + +.headerSubtitle { font-size: 0.6em; font-weight: normal; margin-left: 1em; color: #bbb; } + +/* Side */ +#side-bar { + float: left; + clear: both; + border: 0; + margin: 0; + padding: 0; + width: 80px; +} + +#side-bar ul { + margin: 0; + padding: 0.3em; + list-style-type: none; + list-style-image: none; + border: 0; +} + +#side-bar li { + /* display: inline; */ + line-height: 1.6em; + white-space: nowrap; + padding-top: 0.2em; + padding-bottom: 0.2em; +} + +#side-bar ul li a { + margin: 0; + padding: 0.1em 1ex 0.1em 1ex; + color: #336699; + background-color: transparent; + text-decoration: none; + font-size: 1em; + font-weight: bold; + border: 0; +} + +#side-bar ul li a.hl { + text-decoration: underline; +} + +#side-bar ul li a:hover { color: #111; text-decoration: none; } + +/* Main Copy */ +#main { + max-width: 70em; + color: #111; + margin: 0 auto 0 2em; + padding: 1em 3em 2em 1em; + border: 0; + margin-left: 80px; + border-left: 1px solid #aaa; +} + +#main a { color: #336699; text-decoration: none; } +#main a:hover { text-decoration: underline; } +#main h1, #main-copy h2 { color: #111; border-bottom: 1px solid #ccc; } +#main h2 { border-bottom: 1px solid #ccc; } +#main ul { list-style-type: square; } + +/* Footer */ +#footer { + background-color: #bdc3c7; + color: #111; + font-size: 91%; + padding: 2em; + clear: both; +} + +#footer .left { text-align: left; float: left; clear: left; } +#footer .right { text-align: right; } +#footer a { color: #111; text-decoration: none; } +#footer a:hover { text-decoration: underline; } + +abbr, acronym { border-bottom: 1px dotted #333; cursor: help; } +blockquote { border-left: 1px solid #333; font-style: italic; padding: 1em; } +hr { border-width: 0 0 0.1em 0; border-color: #666; } + +code, pre { font-size: 1.1em } +pre { margin-left: 2em; } diff --git a/swn.pl b/swn.pl new file mode 100755 index 0000000..312999e --- /dev/null +++ b/swn.pl @@ -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/test.pl b/test.pl new file mode 100755 index 0000000..363f870 --- /dev/null +++ b/test.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl +use strict; +use warnings; + +use Path::Class; + +sub trans { + my ($dir, $cb) = @_; + + while(my $file = $dir->next) { + my $outfile = $file->stringify; + + # Some conditions + next if $outfile =~ /(\.|\.\.)$/; + next if $outfile eq $dir; + + if($file->is_dir()) { + # make a directory + trans($file, $cb); + next; + } + + $cb->($file); + } +} + +sub some { + my ($f) = @_; + + die "f is empty" if !$f; + + print "Inside some: $f\n"; +} + +trans dir("in"), \&some; -- cgit v1.2.3-70-g09d2