Blogging From My Phone
Last updated:I have never discussed my personal life here, for two reasons. First, it does not interest me to talk about day-to-day things. Secondly, I would find it very awkward for anyone I know to read my blog. Nevertheless, personal life can, and has interfered in my ability to continue writing.
I no longer have time to go into my office and use my computer. This explains why I haven't written anythjng in almost two years. It's not because I've gotten bored of it.
But, I am able to sneak a few minutes here and there on my phone. Early this year, I discovered Termux. After playing with it for a bit, I realized I could do all of my blogging from my phone.
This is where I'm at right now. It took me from the beginning of March to get this far, for a couple of reasons. I wanted to write my own static site generator (SSG). It turns out that I kind of had to, because I was unable to get Soupault working on this Pixel 8.
I thought writing an SSG is a good way to learn Guile Scheme. I've also been insipted by a tutorial showing an easy way to build your own site builder using shell scripts. unfortunately, I can't find that page any longer.
In the end, I can't say that my SSG is less complicated than others I have tried. Complexity seems to have grown rapidly during development. The requirenents were basically to be able to generate this site which formerly was done using Soupault. I knew I needed templating functionaluty and includes. Here are its features (in the voice of Joerg Sprave from The Slingshot Channel:
- Templates - the sttucture of a web page that can be filled in with content
- Included with this is a means to indicate what content to fill and where to put it. Currently it supports custom tags to replace content and can replace parts of tag attributes.
- Includes - copy the contents of a file and put it at the location of the include
- Index generation - take a set of files, sort them in some way, and generate a summary list as content
- Execute Scheme - take contents of a scheme tag, execute it and replace with output
- If conditional - delete content if condition is not met
- date format
The site is built using Gnu Make. One thing I have noticed is that SSGs are slow to build a site. Determining how to build a website should not be part of the focus of an SSG. This is particularly suited to a build tool like Make. With Soupault, it took me many minutes on my desktop computer. Using make -j16 takes less then 30 seconds to build from scratch, and I have not optimized it at all.
I've also changed my site so that I don't have to build from scratch. The bottom of each page used to have the timestamp of the last time I generated the site, but now it (will) have the last time that page was gernerated, to make use of the power of Make to avoid regenerating pages when nothing's changed.
Complexity
Returning to complexity, one of the things I had to make was an HTML parser. Guile has an XML to SXML parser , but it has several qualities that I did not want and it was too hard to work around.
- It expects one top level tag, like <html>. Since my posts are in markdown, the conversion to HTML doesn't end up with one top level but a series of <p> for example.
- It doesn't parse or retain doctype (quite necessary) or comments (nice to have).
- It creates HTML entities where I don't want or need them.
- Point of contention: while working on this post, I found documentation on how to parse doctype.
- I wanted to create a tag called <scheme> whose contents did not hsve to be escaped.
- More recently, I want to be able to accept embedded PHP (<?php…?>) which I don't think the parser can handle either.
At first I tried to do this in Guile with PEG (Parsing Expression Grammars). It seemed like it should be easy enough. But try as I might, the output was off. Often it would munge things together which should remain separate entities. It wouldn't consistently create a list if there was one item that matched vs. more than one item, but I needed that consistency because SXML is a really simple and consistent way to represent XML in Lisp.
After that failure, I attempted again, but just with Scheme procedures. There were still problems, and it was quickly becoming too complex. It should be noted that I do not have a lot of experience in parsing.
Forth
I had been thinking about Forth again. Some years ago I read this great article about Charles Moore. So Forth has been on my list of languages to try. Gforth (Latest docs) is available as a package for Termux, so I installed it.
Forth is definitely an interesting language. I find it hard to characterize. Jeff Fox has a lot to say about Forth, but I can find little of it that is concrete. Yes, Forth is very simple; you can hold all of it in your head. It is also very low-level; the core of the language only deals with integers.
But, it is very powerful. You can build a set of words to do whafever you need. It is here where I'm a bit stumped. I've created an HTML to SXML parser in Forth in 411 lines. So, at least I was successful here where I failed a few times in Guile, for what it's worth. But the narrative around Forth (myth? urban legend?) leads me to believe I should have achieved this in a few dozen lines at most.
Hopefully, more time using the language will help me realize this potential. For now, I'm happy that I have a custom SSG that I can enhance any way I want and it builds my web site quickly. Though it is not generuc enough for anyone to use, it could be improved in that direction. It's a fun project, to be sure.