10 @ oct

genosite script from suckless.org, with little modifications

Improvements

  • Use urlencode.sh so that you can use special characters in the folder or file names
  • Shows a blank character instead of an underscore in the menu
  • With GNU ls, list categories (folders) before simple articles (files)

Markdown implementation

Original implementation of the markdown language was made in perl. There is many markdown implementations in many other languages, including php or python.

Mate, wait a minute. There’s a C implementation !

It works great and offers so much better performances than perl !

Download it there

Markdown syntax

Learn it !

Download (MIT/X license)

Here is my hacked genosite script

  1 #!/bin/sh
  2 EXT=md
  3 #FMT=/usr/local/bin/markdown.pl
  4 FMT=/usr/local/bin/markdown
  5 LC_ALL=fr_FR.UTF-8
  6 PATH=/bin:/usr/bin:/usr/local/bin
  7 PREFIX=/
  8 #URL=http://zecrazytux.net
  9 #export LC_ALL PATH
 10
 11
 12 menu() {
 13         for i in `gls --group-directories-first -F $1 | grep -v index.$EXT`
 14         do
 15                 case $i in
 16                 *.$EXT)
 17                         base=`echo $i | sed "s/.\$EXT$//"`
 18                         cleanbase=`echo $base | sed 's/_/ /g'`
 19                         link=`echo $base | /usr/local/bin/urlencode.sh`
 20                         if test "x$base" = "x$2"
 21                         then
 22                                 echo "<li class='current'><a href='$base.html'>$cleanbase</a></li>"
 23                         else
 24                                 echo "<li><a href='$link.html'>$cleanbase</a></li>"
 25                         fi
 26                         cur=1
 27                         ;;
 28                 */)
 29                         j=`echo $i | sed 's/_/ /g'`
 30                         echo "<li><a href='$i'>$j</a></li>"
 31                         ;;
 32                 esac
 33         done
 34         cat <<END
 35         </ul>
 36                 </div>
 37 END
 38 }
 39
 40 page() {
 41         mtime=`ls -l $1$2.$EXT | awk '{ print $6 " @ " $7 }'`
 42         title=`echo $4 | sed 's/.html//'`
 43         cat <<END
 44 <!DOCTYPE HTML>
 45 <html>
 46 <head>
 47         <meta charset="utf-8">
 48         <title>$title</title>
 49         <link type="text/css" rel="stylesheet" href="/style.css">
 50 </head>
 51 <body>
 52 <div id="container">
 53         <div id="main">
 54                 <div id="menu">
 55                 <ul>
 56                         <li class="path">$3</a></li>
 57 END
 58         menu $1 $2
 59 cat <<END
 60                 <div id="content">
 61                         <div class="edit">$mtime</div>
 62 END
 63         cat $1$2.$EXT | tr -d '\r' | $FMT
 64         cat <<END
 65                 </div>
 66         </div>
 67         <div id="footer">
 68                 Everything *written* on this website can be copied, redistributed, modified, and what the fuck else you want - Website generated using hacked Genosite script from suckless.org
 69         </div>
 70 </div>
 71 </body></html>
 72 END
 73 }
 74
 75 process() {
 76         for i in `ls -F $1`
 77         do
 78                 case $i in
 79                 *.$EXT)
 80                         echo processing $1$i
 81                         base=`echo $i | sed "s/.\$EXT$//"`
 82                         if test x$base = xindex
 83                         then
 84                                 title=$3
 85                         else
 86                                 title=$3$base.html
 87                         fi
 88                         page "$1" "$base" "$2" "$title" > "$1$base.html"
 89                         ;;
 90                 */)
 91                         k=`echo $i | sed 's/_/ /g'`
 92                         process "$1$i" "$2</a> <a href='$PREFIX$1$i'>$k" $3$i
 93                         ;;
 94                 *)
 95                         ;;
 96                 esac
 97         done
 98 }
 99
100 if test $1
101 then
102         cd $1
103 fi
104 find . -type l | xargs rm -f
105 process "./" "<a href='/'>Accueil/" /