Skip to content

Support custom MarkBind plugins #470

Description

@jamos-tay

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){letpostRenderedContent=content;plugins.forEach((plugin)=>{// Might be able to do `reduce` instead of `forEach`if(plugin.postRender){postRenderedContent=plugin.postRender(postRenderedContent,siteContext,pageConfig);}});returnpostRenderedContent;};

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions