Skip to content

Commit ace4a50

Browse files
committed
add creator and publisher type to schema.org tags
1 parent d75a3dd commit ace4a50

File tree

1 file changed

+36
-9
lines changed

1 file changed

+36
-9
lines changed

datastore/apps/sra/static/sra/js/landingpage.js

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,15 @@
219219
}
220220

221221
$scope.maybeAssign = function(obj) {
222-
var objectToAssignTo = obj;
223-
return function (key, val) {
224-
if (val == null) return objectToAssignTo;
225-
objectToAssignTo[key] = val;
226-
}
222+
var objectToAssignTo = obj;
223+
return function (key, getVal) {
224+
var val = (typeof getVal === 'function')
225+
? getVal()
226+
: getVal;
227+
if (val == null) return objectToAssignTo;
228+
objectToAssignTo[key] = val;
229+
return objectToAssignTo;
230+
}
227231
}
228232
var data = {
229233
"@context": "http://schema.org",
@@ -233,16 +237,39 @@
233237
};
234238

235239
var assignTo = $scope.maybeAssign(data);
236-
assignTo('url', "https://doi.org/" + $scope.getValue($scope.model.metadata, ['Identifier', 'value']))
240+
241+
assignTo('url', function() {
242+
return ($scope.getValue($scope.model.metadata, ['Identifier', 'value']))
243+
? 'https://doi.org/' + $scope.model.metadata.Identifier.value
244+
: null
245+
})
237246
assignTo('name', $scope.getValue($scope.model.metadata, ['Title', 'value']))
238247
assignTo('description', $scope.getValue($scope.model.metadata, ['Description', 'value']))
239248
assignTo('keywords', $scope.getValue($scope.model.metadata, ['Subject', 'value']))
240249
assignTo('license', $scope.getValue($scope.model.display, ['rightsUrl']))
241-
assignTo('identifier', "DOI: " + $scope.getValue($scope.model.metadata, ['Identifier', 'value']))
250+
assignTo('identifier', function() {
251+
return ($scope.getValue($scope.model.metadata, ['Identifier', 'value']))
252+
? 'DOI: ' + $scope.model.metadata.Identifier.value
253+
: null
254+
})
242255
assignTo('citation', $scope.getValue($scope.model.display, ['readableCitation']))
243-
assignTo('creator', $scope.getValue($scope.model.metadata, ['Creator', 'value']))
256+
assignTo('creator', function() {
257+
return ($scope.getValue($scope.model.metadata, ['Creator', 'value']))
258+
? {
259+
"type": "Person",
260+
"name": $scope.model.metadata.Creator.value
261+
}
262+
: null
263+
})
244264
assignTo('datePublished', $scope.getValue($scope.model.metadata, ['Publication Year', 'value']))
245-
assignTo('publisher', $scope.getValue($scope.model.metadata, ['Publisher', 'value']))
265+
assignTo('publisher', function() {
266+
return ($scope.getValue($scope.model.metadata, ['Publisher', 'value']))
267+
? {
268+
"type": "Organization",
269+
"name": $scope.model.metadata.Publisher.value
270+
}
271+
: null
272+
})
246273
assignTo('contributor', $scope.getValue($scope.model.metadata, ['Contributor', 'value']))
247274

248275
angular.element(document.querySelector('#schemaTags')).html(JSON.stringify(data))

0 commit comments

Comments
 (0)