Davide 3d97cd2724 _archives: archive old make-picolin, sh-sitify, vim-tutorial | il y a 1 an | |
---|---|---|
.. | ||
lib | il y a 1 an | |
README.md | il y a 1 an | |
sitify | il y a 1 an |
Sitify is a small, but extremely extensible bourne shell script capable of processing a directory tree and transforming it into a website (it can also be used for other processing but it's original purpose was to make websites).
Out of the box, if you run:
$ sitify origindirectory destinationdirectory
sitify will just print a terse listing of the contents of destinationdirectory. That's what the default hooks do.
Let's do something useful. We start with two directories
$ mkdir orig dest
And then we create our front page:
$ cat >orig/index.markdown <<"EOF"
Hello World!
============
How do you do?
EOF
But sitify won't do anything yet. We need to add hooks.
Edit orig/.sitify/rc:
DIR_HOOKS=${DIR_HOOKS}"
HookDirEnsure"
FILE_HOOKS=${FILE_HOOKS}"
HookFileProcess"
HookDirEnsure () {
# create the correspondent directory
mkdir -p "${DEST}${DIR}"
}
HookFileProcess () {
case "$2" in
*.markdown)
FILE_HTML="$(echo -n "$FILE" | sed 's/\.markdown$/.html/')";
/usr/bin/vendor_perl/Markdown.pl <"${ORIG}${DIR}${FILE}" >"${DEST}${DIR}${FILE_HTML}"
;;
*)
cp "${ORIG}${DIR}${FILE}" "${DEST}${DIR}${FILE}"
;;
esac
}
We added a directory hook (runs whenever the script arrives at a directory) and a file hook (runs whenever the script encounters a file). These two hooks replicate the directory structure from origin to destination, and copy every file as it is except for markdown formatted files (those are processed accordingly).
Now we just have to run sitify and fire a webserver to serve the results:
$ sitify orig dest
$ webfsd -p 8080 -f index.html -r dest
Navigating to http://localhost:8080/ should show your brand new site. Pat yourself in the back and have a beer.
There are four types of hooks:
Script variables available are the following: