Overview

Metagrid Widget

The Metagrid widget is a small snippet of javascript that shows links to additional resources about a person. It’s incorporated on the bibliographic sites of your project and facilitates the technical work of using Metagrid.

Under the hood, the widget queries the following Metagrid endpoint https://api.metagrid.ch/widget/{your-project-slug}/person/{person-identifier}.json and displays the links.

To integrate the Metagrid widget into your project page, you can use one of the following js-modules.

In the following example, we integrate the Metagrid jQuery widget into Dodis. Dodis uses the following URI template to reference persons https://dodis.ch/P{\d+}. An example is Max Petipierre with the URL https://dodis.ch/P5. Metagrid stores the “5” as the identifier for Petipierre. “Dodis” is the project slug. To query all links in Metagrid about Petitpierre you can use the following query: https://api.metagrid.ch/widget/dodis/person/5.json. We can apply that to our jquery widget

<script src="jquery.js"></script>
<script src="dist/metagrid-client.min.js"></script>
<script>
      jQuery(function ($) {
        // extract the person-identifier from the URL
        var matches = window.location.href.match(/dodis\.ch\/P(\d+)$/);
        if(matches !== null){
            var id = matches[1];
            // call the plugin indirectly
            $('#metagridWidget').data({'element-kind':'person', 'element-id': id, 'language': 'de'}).metagridClient({
                projectSlug:'dodis'
            });
        }
      });
</script>
<div id="metagridWidget"></div>

Explanation:

This above code extracts the identifier from the current URL and injects it into the jQuery plugin. If there are links for the queried person, it will display them in the #metagridWidget element.

API-Responses:

  • The API responds with a 200 if Metagrid has links for the given identifier. The answer includes the links
  • The API returns a 404 with a JSON formatted error code in the body if the API doesn’t have any links for the resource.
  • The API returns a 5xx (server error) or 4xx (client error) error code if something goes wrong.
  • The API returns a 404 with an empty body if Metagrid doesn’t know the URL, f.e. wrong projectSlug