I have a small pile of side projects, and one of them is staticgen : a static site generator in Python with no dependencies at all. The goal was not to replace Hugo. The goal was to understand it.
The first version is 37 lines. It reads a folder of markdown, turns it into HTML, and drops it into a template:
def render ( post_md , template ) : lines = post_md . strip ( ) . split ( "\n" ) out = [ ] for line in lines : if line . startswith ( "# " ) : out . append ( "<h1>" + line [ 2 : ] + "</h1>" ) elif line . startswith ( "## " ) : out . append ( "<h2>" + line [ 3 : ] + "</h2>" ) else : line = line . replace ( "**" , "<strong>" , 1 ) . replace ( "**" , "</strong>" , 1 ) out . append ( "<p>" + line + "</p>" ) body = "\n" . join ( out ) title = lines [ 0 ] . lstrip ( "# " ) . strip ( ) return template . replace ( TITLE , title ) . replace ( BODY , body )
Enter fullscreen mode
Exit fullscreen mode
It worked on the one test post I wrote.…