1 | import ymlParse from "js-yaml";
|
2 |
|
3 | export default function(dom, data) {
|
4 | let localData = {};
|
5 | let el = dom.querySelector('script[type="text/front-matter"]');
|
6 | if (el) {
|
7 | let text = el.textContent;
|
8 | localData = ymlParse.safeLoad(text);
|
9 | }
|
10 |
|
11 | data.title = localData.title ? localData.title : "Untitled";
|
12 | data.description = localData.description ? localData.description : "No description.";
|
13 |
|
14 | data.authors = localData.authors ? localData.authors : [];
|
15 |
|
16 | data.authors = data.authors.map((author, i) =>{
|
17 | let a = {};
|
18 | let name = Object.keys(author)[0];
|
19 | if ((typeof author) === "string") {
|
20 | name = author;
|
21 | } else {
|
22 | a.personalURL = author[name];
|
23 | }
|
24 | let names = name.split(" ");
|
25 | a.name = name;
|
26 | a.firstName = names.slice(0, names.length - 1).join(" ");
|
27 | a.lastName = names[names.length -1];
|
28 | if(localData.affiliations[i]) {
|
29 | let affiliation = Object.keys(localData.affiliations[i])[0];
|
30 | if ((typeof localData.affiliations[i]) === "string") {
|
31 | affiliation = localData.affiliations[i]
|
32 | } else {
|
33 | a.affiliationURL = localData.affiliations[i][affiliation];
|
34 | }
|
35 | a.affiliation = affiliation;
|
36 | }
|
37 | return a;
|
38 | });
|
39 |
|
40 |
|
41 | }
|