diff --git a/www/src/doicontroller.js b/www/src/doicontroller.js index 5d4d085641c15fb1b752e8307f09d0b32f3d688c..5918b93d74d628be3a9e9c3414a974fbaae1d6a9 100644 --- a/www/src/doicontroller.js +++ b/www/src/doicontroller.js @@ -172,15 +172,11 @@ DOIController.prototype.getDataForGoogleSearch = function (doi) { //dataType: 'text', // don't convert JSON to Javascript object success: function (data) { if (data) { - // Here we add the 'description' field in the recieved object because 'name' and 'description' fields are required by google dataset search. - if (data.name) { - if (!data.description) { - data.description = data.name; - } - _this.view.addDOIMetadataToHead(JSON.stringify(data)); - } else { - console.log("[GOOGLE SEARCH INDEXING] - The data required by Google is missing the 'name' field. This is required by Google for indexing."); - } + googleMetadataObject = new GoogleMetadataObject(data); + googleMetadataObject.setDescription(); + googleMetadataObject.setLicense(); + + _this.view.addDOIMetadataToHead(JSON.stringify(googleMetadataObject.getMetadata())); } else { console.log("[GOOGLE SEARCH INDEXING] - No metadata recieved from datacite."); } diff --git a/www/src/googleMetadataObject.js b/www/src/googleMetadataObject.js new file mode 100644 index 0000000000000000000000000000000000000000..7081586a8b921f1e4e347099fad8b62bc1d14545 --- /dev/null +++ b/www/src/googleMetadataObject.js @@ -0,0 +1,37 @@ +/** + * This class corresponds to a Google metadata object + * @param {*} data + */ +function GoogleMetadataObject(data) { + this.data = data; +} + +/** + * Get metadata + */ +GoogleMetadataObject.prototype.getMetadata = function () { + return this.data; +} + +/** + * Set a license + */ +GoogleMetadataObject.prototype.setLicense = function () { + if (!this.data.license) { + this.data.license = "https://creativecommons.org/licenses/by/4.0" + } +} + +/** + * Set a description. + */ +GoogleMetadataObject.prototype.setDescription = function () { + if (this.data.name) { + if (!this.data.description) { + this.data.description = this.data.name; + } + } else { + console.log("[GoogleMetadataObject] - The data required by Google is missing the 'name' field. This is required by Google for indexing."); + } +} +