Make collections of processed files available to listeners of next event in generator
There are several functions called by the default site generator that return a collection of files they either created or acted on. Currently, these functions are as follows:
- convertDocuments - collection of publishable pages
- produceRedirects - redirect files (i.e., web server configuration files with redirect/rewrite rules)
- mapSite - sitemap files (including robots.txt)
All of these files are available in one of the catalogs (either the content catalog or the site catalog). These collections are merely identifying which of those files were processed (created or modified). Having this list available can simplify the logic an extension must do. For example, if an extension wishes to replace the site URL in the sitemap with a token, it can do so without having to go back to the site catalog and locate the sitemaps:
pipeline.on('siteMapped', ({ playbook, sitemaps } => {
sitemaps.forEach((sitemap) => {
if (sitemap.extname !== '.xml') return
sitemap.contents = Buffer.from(sitemap.contents.toString().replaceAll(playbook.site.url, '%URL%'))
})
})
The extension could also use this list to identify files it wants to remove, then pass them to the catalog to be removed (once the catalogs provide removeFile).
The generator should assign each of these collections to a pipeline for the duration of the event that follows. These collections should be considered read only. Here are the proposed variable names for these collections:
- convertDocuments => pages
- produceRedirects => redirectFiles
- mapSite => sitemaps
Here's how that will look in the generator:
vars.pages = convertDocuments(contentCatalog, asciidocConfig)
await pipeline.notify('documentsConverted').then(() => vars.remove('pages'))
NOTE: The reason convertDocuments is mapped to pages and not documents is that, technically, the objects in the collection are the (publishable) pages from the content catalog. The function is called "convertDocuments" because it's converting the AsciiDoc documents held by those pages to embedded HTML.