Advanced site configuration

By Craig Buckler

611 words, 4-minute read

plugin
Image courtesy of Alexandre Debiève

The site build is configured by the publican.config.js file. It contains JavaScript code to:

You can add your own Publican customisations as necessary.

Function libraries #

The theme provides the following code libraries in the lib directory.

hooks.js #

This exports two functions:

publican.config.js imports and uses these as event hook functions:

import * as fnHooks from './lib/hooks.js';

// determine post date from filename
publican.config.processContent.add( fnHooks.processFileDate );

// processPostRender hook: add <meta> tags
publican.config.processPostRender.add( fnHooks.postrenderMeta );

format.js #

This provides a number of formatting functions such as:

publican.config.js imports and appends these functions to the tacs object:

import * as fnFormat from './lib/format.js';

// jsTACS functions
tacs.fn = tacs.fn || {};
tacs.fn.format = fnFormat;

Therefore, templates can format dates and numbers, e.g.

<ul>
  <li>Post written on ${ tacs.fn.format.dateHuman( data.date ) }</li>
  <li>${ tacs.fn.format.number( data.wordCount ) } words</li>
<ul>

To render:

This exports three functions:

These are complex and would be cumbersome to create in ${ expressions } alone. publican.config.js imports and appends these functions to the tacs object:

import * as fnNav from './lib/nav.js';

// jsTACS functions
tacs.fn = tacs.fn || {};
tacs.fn.nav = fnNav;

The main menu can therefore be added to a template using code such as:

<nav class="menu">
  ${ tacs.fn.nav.menuMain( data.link ) }
</nav>