-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
203 lines (169 loc) · 4.72 KB
/
utils.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
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.convertEditionToCslRecord = exports.convertSectionToCslRecord = exports.makeAssetTitle = void 0;
var _react = _interopRequireDefault(require("react"));
var _peritextUtils = require("peritext-utils");
var _reactCiteproc = require("react-citeproc");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const makeAssetTitle = (resource, production, edition) => {
const type = resource.metadata.type;
switch (type) {
case 'glossary':
return resource.data.name ? resource.data.name : `${resource.data.firstName} ${resource.data.lastName}`;
case 'bib':
const item = (0, _peritextUtils.resourceToCslJSON)(resource)[0];
const citation = (0, _reactCiteproc.makeBibliography)({
[item.id]: item
}, edition.data.citationStyle.data, edition.data.citationLocale.data, {
select: [{
field: 'id',
value: resource.data.citations[0].id
}]
})[1];
return _react.default.createElement("div", {
dangerouslySetInnerHTML: {
__html: citation
}
});
/* eslint react/no-danger : 0 */
default:
return resource.metadata.title;
}
};
exports.makeAssetTitle = makeAssetTitle;
const convertSectionToCslRecord = (section, production, edition = {}) => {
const {
data: editionData = {}
} = edition;
const {
publicationTitle,
publicationDate,
publicationAuthors = [],
bibType: parentBibType = 'book'
} = editionData;
const title = publicationTitle || production.metadata.title;
const globalAuthors = publicationAuthors.length ? publicationAuthors : production.metadata.authors || [];
let sectionBibType;
const record = {};
record.id = section.id;
record.title = section.metadata.title;
let now;
if (publicationDate) {
now = new Date(publicationDate);
} else {
now = new Date();
}
const year = now.getFullYear();
const month = now.getMonth();
const day = now.getDate();
record.issued = {
'date-parts': [year, month, day]
};
const authors = section.metadata.authors && section.metadata.authors.length ? section.metadata.authors : globalAuthors;
record.abstract = production.metadata.abstract;
record.author = authors.map(a => ({
given: a.given,
family: a.family
}));
switch (parentBibType) {
case 'article':
sectionBibType = 'article';
break;
case 'book':
case 'booklet':
case 'inbook':
case 'incollection':
sectionBibType = 'chapter';
record.booktitle = title;
break;
case 'mastersthesis':
case 'phdthesis':
sectionBibType = 'chapter';
record.booktitle = title;
break;
case 'proceedings':
case 'inproceedings':
sectionBibType = 'paper-conference';
record.booktitle = title;
break;
case 'techreport':
case 'unpublished':
case 'manual':
case 'misc':
default:
sectionBibType = 'webpage';
break;
}
record.type = sectionBibType;
return record;
};
exports.convertSectionToCslRecord = convertSectionToCslRecord;
const convertEditionToCslRecord = (production, edition = {}) => {
const {
data: editionData = {}
} = edition;
const {
publicationTitle,
publicationDate,
publicationAuthors = [],
bibType = 'book'
} = editionData;
const title = publicationTitle || production.metadata.title;
const globalAuthors = publicationAuthors.length ? publicationAuthors : production.metadata.authors || [];
const record = {};
record.id = production.id;
record.title = title;
record.abstract = production.metadata.abstract;
let now;
if (publicationDate) {
now = new Date(publicationDate);
} else {
now = new Date();
}
const year = now.getFullYear();
const month = now.getMonth();
const day = now.getDate();
record.issued = {
'date-parts': [year, month, day]
};
record.author = globalAuthors.map(a => ({
given: a.given,
family: a.family
}));
switch (bibType) {
case 'booklet':
case 'incollection':
case 'inbook':
case 'proceedings':
record.type = 'chapter';
break;
case 'mastersthesis':
case 'phdthesis':
record.type = 'thesis';
break;
case 'inproceedings':
record.type = 'paper-conference';
break;
case 'techreport':
record.type = 'report';
break;
case 'manual':
case 'unpublished':
record.type = 'manuscript';
break;
case 'misc':
record.type = 'webpage';
break;
/*
* case "article":
* case "book":
*/
default:
record.type = bibType;
break;
}
return record;
};
exports.convertEditionToCslRecord = convertEditionToCslRecord;