diff --git a/public/js/citationSheetParse.js b/public/js/citationSheetParse.js index 810796ab5f870c47243a3121dab747113cc83c6d..908547f21e6dc3c4f59158ddb12f458049ccbf49 100644 --- a/public/js/citationSheetParse.js +++ b/public/js/citationSheetParse.js @@ -3,6 +3,9 @@ // var jsonContent = []; +var bibAuthors = ""; +var bit1stAuthorLN =""; + /* set up XMLHttpRequest */ var url = "./content/CitationSheet.xlsx"; @@ -31,6 +34,8 @@ xmlHttpRequest.onload = function (e) { var jsonOutput = XLSX.utils.sheet_to_json(worksheet); for (i = 0; i < jsonOutput.length; i++) { + var authors = jsonOutput[i].Authors.replace("and ", "").trim().split(","); + var bibAuthors; var item = { "item": { "title": "", @@ -50,12 +55,13 @@ xmlHttpRequest.onload = function (e) { "pdf": "", "url": "", "demo": "" - } + }, + "bibtex" : "" } - var authors = jsonOutput[i].Authors.replace("and ", "").trim().split(","); - item["item"].title = jsonOutput[i].Titel; - item["item"].project = jsonOutput[i].Project; + + bibAuthors = ""; + bit1stAuthorLN =""; for (j = 0; j < authors.length; j++) { var author = { "firstName": "", @@ -65,23 +71,38 @@ xmlHttpRequest.onload = function (e) { author["firstName"] = authors[j].trim().split(".")[0]; author["lastName"] = authors[j].trim().split(".")[1]; item["item"].authors.push(author); + bibAuthors+=authors[j].trim().split(".")[1] + ", "+ authors[j].trim().split(".")[0]+ " and "; } else if (authors[j].trim().split(" ").length == 2) { author["firstName"] = authors[j].trim().split(" ")[0]; author["lastName"] = authors[j].trim().split(" ")[1]; item["item"].authors.push(author); + bibAuthors+=authors[j].trim().split(" ")[1] + ", "+ authors[j].trim().split(" ")[0]+ " and "; } else if (authors[j].trim().split(" ").length == 3) { author["firstName"] = authors[j].trim().split(" ")[0]; author["lastName"] = authors[j].trim().split(" ")[2]; item["item"].authors.push(author); + bibAuthors+=authors[j].trim().split(" ")[2] + ", "+ authors[j].trim().split(" ")[0]+ " and "; } } - item["item"].imageLink = jsonOutput[i]["Path to demo image"] + if (jsonOutput[i].Keywords != undefined) { item["item"].keywords = jsonOutput[i].Keywords.split(","); } else { item["item"].keywords = jsonOutput[i].Keywords; } + + if (authors[0].split(" ").length == 3 ){ + bit1stAuthorLN = authors[0].split(" ")[2]; + } else if (authors[0].split(" ").length == 2 ){ + bit1stAuthorLN = authors[0].split(" ")[1]; + } else if (authors[0].split(" ").length == 1 ){ + bit1stAuthorLN = authors[0].split(" ")[0]; + } + + item["item"].title = jsonOutput[i].Titel; + item["item"].project = jsonOutput[i].Project; + item["item"].imageLink = jsonOutput[i]["Path to demo image"] item["item"].journal.name = jsonOutput[i].Journal; item["item"].journal.volume = jsonOutput[i].Volume; item["item"].journal.year = jsonOutput[i].Year; @@ -91,14 +112,31 @@ xmlHttpRequest.onload = function (e) { item["links"].url = jsonOutput[i].URL; item["links"].demo = jsonOutput[i].URL; + //// BibTex ///////////////////// + item["bibtex"] = "@article{"+ bit1stAuthorLN + jsonOutput[i].Year +","+ + "title={"+ jsonOutput[i].Titel + + "},author={"+ bibAuthors.trim().substring(0, bibAuthors.trim().lastIndexOf(" ")) + + "},journal={"+ jsonOutput[i].Journal + + "},volume={"+ jsonOutput[i].Volume + + // "},number={"+ number + "},pages={"+ jsonOutput[i].Pages + + "},year={"+ jsonOutput[i].Year + + "},DOI ={"+ jsonOutput[i].DOI+ + "},url ={"+ jsonOutput[i].URL+ + "}}" + jsonContent.push(item); } - // console.log(jsonContent); + console.log(jsonContent); } xmlHttpRequest.send(); + +// str = str.substring(0, lastIndex); + + // // ending of xlsx to json coversion //