|
|
|
@ -6,12 +6,14 @@ global.window = window; |
|
|
|
|
var showdown = require("showdown"); |
|
|
|
|
const converterShowdown = new showdown.Converter(); |
|
|
|
|
const libxmljs = require("libxmljs"); |
|
|
|
|
const getTerm = require("./getTerm.js"); |
|
|
|
|
|
|
|
|
|
fs.readFile("./events.xml", "utf8", (err, data) => { |
|
|
|
|
fs.readFile("../../events.xml", "utf8", (err, data) => { |
|
|
|
|
if (err) { |
|
|
|
|
console.error(err); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
data = data.replace(/<!DOCTYPE.*>/, ""); |
|
|
|
|
parseXML(data); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -41,6 +43,8 @@ const parseTime = (dateStr, timeStr) => { |
|
|
|
|
return date; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const nodeChildrenToString = (nodeChildren) => { |
|
|
|
|
let string = ""; |
|
|
|
|
for (let i = 0; i < nodeChildren.length; ++i) { |
|
|
|
@ -56,54 +60,36 @@ const nodeChildrenToString = (nodeChildren) => { |
|
|
|
|
const parseXML = (XML) => { |
|
|
|
|
const xmlDoc = libxmljs.parseHtml(XML); |
|
|
|
|
let eventdefsChildren = xmlDoc.get("//eventdefs").childNodes(); |
|
|
|
|
let currentTerm = ""; |
|
|
|
|
for (let i = 0; i < eventdefsChildren.length; ++i) { |
|
|
|
|
eventdefsChildren.forEach((eventItem) => { |
|
|
|
|
// sometimes there's events that are commented out, hopefully this catches that
|
|
|
|
|
if ( |
|
|
|
|
eventdefsChildren[i].type() === "comment" && |
|
|
|
|
/((winter)|(fall)|(spring))/.exec( |
|
|
|
|
eventdefsChildren[i].toString().toLowerCase() |
|
|
|
|
) |
|
|
|
|
) { |
|
|
|
|
currentTerm = eventdefsChildren[i].text().replace(/[\\\\/:*?\"<>|]/g, ""); |
|
|
|
|
currentTerm = currentTerm.replace(/(\s+)/g, "-"); |
|
|
|
|
} else if (eventdefsChildren[i].type() === "element") { |
|
|
|
|
const title = eventdefsChildren[i].attr("title").value(); |
|
|
|
|
const shortNodes = eventdefsChildren[i].get(".//short").childNodes(); |
|
|
|
|
if (eventItem.type() === "element") { |
|
|
|
|
const title = eventItem.attr("title").value(); |
|
|
|
|
const shortNodes = eventItem.get(".//short").childNodes(); |
|
|
|
|
let short = converterShowdown.makeMarkdown( |
|
|
|
|
nodeChildrenToString(shortNodes) |
|
|
|
|
); |
|
|
|
|
// remove newlines from short
|
|
|
|
|
short = short.replace(/\n/g, ""); |
|
|
|
|
const dateStr = eventdefsChildren[i].attr("date").value(); |
|
|
|
|
const timeStr = eventdefsChildren[i].attr("time").value(); |
|
|
|
|
const dateStr = eventItem.attr("date").value(); |
|
|
|
|
const timeStr = eventItem.attr("time").value(); |
|
|
|
|
const date = parseTime(dateStr, timeStr); |
|
|
|
|
const location = eventdefsChildren[i].attr("room").value(); |
|
|
|
|
currentTerm = getTerm(date); |
|
|
|
|
const location = eventItem.attr("room").value(); |
|
|
|
|
const online = location.toLowerCase() === "online" ? true : false; |
|
|
|
|
let abstract = short; |
|
|
|
|
if (eventdefsChildren[i].get(".//abstract") !== undefined) { |
|
|
|
|
const abstractNodes = eventdefsChildren[i] |
|
|
|
|
.get(".//abstract") |
|
|
|
|
.childNodes(); |
|
|
|
|
if (eventItem.get(".//abstract") !== undefined) { |
|
|
|
|
const abstractNodes = eventItem.get(".//abstract").childNodes(); |
|
|
|
|
abstract = converterShowdown.makeMarkdown( |
|
|
|
|
nodeChildrenToString(abstractNodes) |
|
|
|
|
); |
|
|
|
|
abstract = abstract.replace(/<br>/g, "\n"); |
|
|
|
|
} |
|
|
|
|
let registerLink = ""; |
|
|
|
|
// detects a link in markdown such as [CSC Club Website](<http://csclub.uwaterloo.ca//>)
|
|
|
|
|
const markdownLinkDetectRegex = /(?<=\[(.*)\]\(<)(.*)(?=>\))/; |
|
|
|
|
if (markdownLinkDetectRegex.exec(abstract)) { |
|
|
|
|
registerLink = `\n registerLink: "${ |
|
|
|
|
markdownLinkDetectRegex.exec(abstract)[0] |
|
|
|
|
}",`;
|
|
|
|
|
} |
|
|
|
|
const mdx = `export const metadata = {
|
|
|
|
|
name: "${title}", |
|
|
|
|
short: "${short}", |
|
|
|
|
date: new Date("${date.toString()}"), |
|
|
|
|
online: ${online}, |
|
|
|
|
location: "${location}",${registerLink} |
|
|
|
|
location: "${location}", |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
${abstract}`;
|
|
|
|
@ -127,5 +113,5 @@ ${abstract}`; |
|
|
|
|
} |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|