-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake-metadata.js
More file actions
92 lines (62 loc) · 2.09 KB
/
make-metadata.js
File metadata and controls
92 lines (62 loc) · 2.09 KB
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
var fs = require('fs-extra'),
path = require('path'),
async = require('async'),
parseXML = require('xml2js').parseString;
module.exports = {};
module.exports.init = function init(callback) {
// "independent" only, for now
var source = path.resolve(
self.config.mypath,
self.config.source.independent
);
// - get list of independent styles …
fs.readdir(source, function (err, styles) {
// - catch error or empty result
if (err || !styles) {
callback(err || new Error("No styles found!"));
}
var list = self._list;
// - filter the non-csl files from `styles` list
// - make obj for each item
async.each(
styles,
function (item, callback) {
// - if it is "foo.csl"
if (path.extname(item) === self.config.ext) {
// contruct basic obj
var obj = {
"id": item.replace(self.config.ext, ''), // "foo"
"path": path.resolve(self.config.mypath, self.config.source.independent, item)
};
// - read some props from xml…
readXML(obj.path, function (err, res) {
var info = res.style.info;
// require('eyes').inspect(info);
// - grab some info about the styles
obj.url = info.id;
['issn', 'eissn', 'title', 'updated'].forEach(function (prop) {
obj[prop] = info[prop];
});
// - push to results
list.push(obj);
// - no error so far, continue
callback(null);
});
}
},
function (err) {
console.log(err);
// - callback with resulting array of objs
callback(err || null, {
"independent": list
});
}
);
});
}
// internal functions
function readXML(path, callback) {
fs.readFile(path, function (err, data) {
parseXML(data, callback);
})
}