Python tools for managing static websites?
pavlovevidence at gmail.com
Tue Oct 31 22:54:54 CET 2006
Chris Pearl wrote:
> Are there Python tools to help webmasters manage static websites?
> I'm talking about regenerating an entire static website - all the HTML
> files in their appropriate directories and sub-directories. Each page
> has some fixed parts (navigation menu, header, footer) and some
> changing parts (body content, though in specific cases the normally
> fixed parts might change as well). The tool should help to keep site
> editing DRY every piece of data, including the recurring parts, should
> exist only once.
> The above should be doable with any decent templating tool, such as
> those forming part of most CMSes and full-stack web-frameworks.
> Normally I might have just resorted to a CMS/web-framework, running
> locally on the webmaster's station, with the only addition being a
> mechanism for generating all pages composing the site and saving them
> as files.
> But such a solution might not be enough, as the system I'm looking for
> must be able to control the physical traits of the website as a
> collection of files - e.g., creation and distribution of files among
> several physical directories and subdirectories.
If you don't mind me pimping my own static website generator, you might
find HRL useful:
On one hand, it's like an ordinary templating engine in that you can
define macros and variables and such, and stick them into documents.
For example, define a sidebar macro in the file macro.hri:
<li>First menu entry</li>
<li>Second menu entry</li>
<li>Thrid menu entry</li>
This creates a new "sidebar" tag that expands to the macro definition.
You can use this macro in your main document file:
However, HRL is much more powerful than a simple templating system,
because it can embed Python code to be run during page generation.
Here's a very simple example:
hrl.doc.write("Page last generated on %s" %
Thus, unlike most templating engines, HRL can adapt very well to
unusual situations. You can embed the Python "scriptlet" into macro
definitions to create very powerful macros. For instance, you could
write a sidebar macro to automatically disable the link to the current
page--impossible with a simple text-substitution engine. Even more
powerful uses are possible. You could write a macro that inserts
information from a database into the page (which sounds kind of like
what you mentioned).
On the downside, it's not exactly hip to the latest web trends. It
uses sgmllib for input, bleagh. The list of HTML tags it knows about
is vintage 1998. (One of my design goals was freedom to be sloppy with
closing tags. HRL keeps track of and automatically closes tags when
appropriate, but it doesn't know about tags like embed.) And it's not
any sort of enterprise-quality content management. It's just a
templating engine with power.
More information about the Python-list