antwarjs / antwar

A static site generator built with React and Webpack.
https://antwar.js.org/
MIT License
460 stars 35 forks source link

Implement a plugin API #11

Closed bebraw closed 9 years ago

bebraw commented 9 years ago

It should be possible to hook into the rendering process through a plugin API. Example configuration:

plugins: {
    // the tag plugin would operate based on posts tags metadata + provide a data source that can be used for routing
    // ie. it would shape ['foo', 'bar'] into [{name: 'foo', url: '...', posts: [...]}, {name: 'bar', url: '...', posts: [...]}]
    // you can see url shaping function below
    'antwar-tags': {},
    // there could be an image plugin to deal with thumbnail generation
    'antwar-images': {}, // is this actually needed here? push to higher level?
    'antwar-popular-posts': { // https://www.npmjs.com/package/ga-server
        id: '...',
        clientEmail: '...',
        privateKey: '...'
    }, // adds popularity field for each post
},

Each plugin is a NPM plugin with a matching name. It can take an object containing options related to it.

Interface of a plugin can look like this:

module.exports = function(meta) {
    // do something with the meta, manipulate somehow ie. see examples above

    ...

    return meta;
};
bebraw commented 9 years ago

I guess it's safe to close this now. We have preProcess/postProcess hooks and it's possible to load external packages. Further development can be done through separate issues.