-
Notifications
You must be signed in to change notification settings - Fork 74
/
elife_converter.js
357 lines (292 loc) · 9.96 KB
/
elife_converter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
"use strict";
var util = require("../substance/util");
var _ = require("underscore");
var LensConverter = require('lens/converter');
var ElifeConverter = function(options) {
LensConverter.call(this, options);
};
ElifeConverter.Prototype = function() {
var __super__ = LensConverter.prototype;
this.test = function(xmlDoc, documentUrl) {
var publisherName = xmlDoc.querySelector("publisher-name").textContent;
return publisherName === "eLife Sciences Publications, Ltd";
};
// Config
// ---------
//
// This makes sure elife-xml-version does not show up in the info panel, as it's a custom metagroup that
// would otherwise be considered by the converter
this.__ignoreCustomMetaNames = ["elife-xml-version"];
// Add Decision letter and author response
// ---------
this.enhanceArticle = function(state, article) {
var nodes = [];
var doc = state.doc;
var heading, body;
// Decision letter (if available)
// -----------
var articleCommentary = article.querySelector("#SA1");
if (articleCommentary) {
heading = {
id: state.nextId("heading"),
type: "heading",
level: 1,
content: "Article Commentary"
};
doc.create(heading);
nodes.push(heading);
heading = {
id: state.nextId("heading"),
type: "heading",
level: 2,
content: "Decision letter"
};
doc.create(heading);
nodes.push(heading);
body = articleCommentary.querySelector("body");
nodes = nodes.concat(this.bodyNodes(state, util.dom.getChildren(body)));
}
// Author response
// -----------
var authorResponse = article.querySelector("#SA2");
if (authorResponse) {
heading = {
id: state.nextId("heading"),
type: "heading",
level: 2,
content: "Author response"
};
doc.create(heading);
nodes.push(heading);
body = authorResponse.querySelector("body");
nodes = nodes.concat(this.bodyNodes(state, util.dom.getChildren(body)));
}
// Show them off
// ----------
if (nodes.length > 0) {
this.show(state, nodes);
}
};
this.enhanceCover = function(state, node, element) {
var category;
var dispChannel = element.querySelector("subj-group[subj-group-type=display-channel] subject").textContent;
try {
category = element.querySelector("subj-group[subj-group-type=heading] subject").textContent;
} catch(err) {
category = null;
}
node.breadcrumbs = [
{ name: "eLife", url: "http://elifesciences.org/", image: "http://lens.elifesciences.org/lens-elife/styles/elife.png" },
{ name: dispChannel, url: "http://elifesciences.org/category/"+dispChannel.replace(/ /g, '-').toLowerCase() },
];
if (category) node.breadcrumbs.push( { name: category, url: "http://elifesciences.org/category/"+category.replace(/ /g, '-').toLowerCase() } );
};
// Resolves figure url
// --------
//
this.enhanceFigure = function(state, node, element) {
var graphic = element.querySelector("graphic");
var url = graphic.getAttribute("xlink:href");
node.url = this.resolveURL(state, url);
};
// Example url to JPG: http://cdn.elifesciences.org/elife-articles/00768/svg/elife00768f001.jpg
this.resolveURL = function(state, url) {
// Use absolute URL
if (url.match(/http:\/\//)) return url;
// Look up base url
var baseURL = this.getBaseURL(state);
if (baseURL) {
return [baseURL, url].join('');
} else {
// Use special URL resolving for production articles
// File extension support
if (url.match(/\.tif$/g)) {
url = url.replace(/\.tif$/g, '.jpg')
} else if (!(url.match(/\.gif$/g))) {
url = url+'.jpg'
}
return [
"http://publishing-cdn.elifesciences.org/",
state.doc.id,
"/",
url
].join('');
}
};
this.enhanceSupplement = function(state, node) {
var baseURL = this.getBaseURL(state);
if (baseURL) {
return [baseURL, node.url].join('');
} else {
node.url = [
"http://publishing-cdn.elifesciences.org/",
state.doc.id,
"/",
node.url
].join('');
}
};
this.enhancePublicationInfo = function(state) {
var article = state.xmlDoc.querySelector("article");
var articleMeta = article.querySelector("article-meta");
var publicationInfo = state.doc.get('publication_info');
// Extract research organism
// ------------
//
// <kwd-group kwd-group-type="research-organism">
// <title>Research organism</title>
// <kwd>B. subtilis</kwd>
// <kwd>D. melanogaster</kwd>
// <kwd>E. coli</kwd>
// <kwd>Mouse</kwd>
// </kwd-group>
var organisms = articleMeta.querySelectorAll("kwd-group[kwd-group-type=research-organism] kwd");
// Extract keywords
// ------------
//
// <kwd-group kwd-group-type="author-keywords">
// <title>Author keywords</title>
// <kwd>innate immunity</kwd>
// <kwd>histones</kwd>
// <kwd>lipid droplet</kwd>
// <kwd>anti-bacterial</kwd>
// </kwd-group>
var keyWords = articleMeta.querySelectorAll("kwd-group[kwd-group-type=author-keywords] kwd");
// Extract subjects
// ------------
//
// <subj-group subj-group-type="heading">
// <subject>Immunology</subject>
// </subj-group>
// <subj-group subj-group-type="heading">
// <subject>Microbiology and infectious disease</subject>
// </subj-group>
var subjects = articleMeta.querySelectorAll("subj-group[subj-group-type=heading] subject");
// Article Type
//
// <subj-group subj-group-type="display-channel">
// <subject>Research article</subject>
// </subj-group>
var articleType = articleMeta.querySelector("subj-group[subj-group-type=display-channel] subject");
// Extract PDF link
// ---------------
//
// <self-uri content-type="pdf" xlink:href="elife00007.pdf"/>
var pdfURI = article.querySelector("self-uri[content-type=pdf]");
if (pdfURI) {
var pdfLink = [
"http://publishing-cdn.elifesciences.org/",
state.doc.id,
"/",
pdfURI ? pdfURI.getAttribute("xlink:href") : "#"
].join('');
}
// Version number from the PDF href, default to 1
var match = null;
if (pdfURI) {
match = pdfURI.getAttribute("xlink:href").match(/\w*-\w*-v(\d*).pdf$/);
}
var version = match ? match[1] : 1;
// Collect Links
// ---------------
var links = [];
if (pdfLink) {
links.push({
url: pdfLink,
name: "PDF",
type: "pdf"
});
}
links.push({
url: "https://s3.amazonaws.com/elife-publishing-cdn/"+state.doc.id+"/elife-"+state.doc.id+"-v"+version+".xml",
name: "Source XML",
type: "xml"
});
// Add JSON Link
links.push({
url: "", // will be auto generated
name: "Lens JSON",
type: "json"
});
publicationInfo.research_organisms = _.pluck(organisms, "textContent");
publicationInfo.keywords = _.pluck(keyWords, "textContent");
publicationInfo.subjects = _.pluck(subjects, "textContent");
publicationInfo.article_type = articleType ? articleType.textContent : "";
publicationInfo.links = links;
if (publicationInfo.related_article) publicationInfo.related_article = "http://dx.doi.org/" + publicationInfo.related_article;
};
this.enhanceSupplement = function(state, node) {
var baseURL = this.getBaseURL(state);
if (baseURL) {
return [baseURL, node.url].join('');
} else {
node.url = [
"http://publishing-cdn.elifesciences.org/",
state.doc.id,
"/",
node.url
].join('');
}
};
this.enhanceVideo = function(state, node, element) {
var href = element.getAttribute("xlink:href").split(".");
var name = href[0];
node.url = "http://api.elifesciences.org/v2/articles/"+state.doc.id+"/media/file/"+name+".mp4";
node.url_ogv = "http://api.elifesciences.org/v2/articles/"+state.doc.id+"/media/file//"+name+".ogv";
node.url_webm = "http://api.elifesciences.org/v2/articles/"+state.doc.id+"/media/file//"+name+".webm";
node.poster = "http://api.elifesciences.org/v2/articles/"+state.doc.id+"/media/file/"+name+".jpg";
};
// Example url to JPG: http://cdn.elifesciences.org/elife-articles/00768/svg/elife00768f001.jpg
this.resolveURL = function(state, url) {
// Use absolute URL
if (url.match(/http:\/\//)) return url;
// Look up base url
var baseURL = this.getBaseURL(state);
if (baseURL) {
return [baseURL, url].join('');
} else {
// Use special URL resolving for production articles
// File extension support
if (url.match(/\.tif$/g)) {
url = url.replace(/\.tif$/g, '.jpg')
} else if (!(url.match(/\.gif$/g))) {
url = url+'.jpg'
}
return [
"http://publishing-cdn.elifesciences.org/",
state.doc.id,
"/",
url
].join('');
}
};
var AUTHOR_CALLOUT = /author-callout-style/;
this.enhanceAnnotationData = function(state, anno, element, type) {
// HACK: elife specific hack: there are 'styling' annotations to annotate
// text in a certain color associated to one author.
if (type === "named-content") {
var contentType = element.getAttribute("content-type");
if (AUTHOR_CALLOUT.test(contentType)) {
anno.type = "author_callout";
anno.style = contentType;
}
}
};
this.showNode = function(state, node) {
switch(node.type) {
// Boxes go into the figures view if these conditions are met
// 1. box has a label (e.g. elife 00288)
case "box":
if (node.label) {
state.doc.show("figures", node.id);
}
break;
default:
__super__.showNode.apply(this, arguments);
}
};
};
ElifeConverter.Prototype.prototype = LensConverter.prototype;
ElifeConverter.prototype = new ElifeConverter.Prototype();
ElifeConverter.prototype.constructor = ElifeConverter;
module.exports = ElifeConverter;