Write plugins
What if you want to integrate text translations to Datashare’s interface? Or make it display tweets scraped with Twint? Ask no more: there is plugins for that!
Last updated
What if you want to integrate text translations to Datashare’s interface? Or make it display tweets scraped with Twint? Ask no more: there is plugins for that!
Last updated
Since , instead of modifying Datashare directly, you can now isolate your code with a specific set of features and then configure Datashare to use it. Each Datashare user could pick the plugins they need or want, and have a fully customized installation of our search platform.
When starting, Datashare can receive a pluginsDir
option, pointing to your plugins' directory. In this example, this directory is called ~/Datashare Plugins
:
You can list official Datashare plugins like this :
The string given to --pluginList
is a . You can filter the plugin list if you know what you are looking for.
You can install a plugin with its id and providing where the Datashare plugins are stored:
Then if you launch Datashare with the same plugin location, the plugin will be loaded.
When you want to stop using a plugin, you can either remove by hand the directory inside the plugins folder or remove it with datashare --pluginDelete
:
Create a hello-world
directory with a single index.js
:
Reload the page, open the console: et voilà 🔮! Easy, right?
Now you would like to develop your plugin in your repository and not necessarily in Datashare Plugins
folder.
You can have your code under, say ~/src/my-plugin
and deploy it into Datashare with the plugin API. To do so, you'll need to make a zip or a tarball, for example in ~/src/my-plugin/dist/my-plugin.tgz
.
The tarball could contain :
Then you can install it with:
And remove it:
In that case my-plugin
is the base directory of the plugin (the one that is in the tarball).
To register a new component to a hook, use the following method:
Or with a more complex example:
To inject plugins, Datashare will look for a Node-compatible module in ~/Datashare Plugins
. This way we can rely on NPM/Yarn to handle built packages. As described in , it can be:
Datashare will read the content of each module in the plugins directory to automatically inject them in the user interface. The backend will serve the plugin files. The entrypoint of each plugin (usually the main property of ) is injected with a <script>
tag, right before the closing </body>
tag.
To allow external developers to add their own components, we added markers in strategic locations of the user interface where a user can define new . These markers are called "hooks":
datashare.config.set('hooksDebug', true)
.