Commit 6885f7e6 authored by Maxime Chaillet's avatar Maxime Chaillet

add metadata in json+ld format in the head of the doi landing page. It fixes...

add metadata in json+ld format in the head of the doi landing page. It fixes #63.
parent dc794dc1
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> ESRF - DOI </title>
<link rel="icon" href="/src/images/favicon.ico">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<!-- Using grunt-wiredep, the proper js files from bower components are included below -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/dustjs-linkedin/dist/dust-full.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="bower_components/dustjs-helpers/dist/dust-helpers.min.js"></script>
<script src="bower_components/lodash/lodash.js"></script>
<script src="bower_components/moment/moment.js"></script>
<!-- endbower -->
<!-- Using grunt-include-source, the proper js files created by us (not minified) are included below -->
<script src="src/author.js"></script>
<script src="src/beamlineurl.js"></script>
<script src="src/citation.js"></script>
<script src="src/constants.js"></script>
<script src="src/doicontroller.js"></script>
<script src="src/doiData.js"></script>
<script src="src/doiview.js"></script>
<script src="src/ESRF-DC-142893590.js"></script>
<script src="src/ESRF-DC-142915526.js"></script>
<script src="src/event.js"></script>
<script src="src/experimentalreportcontroller.js"></script>
<script src="src/jsonextractor.js"></script>
<script src="src/metadataTableHelper.js"></script>
<!-- bower:css -->
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
<!-- endbower -->
<head>
<meta charset="UTF-8">
<title> ESRF - DOI </title>
<link rel="icon" href="/src/images/favicon.ico">
<!-- Using grunt-include-source, the proper all dustjs templates files (not minified are included below -->
<script src="min/precompiled.templates.min.js"></script>
<link rel="stylesheet" href="/min/output.min.css" >
<script type="text/javascript">
$(document).ready(function() {
var doi = document.location.search.substring(5);
if (doi==="") {
alert ("Please use dev.html page as follow .../dev.html?DOI=prefix/suffix");
} else {
new DOIController(new DOIView()).getData(doi);
}
});
</script>
</head>
<body>
<div class="container-fluid">
<div class="row align-items-center blueBackground">
<div class="col-12 col-sm-4" > <img id="logo" style="height:80px;" src="/src/images/esrflogo.png" alt="the ESRF logo"> </img> </div>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<!-- Using grunt-wiredep, the proper js files from bower components are included below -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/dustjs-linkedin/dist/dust-full.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="bower_components/dustjs-helpers/dist/dust-helpers.min.js"></script>
<script src="bower_components/lodash/lodash.js"></script>
<script src="bower_components/moment/moment.js"></script>
<!-- endbower -->
<!-- Using grunt-include-source, the proper js files created by us (not minified) are included below -->
<script src="src/author.js"></script>
<script src="src/beamlineurl.js"></script>
<script src="src/citation.js"></script>
<script src="src/constants.js"></script>
<script src="src/doicontroller.js"></script>
<script src="src/doiData.js"></script>
<script src="src/doiview.js"></script>
<script src="src/ESRF-DC-142893590.js"></script>
<script src="src/ESRF-DC-142915526.js"></script>
<script src="src/event.js"></script>
<script src="src/experimentalreportcontroller.js"></script>
<script src="src/jsonextractor.js"></script>
<script src="src/metadataTableHelper.js"></script>
<!-- bower:css -->
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
<!-- endbower -->
<!-- Using grunt-include-source, the proper all dustjs templates files (not minified are included below -->
<script src="min/precompiled.templates.min.js"></script>
<link rel="stylesheet" href="/min/output.min.css">
<script type="text/javascript">
$(document).ready(function () {
var doi = document.location.search.substring(5);
if (doi === "") {
alert("Please use dev.html page as follow .../dev.html?DOI=prefix/suffix");
} else {
new DOIController(new DOIView()).getData(doi);
}
});
</script>
</head>
<body>
<div class="container-fluid">
<div class="row align-items-center blueBackground">
<div class="col-12 col-sm-4"> <img id="logo" style="height:80px;" src="/src/images/esrflogo.png" alt="the ESRF logo">
</img> </div>
<div class="col"> </div>
<div class="col-auto">
<div class="whiteFont font-3p2rem" id="doiValue">
<!-- filled by the js code -->
</div>
<div class="whiteFont font-3p2rem" id="doiValue">
<!-- filled by the js code -->
</div>
</div>
</div>
</div>
</div>
</div>
<div id="main"></div>
<div id='error' ></div>
<div class="modal">
<div id="main"></div>
<div id='error'></div>
<div class="modal">
<!-- nothing to write here -->
</div>
<footer class="footer">
<div class="container-fluid">
</div>
<footer class="footer">
<div class="container-fluid">
<div class="row">
<div class="col-12 col-md-5" >
<p><a style='font-weight:bold;' href="http://www.esrf.eu">European Synchrotron Radiation Facility</a></p>
</div>
<div class="col-12 col-md-2" >
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a>
</div>
<div class="col-12 col-md-5">
<p class="float-right" style="font-size:12px;display:block;" > Access to data is governed by the <a href="http://www.esrf.eu/files/live/sites/www/files/about/organisation/ESRF%20data%20policy-web.pdf" target="_blank">ESRF data policy</a>.</p>
</div>
<div class="col-12 col-md-5">
<p><a style='font-weight:bold;' href="http://www.esrf.eu">European Synchrotron Radiation Facility</a></p>
</div>
<div class="col-12 col-md-2">
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License"
style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a>
</div>
<div class="col-12 col-md-5">
<p class="float-right" style="font-size:12px;display:block;"> Access to data is governed by the <a
href="http://www.esrf.eu/files/live/sites/www/files/about/organisation/ESRF%20data%20policy-web.pdf"
target="_blank">ESRF data policy</a>.</p>
</div>
</div>
</div>
</footer>
</body>
</html>
</div>
</footer>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="icon" href="/src/images/favicon.ico">
<title> ESRF - DOI </title>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="/min/output.min.css" >
</head>
<script src="/min/components.min.js"></script>
<script src="/min/precompiled.templates.min.js"></script>
<script src="/min/doi.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var doi = document.location.pathname.substring(1,document.location.pathname.length);
var controller = new DOIController(new DOIView());
if (doi !="") {
controller.setOrigin("index");
}
else {
controller.setOrigin("welcome-page");
}
controller.displayMainContent(doi);
});
// search the doi entered in the search box
function searchDOI(){
var doi = $('#doiSearchBox').val();
if (!doi){doi = $('#doiSearchBox').attr('placeholder')}
var controller = new DOIController(new DOIView());
controller.setOrigin("welcome-page");
controller.getData(doi);
};
</script>
</head>
<body>
<div class="container-fluid">
<div class="row align-items-center blueBackground">
<div class="col-12 col-sm-4" > <img id="logo" style="height:80px;" src="/src/images/esrflogo.png" alt="the ESRF logo"> </img> </div>
<head>
<meta charset="UTF-8">
<link rel="icon" href="/src/images/favicon.ico">
<title> ESRF - DOI </title>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<link rel="stylesheet" href="/min/output.min.css">
</head>
<script src="/min/components.min.js"></script>
<script src="/min/precompiled.templates.min.js"></script>
<script src="/min/doi.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var doi = document.location.pathname.substring(1, document.location.pathname.length);
var controller = new DOIController(new DOIView());
if (doi != "") {
controller.setOrigin("index");
}
else {
controller.setOrigin("welcome-page");
}
controller.displayMainContent(doi);
});
// search the doi entered in the search box
function searchDOI() {
var doi = $('#doiSearchBox').val();
if (!doi) { doi = $('#doiSearchBox').attr('placeholder') }
var controller = new DOIController(new DOIView());
controller.setOrigin("welcome-page");
controller.getData(doi);
};
</script>
</head>
<body>
<div class="container-fluid">
<div class="row align-items-center blueBackground">
<div class="col-12 col-sm-4">
<img id="logo" style="height:80px;" src="/src/images/esrflogo.png" alt="the ESRF logo">
</div>
<div class="col"> </div>
<div class="col-auto">
<div class="whiteFont font-3p2rem" id="doiValue">
<!-- filled by the js code -->
</div>
<div class="whiteFont font-3p2rem" id="doiValue">
<!-- filled by the js code -->
</div>
</div>
</div>
</div>
<div id='main' ></div>
<div id='error' ></div>
<div class="modal">
<!-- nothing to write here -->
</div>
<footer class="footer">
<div class="container-fluid">
</div>
</div>
<div id='main'></div>
<div id='error'></div>
<div class="modal">
<!-- nothing to write here -->
</div>
<footer class="footer">
<div class="container-fluid">
<div class="row">
<div class="col-12 col-md-5" >
<p><a style='font-weight:bold;' href="http://www.esrf.eu">European Synchrotron Radiation Facility</a></p>
</div>
<div class="col-12 col-md-2" >
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a>
</div>
<div class="col-12 col-md-5">
<p class="float-right" style="font-size:12px;display:block;" > Access to data is governed by the <a href="http://www.esrf.eu/files/live/sites/www/files/about/organisation/ESRF%20data%20policy-web.pdf" target="_blank">ESRF data policy</a>.</p>
</div>
<div class="col-12 col-md-5">
<p><a style='font-weight:bold;' href="http://www.esrf.eu">European Synchrotron Radiation Facility</a></p>
</div>
<div class="col-12 col-md-2">
<a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License"
style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a>
</div>
<div class="col-12 col-md-5">
<p class="float-right" style="font-size:12px;display:block;"> Access to data is governed by the <a
href="http://www.esrf.eu/files/live/sites/www/files/about/organisation/ESRF%20data%20policy-web.pdf"
target="_blank">ESRF data policy</a>.</p>
</div>
</div>
</div>
</footer>
</body>
</html>
</div>
</footer>
</body>
</html>
\ No newline at end of file
......@@ -56,7 +56,7 @@ DOIController.prototype.render = function (doi, data) {
doiData.abstract = jsonExtractor.getAbstract(data);
doiData.investigationId = jsonExtractor.getInvestigationId(data);
doiData.resourceType = jsonExtractor.getResourceType(data);
doiData.proposalType = jsonExtractor.getFieldFromSubject(data.subjects, "Proposal Type Description");
......@@ -88,6 +88,7 @@ DOIController.prototype.render = function (doi, data) {
_this.view.renderDOIData(doiData);
}
};
DOIController.prototype.getData = function (doi) {
var _this = this;
......@@ -104,64 +105,93 @@ DOIController.prototype.getData = function (doi) {
}
if (this.hasAcceptedPrefix(doi)) {
$.ajax({
headers: {
Accept: "application/vnd.datacite.datacite+json"
},
type: "GET",
timeout: 15000, // triggers timeout when request pends longer than
// 5000ms
url: this.doiServer + doi,
beforeSend: function () {
_this.view.setLoading("Retrieving data from Server");
},
complete: function () {
_this.view.setLoading(false);
}
})
$.ajax({
headers: {
Accept: "application/vnd.datacite.datacite+json"
},
type: "GET",
timeout: 15000, // triggers timeout when request pends longer than
// 5000ms
url: this.doiServer + doi,
beforeSend: function () {
_this.view.setLoading("Retrieving data from Server");
},
complete: function () {
_this.view.setLoading(false);
}
})
.done(function (data) {
if (data) {
_this.render(doi, data);
}
}).fail(function (jqXHR, textStatus, errorThrown) {
/** Try with icat server **/
$.ajax({
}).fail(function (jqXHR, textStatus, errorThrown) {
/** Try with icat server **/
$.ajax({
type: "GET",
timeout: 15000, // triggers timeout when request pends longer than
// 5000ms
url: _this.icatPlusServer + doi + "/json-datacite",
url: _this.icatPlusServer + doi + "/json-datacite",
beforeSend: function () {
try{
$("logo").fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut();
try {
$("logo").fadeIn().fadeOut().fadeIn().fadeOut().fadeIn().fadeOut();
}
catch(e){}
catch (e) { }
_this.view.setLoading("Retrieving data from Server");
},
complete: function () {
_this.view.setLoading(false);
}
})
.done(function (data) {
if (data) {
_this.render(doi, data);
}
}).fail(function (jqXHR, textStatus, errorThrown) {
_this.view.renderError(jqXHR, errorThrown, _this.origin);
_this.view.setLoading(false);
});
.done(function (data) {
if (data) {
_this.render(doi, data);
}
}).fail(function (jqXHR, textStatus, errorThrown) {
_this.view.renderError(jqXHR, errorThrown, _this.origin);
_this.view.setLoading(false);
});
});
this.getDataForGoogleSearch(doi);
} else {
_this.view.renderError("Bad Prefix", _this.origin);
}
};
/**
* Get the DOI metadata in the ld+Json format as requested by google search engine for datasets.
* @param {string} doi in the format prefix/suffix
*/
DOIController.prototype.getDataForGoogleSearch = function (doi) {
var _this = this;
if (doi) {
$.ajax({
headers: {
Accept: "application/vnd.schemaorg.ld+json"
},
type: "GET",
timeout: 15000,
url: 'https://data.datacite.org/' + doi,
dataType: 'text', // don't convert JSON to Javascript object
success: function (data) {
if (data) {
_this.view.addDOIMetadataToHead(data);
}
console.log("[GOOGLE SEARCH INDEXING] - No metadata recieved from datacite.")
},
error: function (error) {
console.log("[GOOGLE SEARCH INDEXING] - Failed getting metadata from datacite.")
console.log(error.responseJSON);
}
})
}
}
/**
* Checks whether the requested doi prefix is an esrf prefix
*
* @param{string} doi The DOI number
* @return true if the prefix is an esrf prefix, false otherwise
*
*/
DOIController.prototype.hasAcceptedPrefix = function (doi) {
var prefix = doi.split('/')[0];
......
......@@ -20,8 +20,7 @@ DOIView.prototype.setLoading = function (message) {
};
/**
* Set the doi prefix/suffix text in the top banner of the doi landing page. This is done before the template is rendered.
*
* Set the doi prefix/suffix text in the top banner of the doi landing page. This is done before the template is rendered.
*/
DOIView.prototype.setDOIInTopBanner = function (doiCode) {
$("#doiValue").text("DOI > " + doiCode.toUpperCase());
......@@ -29,9 +28,7 @@ DOIView.prototype.setDOIInTopBanner = function (doiCode) {
/**
* Render experimental Report data
*
* @param {array}
* data The filename list to be displayed
* @param {array} data The filename list to be displayed
*/
DOIView.prototype.renderExperimentalReportData = function (data) {
if (data) {
......@@ -52,10 +49,10 @@ DOIView.prototype.renderExperimentalReportData = function (data) {
};
DOIView.prototype.renderDOIData = function (doiData) {
var _this = this;
var _this = this;
dust.render('landingpage_tpl', {
data: doiData,
constants : CONSTANTS
constants: CONSTANTS
}, function (err, out) {
$('#' + _this.mainPanelId).html(out);
_this.isDOIAlreadyRendered = true;
......@@ -76,11 +73,8 @@ DOIView.prototype.renderDOIData = function (doiData) {
/**
* Render the error message
*
* @param {string}
* error The error which was thrown
* @param {string}
* origin The page which caused this rendering. This directly
* influence the element id
* @param {string} errorThrown The error which was thrown
* @param {string} origin The page which caused this rendering. This directly influences the element id
*/
DOIView.prototype.renderError = function (jqXHR, errorThrown, origin) {
var template = ((origin === "welcome-page") ? "doinotfound2_tpl" : "doinotfound_tpl");
......@@ -142,7 +136,7 @@ DOIView.prototype.renderBadges = function (data) {
dust.render('badges_tpl', {
data: data,
constants : CONSTANTS
constants: CONSTANTS
}, function (err, out) {
$('#' + _this.badgePanelId).html(out);
});
......@@ -157,21 +151,17 @@ DOIView.prototype.renderMetadata = function (data) {
var _this = this;
dust.render('metadata_tpl', {
data: data,
constants : CONSTANTS
constants: CONSTANTS
}, function (err, out) {
$('#' + _this.metadataDivId).html(out);
});
}
};
/**
* Set the message which is displayed just above the "Access data button" in experimental data box.
*
* @param {object}
* data The json object reference.
* @return {string}
* the message to display
* @param {object} doiData json object reference.
* @return {string} message to display
*/
DOIView.prototype.setDataAccessMessage = function (doiData) {
if (doiData.accessibility === "Open access") {
......@@ -182,3 +172,14 @@ DOIView.prototype.setDataAccessMessage = function (doiData) {
}
};
/**
* Add JSON LD metadata to the head of the page such that google search engine can index this page.
* @param {string} data doi metadata in Json+LD format as provided by datacite.
*/
DOIView.prototype.addDOIMetadataToHead = function (data) {
$('<script>')
.attr('type', 'application/ld+json')
.text(data)
.appendTo('head');
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment