-
Notifications
You must be signed in to change notification settings - Fork 12
/
custom_converter.js
75 lines (60 loc) · 2.23 KB
/
custom_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
"use strict";
var LensConverter = require('lens/converter');
var LensArticle = require("lens/article");
var CustomNodeTypes = require("./nodes");
var CustomConverter = function(options) {
LensConverter.call(this, options);
};
CustomConverter.Prototype = function() {
this.test = function(xmlDoc) {
var publisherName = xmlDoc.querySelector("publisher-name").textContent;
return publisherName === "My Journal";
};
// Override document factory so we can create a customized Lens article,
// including overridden node types
this.createDocument = function() {
var doc = new LensArticle({
nodeTypes: CustomNodeTypes
});
return doc;
};
// Resolve figure urls
// --------
//
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
return [
"http://cdn.elifesciences.org/elife-articles/",
state.doc.id,
"/jpg/",
url,
".jpg"
].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";
};
};
CustomConverter.Prototype.prototype = LensConverter.prototype;
CustomConverter.prototype = new CustomConverter.Prototype();
CustomConverter.prototype.constructor = CustomConverter;
module.exports = CustomConverter;