shebangs
When working with a unix-like system, you've no doubt come across shebangs, like the little
#!/bin/sh
at the top of your shell scripts. The way these work is actually really simple: if you have a text file with a shebang and you set the execute bit on it, you can execute it as if you've invoked the interpreter in the shebang with that file.
For example, if you have a shell script,
script.sh
, and you place a
#!/bin/sh
at the top, executing this file will essentially run the
/bin/sh
program with the arguments
script.sh
. This probably seems quite straightforward, but it does mean you can do some pretty cool stuff.
shblg
Using this simple feature, I decided to re-write the static-generator for my site. Instead of running a single python script that will convert markdown files into html, shblg takes source files and "executes" them. I wrote a small program that takes a markdown file as an argument and converts it to html and writes it to stdout, naming it
md2html
. With this, I can place a shebang at the top of each markdown file,
#!/usr/bin/md2html
and then execute the markdown file to output an html file.
All shblg does is it recursively executes each file in a given site directory, writing their output to files in the output directory. While this does have some limitations, it can be very easily extended to any sorts of file, and since files are executed with any generic interpreter, they can contain any sort of logic like listing files, or calculating dates.
source
if you want to check out the code of shblg, you can clone it with:
git clone https://git.davidovski.xyz/shblg.git
and if you want to check out how i used it for the code of this site, you can clone it with:
git clone https://git.davidovski.xyz/davidovski.git