Snippets allow you to tweak certain portions of web pages generated by Wget — for example, to replace CMS login links with plain text.
A snippet is a chunk of HTML to be substituted for another chunk in the original web page on the host (stored in the variable, url_base). Each one is assigned a numerical ID, using fixed point notation with three decimal places, i.e., between 000 and 999. They are stored as files in the snippets/ folder inside MakeStaticSite’s top-level directory, with filename matching their ID. Thus, a snippet with ID 001 the corresponding file is snippet001.html. A snippet may be used in more than one site, hence they are stored together. To differentiate sets of snippets, a numbering convention may be used, e.g., 1xx for site 1, 2xx for site 2, and so on.
To incorporate snippets, the following pair of tags need to be included in the source HTML of any page where a replacement needs to be made (in WordPress, when using the Gutenberg editor, you can insert them by using the <code> block). For ID 001, say, insert the following HTML before the content to be changed:
<!--SNIPPET001BEGIN-->
And insert the other immediately after the content:
<!--SNIPPET001END-->
An index to all the snippets is stored in snippets.data, which lists the path to each file to be modified followed by a list of snippet identifiers. A simple tag is used to demarcate sets of snippets for a particular site, where the element name corresponds to the local site name.
The following code specifies three snippets for one site and one for another:
<sigalaresearch>
index.html:1
about/website/index.html:2,3
</sigalaresearch>
<ptworld_local>
contact/index.html:4
</ptworld_local>
After a mirror is created by Wget, the script will match on <$local_sitename> and work through lines inside the tag pair, extracting the file path (the string preceding and then the comma-separated snippet IDs, with the colon as delimiter. For example, when processing the third line above, it access to the mirror to read the file about/website/index.html and looks for SNIPPET002 and SNIPPET003 tag pairs.
It will proceed to create a temporary copy of the file and path and apply the relevant snippet substitution. Depending on the settings, the revised file may be deployed and/or included in the zip file.
Once a snippet has been applied, the SNIPPET tag is removed, whereas if a SNIPPET tag is visible, the snippet has not yet been applied. The latter is true for content within the mirror/ directory, which contains the ‘raw’ snapshot before applying snippets; files which have been changed are stored in the subs/ directory.