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!
Since version 5.6.1, 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.
Getting started
When starting, Datashare can receive a pluginsDir
option, pointing to your plugins' directory. In this example, this directory is called ~/Datashare Plugins
:
Installing and Removing registered plugins
Listing
You can list official Datashare plugins like this :
The string given to --pluginList
is a regular expression. You can filter the plugin list if you know what you are looking for.
Installing
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.
Removing
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 your first plugin
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 NPM documentation, 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 package.json) is injected with a <script>
tag, right before the closing </body>
tag.
Create a hello-world
directory with a single index.js
:
Reload the page, open the console: et voilà 🔮! Easy, right?
Installing and Removing your custom Plugin
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).
Adding elements to the Datashare user interface
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 Vue Component. These markers are called "hooks":
To register a new component to a hook, use the following method:
Or with a more complex example:
Last updated