< back to hacks

xfwk: a static site generator using pure XML

Why does this exist?

If you want to make a nice website, you will want various features (navigation bar, 88x31 badges, etc.) to appear identical on several pages. If you have lots of pages, you'd better automate this a bit! An old-fashioned way is to use server-side includes (SSI)(wikipedia) but simple web hosts like Neocities don't support it. Another way is to use JavaScript to load the content client-side , but I'm not doing that. Therefore the ideal way for me to make my website would be using a static site generator(wikipedia) .

However, I don't really like the way most SSGs work (i.e. write in Markdown; compile to HTML), so I've written my own (write in XML/HTML with special tags; compile to HTML). This allows me direct access to all features of HTML.

Features of XFWK

Using XFWK

Here is an example directory structure for a website using XFWK:

The source files (that the user edits) are stored in site/. When the user wants to publish the site, they run XFWK and the website is compiled into site.o/ and this is what is uploaded to the host (e.g. using the neocities command-line tool ).

This user has a consistent navigation bar and footer that they want to use on all their pages. In (for example) index.html, they put the tags <fwk:usetemplate name="navigation.html" /> and <fwk:usetemplate name="footer.html" /> in the correct places. In ?includes/navigation.html there is a single <html> tag containing the elements to make the navigation bar. At compile time, these are inserted into the files.

This user also has a blog where the <body> of each page is mostly the same, except for different content. In each source file for the blog, rather than the usual <body> tag, the user writes a <fwk:usetemplate name="blog-body.html"> tag wrapping the contents of the article. ?includes/navigation.html contains a <fwk:inner> tag. At compile time, the <fwk:inner> tag is replaced with the content of the <fwk:usetemplate> tag and the whole thing is inserted into the page.

The design of XFWK

The program consists of two files, xfwk and xfwk-replacer. xfwk-replacer is written in Python and converts all custom tags in a single file. xfwk is written in fish-shell and iterates over the source directory, converting all HTML files, and copying everything else except ?includes and other special files.

xfwk-replacer was originally written using the module Beautiful Soup, but that module really messed with the formatting of the HTML and made the compiled files almost unreadable; it also messed around with the whitespace, causing spaces to appear in places where they shouldn't. I rewrote it using ElementTree and it now behaves sensibly and even leaves the formatting alone!

Planned features & improvements

New tag: <fwk:script name="filename"> - process the inner text / HTML using a specified script in the ?scripts directory.

Before I do a public release I will need to work out how to use Github or whatever.

The Green Goose trans Hosted on Neocities Edited with Vim - Improved & Free - I love my editor Enter the Void Anti-fascism The Mod Archive