Giter VIP home page Giter VIP logo

Comments (7)

eldh avatar eldh commented on May 24, 2024

Ok, now we have preProcessPosts(posts) and postProcessPosts(posts) hooks implemented. It looks in both theme/functions and antwar.config.js for functions. At this time there is still no plugin support, but the hooks system is prepared for it.

We just need to figure out how we want to define plugins. The nicest would be just an array om plugin names, but that will require some webpack alias magic to avoid doing require(unknownPluginName).

Second thing we need to do is to implement similar hooks for things inside the processing of each post, like url, date or even content. But I'll create a separate task for that.

from antwar.

bebraw avatar bebraw commented on May 24, 2024

From antwar.config.js point of view the interface explained at #11 is likely enough. You just provide an object of objects (plugin name -> configuration). Plugin name maps to NPM by default but we could support paths just like in case of themes right now to make it more versatile.

A plugin itself could look something like this (index.js):

module.exports = {
    preProcess: function(...) {},
    process: function(...) {}, // needed???
    postProcess: function(...) {},
}

This would be enough. We can add more hooks if/when needed.

from antwar.

eldh avatar eldh commented on May 24, 2024

Skipping process(), at least for now. Otherwise that looks good.

If we assume plugins are installed in the site folder I suppose we can require("plugin/"+pluginName) and have an alias: {'plugins': cwd + '/node_modules'}

from antwar.

eldh avatar eldh commented on May 24, 2024

Didn't get the require("plugin/"+pluginName) strategy to work. We have to think of some other way. One alternative is that the config file just gives an array of plugin objects. That would mean they are required from within the config file and we don't have to care if they are npm modules, local things or just something that's declared directly in the config file.

Something like:

plugins:  [
    require('a-plugin-from-npm'),
    {preProcessPosts: function(posts){…}},
    require('./local-plugin.js')
]

Not sure that would work?

from antwar.

bebraw avatar bebraw commented on May 24, 2024

Yeah, I can see your point. Isn't that analogous to how functions work now? Given that I can't see why this would fail.

from antwar.

eldh avatar eldh commented on May 24, 2024

I only see a possible issue with doing require's from there. But I'll try it.

from antwar.

bebraw avatar bebraw commented on May 24, 2024

As far as I can see preProcess/postProcess works now, even with require. I set up a demo plugin to try this out, https://github.com/antwarjs/prevnext-plugin .

While at it I simplified the plugin contract a little bit (no need for extra functions key). I think this might have been your original intention given the example above.

from antwar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.