Skip to content

Commit

Permalink
Merge pull request #2 from IQSS/1-redirct
Browse files Browse the repository at this point in the history
add code to redirect to Binder
  • Loading branch information
landreev authored Mar 11, 2024
2 parents 5a614a8 + c6a08e3 commit 79207d3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
# dataverse-binder-redirect
# Dataverse Binder Redirect

To use Binder with Dataverse, please install the following [external tool][] manifest.

[external tool]: https://guides.dataverse.org/en/latest/admin/external-tools.html

Once you do, a "Binder" button will appear under "Access Dataset". Clicking that button will send the user to a static page hosted on GitHub Pages (the code in this repo). The static page places the DOI of a dataset into a URL that Binder can understand and then redirects the user there.

For example, the user may click "Binder" and land on the static page at https://iqss.github.io/dataverse-binder-redirect/v1/?datasetPid=doi:10.7910/DVN/TJCLKP which will send the user to https://mybinder.org/v2/dataverse/10.7910/DVN/TJCLKP/

Please note that this redirect page will no longer be required once the Dataverse external tool framework supports putting parameters in the path (rather than just the query parameters) of a URL ([#9345](https://github.com/IQSS/dataverse/issues/9345)).

```bash
curl -X POST -H 'Content-type: application/json' http://localhost:8080/api/admin/externalTools -d \
'{
"displayName": "Binder",
"description": "Run on Binder",
"scope": "dataset",
"type": "explore",
"toolUrl": "https://iqss.github.io/dataverse-binder-redirect/v1/",
"toolParameters": {
"queryParameters": [
{
"datasetPid": "{datasetPid}"
}
]
}
}'
```
10 changes: 10 additions & 0 deletions v1/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
// Send datasetPid as a query parameter like this:
// https://iqss.github.io/dataverse-binder-redirect/v1/?datasetPid=doi:10.7910/DVN/TJCLKP
const urlParams = new URLSearchParams(window.location.search);
const datasetPid = urlParams.get('datasetPid');
const pidWithoutProtocol = datasetPid.split(':')[1];
// Redirect to Binder like this:
// https://mybinder.org/v2/dataverse/10.7910/DVN/TJCLKP/
window.location.replace('https://mybinder.org/v2/dataverse/' + pidWithoutProtocol + '/');
</script>

0 comments on commit 79207d3

Please sign in to comment.