Preparation of a single site with Mokvino Web


Mokvino Web is a collection of scripts for GNU Awk, GNU Make and Mokvino which can be used to build and maintain websites.

Mokvino Web allows you to maintain a hierarchy of source files from which webpages will be built. By default, this hierarchy has the following structure:

When you're in the root directory, running make will attempt to build webpages out of the files in src/, and place them in pub/www/. Site-wide macro definitions and GNU Awk libraries should go in etc/. Intermediate files are placed in the var/ hierarchy. You only need the src/www/ files to begin with; the others will be created as required.

By default, WWWPREFIX is set to pub/www/. You can override it in Makefile to cause pages to be created in another directory. Make sure the value includes a trailing slash.

Configuration

Makefile should minimally contain the following:

all:: m5web-all

# Identify documents to be built here.  For example:
DOCS += index
DOCS += styles/main
DOCS += styles/print

# Identify simple image copies or conversions.  For example:
PNGS += icons/foo
JPEGS += icons/bar
SVGS += icons/baz
SVGZS += icons/qux

TARGET_LANGUAGE=en-GB

INDEXBASE=

include m5web.mk

That example expects the following files to exist:

  • src/www/index.m5
  • src/www/styles/main.m5
  • src/www/styles/print.m5
  • src/www/icons/foo.sfx1
  • src/www/icons/bar.sfx2
  • src/www/icons/baz.sfx3
  • src/www/icons/qux.sfx4

…where sfx1 is png or a suffix for an image type that can be converted to PNG, sfx2 is jpg or a suffix for an image type that can be converted to JPEG, etc.

Suffixes

You can configure the suffixes used for different file types, in both source and public directories. For a given type, identified by a label TYPE, there are upto four pre-defined variables in Make:

  • TYPE_DFL_SUFFIX — This is an internal suffix which you should not override. It is also the suffix used inside var/www/.

  • TYPE_SRC_SUFFIX — This is the suffix identifying the type within src/www/. You probably won't need to change this, but you can if it makes things more convenient. It defaults to $$(TYPE_DFL_SUFFIX).

  • TYPE_SUFFIX — This is the suffix identifying the type in pub/www. It defaults to $$(TYPE_DFL_SUFFIX).

  • TYPE_LNK_SUFFIX — This is the suffix used to link to files of this type. It defaults to $$(TYPE_SUFFIX). Clear it to enable content negotiation, or simply to make the link independent of the underlying technology.

The types HTML, CSS, XHTML, XSLT2HTML, PHP2HTML and STDMAP don't define a source suffix TYPE_SRC_SUFFIX, as they are usually created from Mokvino files. Other types, mainly graphics, define all four variables.

Many of these variables, especially those of the form TYPE_SUFFIX and TYPE_LNK_SUFFIX, are exported to Mokvino under the same names.

Multiple installations

You might want to have multiple installations of your site's source, each requiring variations in the configuration to suit the different environments. For example, to build your public pages, you might want to use hyperlinks without suffixes, and have each page available in all languages defined for it. Makefile would then have to contain:

all:: m5web-all

HTML_LNK_SUFFIX=

Meanwhile, for testing and preparation, you could have a local installation that only generates pages in English, and uses full suffixes, even on index pages. For that, you'd need:

all:: m5web-all

TARGET_LANGUAGE=en-GB
INDEXBASE=

To achieve both, without causing conflicts in your version-control system, use this instead:

all:: m5web-all

-include mysite-env.mk

This will cause GNU Make to search for mysite-env.mk in the same directory as Makefile, then to try other locations as defined by -Idirectory. This gives you a chance to inject local configuration by putting it in that file, without causing an error if not found.

Editing with Emacs

If you're editing with Emacs, you can make it switch into m4-mode automatically when it encounters a Mokvino file, by adding this to your ~/.emacs file:

(add-to-list 'auto-mode-alist '("\\.m5\\'" . m4-mode))

Oddly, Emacs recognizes \-escaped characters in this mode, which means it already handles Mokvino's default escaping, even though M4 doesn't recognize that kind of escaping (as far as I know)!

You also might want to enable a soft line wrap:

(add-hook 'm4-mode-hook 'visual-line-mode)

Tidying mark-up

By default, generated mark-up documents are passed through HTMLTidy. When debugging, this can be problematic, as the line numbers given by Tidy become meaningless when its input has been discarded. An untidy version is therefore kept in var/m5web/www/VNAME.untidy.

You can disable tidying up by using:

define(`matrix.tidy.HTML', ``cat'')\

Use the suffix HTML to match the fmts parameter given to matrix. The default is defined as follows:

define(`matrix.tidy.HTML', `M5WEB_LIB`/m5web/wraptidy -f var/m5web/www/'VNAME`.'FORMAT`.'DOCUMENT_LANGUAGE`.tidy-errs -utf8 -i -q'')

Note that it doesn't call tidy directly, but instead calls a script wraptidy provided by Mokvino Web, which prevents warnings generated by the command from being treated as errors by Make.

XML can also be tidied, but be aware that HTMLTidy sometimes strips away necessary spaces from XML, with disappointing results.

Compression

You can cause the final output of a file to be compressed. For a given page, you could write:

define(`matrix.compress.HTML', ``gzip -9'')\
define(`HTML_SUFFIX', ``.html.gz'')\

For a site-wide effect, you could define:

# In mysite-env.mk

HTML_COMPRESS=gzip -9
HTML_SUFFIX=.html.gz
HTML_LNK_SUFFIX=

HTML_COMPRESS specifies the command to use to perform the compression. HTML_SUFFIX must be augmented to tell the server that the files are compressed. Clearing HTML_LNK_SUFFIX means that internal URIs won't include suffixes, to enable content negotiation.