|
219 | 219 | } |
220 | 220 |
|
221 | 221 | $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 | + } |
227 | 231 | } |
228 | 232 | var data = { |
229 | 233 | "@context": "http://schema.org", |
|
233 | 237 | }; |
234 | 238 |
|
235 | 239 | 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 | + }) |
237 | 246 | assignTo('name', $scope.getValue($scope.model.metadata, ['Title', 'value'])) |
238 | 247 | assignTo('description', $scope.getValue($scope.model.metadata, ['Description', 'value'])) |
239 | 248 | assignTo('keywords', $scope.getValue($scope.model.metadata, ['Subject', 'value'])) |
240 | 249 | 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 | + }) |
242 | 255 | 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 | + }) |
244 | 264 | 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 | + }) |
246 | 273 | assignTo('contributor', $scope.getValue($scope.model.metadata, ['Contributor', 'value'])) |
247 | 274 |
|
248 | 275 | angular.element(document.querySelector('#schemaTags')).html(JSON.stringify(data)) |
|
0 commit comments