@iebh/reflib 2.6.5 → 2.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/modules/bibtex.js +15 -8
- package/package.json +1 -1
package/modules/bibtex.js
CHANGED
|
@@ -4,12 +4,17 @@ import Emitter from '../shared/emitter.js';
|
|
|
4
4
|
* Example: "Roomruangwong2020"
|
|
5
5
|
*/
|
|
6
6
|
function generateCitationKey(ref) {
|
|
7
|
-
let
|
|
8
|
-
if (
|
|
9
|
-
|
|
7
|
+
let author = 'Anon';
|
|
8
|
+
if (ref.authors && ref.authors.length > 0) {
|
|
9
|
+
author = ref.authors[0].split(',')[0];
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
|
|
12
|
+
let year = 'n.d.';
|
|
13
|
+
if (ref.year) {
|
|
14
|
+
year = ref.year;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return `${author}${year}`;
|
|
13
18
|
}
|
|
14
19
|
/**
|
|
15
20
|
* Lookup enum for the current parser mode we are in
|
|
@@ -76,9 +81,7 @@ export function readStream(stream, options) {
|
|
|
76
81
|
} else if (!settings.recNumberNumeric && match.groups.id) { // Non numeric / finite ID - but we're allowed to accept it anyway
|
|
77
82
|
ref.recNumber = +match.groups.id;
|
|
78
83
|
} else if (settings.recNumberKey) { // Non numeric, custom looking key, stash in 'key' instead
|
|
79
|
-
ref.key =
|
|
80
|
-
// ref.key = match.groups.id;
|
|
81
|
-
console.log("Here is the id",ref.key)
|
|
84
|
+
ref.key = match.groups.id;
|
|
82
85
|
} // Implied else - No ID, ignore
|
|
83
86
|
|
|
84
87
|
ref.type = match.groups.type;
|
|
@@ -230,6 +233,10 @@ export function writeStream(stream, options) {
|
|
|
230
233
|
return Promise.resolve();
|
|
231
234
|
},
|
|
232
235
|
write: ref => {
|
|
236
|
+
if (!ref.key) {
|
|
237
|
+
ref.key = generateCitationKey(ref);
|
|
238
|
+
}
|
|
239
|
+
// console.log("Here is the id",ref.key)
|
|
233
240
|
// Fetch Reflib type definition
|
|
234
241
|
let rlType = (ref.type || settings.defaultType) && translations.types.rlMap.get(ref.type.toLowerCase());
|
|
235
242
|
let btType = rlType?.bt || settings.defaultType;
|