Tutorial: Plugins and Scripts

Plugins and Scripts

Plugins and Scripts

For some users and developers, they may need some custom functions for their sites or themes, however we cannot add all those to Hikaru, so we support plugins and scripts for them.

Scripts

For users or devs who just wants some small or theme-specific functions, they can create JavaScript files in site or theme's scripts/ dir, a script is a Node module which exports a function with a parameter for a Hikaru object like this. Hikaru can load them before dealing with site files.

module.exports = (hikaru) => {
  hikaru.logger.log("Loading custom script!")
}

You can access Hikaru's renderer, compiler, processor, generator, decorator, logger, translator, types, utils, opts and site object through the Hikaru object.

Plugins

For users or devs who wants some independent functions to release, they can create plugins. Plugins are npm packages that starts with hikaru- in their name and installed in site's node_modules dir, Hikaru can load dependencies in site's package.json before dealing with site files.

They must export a main function like scripts, this will be the entry of a plugin when Hikaru is loading them.

You are supposed to hint the plugin type with words like renderer, compiler, processor, generator, decorator, logger, translator, types, utils.

For more example, you can read the code of hikaru-generator-feed.