Edited from #467 (comment)
Consider using a plugin concept, e.g. in Eslint.
For a start, we can have a postRender entry point. This means something like this in site.json:
{
"plugins": [
"custom-plugin"
],
"context": { // Can consider a different name
"custom-plugin": ... data
}
}
And in src/plugins/custom-plugin.js:
module.exports = {
postRender: function (content, siteContext, pageConfig) {
// ...
return $.html();
},
};
And in Page.js:
+ .then(result => this.postRender(result, siteContext, pageConfig))
Page.prototype.postRender = function (content, siteContext, pageConfig) {
let postRenderedContent = content;
plugins.forEach((plugin) => { // Might be able to do `reduce` instead of `forEach`
if (plugin.postRender) {
postRenderedContent = plugin.postRender(postRenderedContent, siteContext, pageConfig);
}
});
return postRenderedContent;
};
Entry points we can support (for now):
.then(result => addContentWrapper(result))
-- prerender entry point--
- .then(result => this.insertSiteNav((result)))
- .then(result => this.insertFooter(result)) // Footer has to be inserted last to ensure proper formatting
- .then(result => formatFooter(result))
.then(result => markbinder.resolveBaseUrl(result, fileConfig))
.then(result => fs.outputFileAsync(this.tempPath, result))
.then(() => markbinder.renderFile(this.tempPath, fileConfig))
-- postrender entry point--
- .then(result => this.filterTags(this.frontMatter.tags, result))
- .then(result => this.addAnchors(result))
Consider migrating to plugins?
- Site nav and footer
- Tags
- Anchors
Edited from #467 (comment)
Consider using a plugin concept, e.g. in Eslint.
Entry points we can support (for now):
.then(result => addContentWrapper(result)) -- prerender entry point-- - .then(result => this.insertSiteNav((result))) - .then(result => this.insertFooter(result)) // Footer has to be inserted last to ensure proper formatting - .then(result => formatFooter(result)) .then(result => markbinder.resolveBaseUrl(result, fileConfig)) .then(result => fs.outputFileAsync(this.tempPath, result)) .then(() => markbinder.renderFile(this.tempPath, fileConfig)) -- postrender entry point-- - .then(result => this.filterTags(this.frontMatter.tags, result)) - .then(result => this.addAnchors(result))Consider migrating to plugins?