genhtml — Static HTML Inserts for Website Files

New: as of June 2017, genhtml now handles ".*" Mac/Unix cruft files in inserts and templates folders. This includes both ".DS_Store" Finder files, and any "._*" AppleDouble resource-fork files on non-Mac drives. Both are skipped in inserts to avoid errors, but are simply copied like other non-HTML in templates because more may pop up before publication—filter later with your zip or upload tools (e.g., ziptools).

See the new script's docstring for details. For a quick example of genhtml at work, see also the template file for the page you are viewing, and its expansion via your browser's "view source." There's also a new example site-publisher master script that uses genhtml as a nested tool, and is used to publish the website you are viewing.

This Python 3.X program replaces keys in a folder's HTML code files with the content of correspondingly-named text files, providing basic HTML macro functionality. For static content, it can be used to avoid mass cut-and-pastes (which are prohibitively tedious); JavaScript hacks on the client (which users may disable); and PHP server-side inserts (which can make your pages dependent on a server).

Among its features, this program has automatic dependency tracking—HTML files are regenerated when their templates or any inserts they use have changed; configurable Unicode support—encodings in a sequence are tried in turn for each HTML file; and one-level nested inserts—insert files can insert other insert files. It also serves to illustrate a typical utility role for Python scripts.

See the main script's docstring and other items below for usage details.

Code and docs:

Example:

Usage:

Download/view all:

This program was last changed June 11, 2017.

For more code examples, see the programs page.


[Python Logo] Home Books Programs Blog Python Author Training Email Search ©M.Lutz