Reduce code complexity by using xml-js

This commit is contained in:
Jared He 2021-06-13 11:26:10 -05:00
parent b5981ecab1
commit b22c7058a5
6 changed files with 112 additions and 44 deletions

View File

@ -0,0 +1,31 @@
export const metadata = {
name: "CSC BOT & Game Night",
short: "Learn about our plans for the term and play some games with us.",
date: "Mon May 17 2021 20:00:00 GMT-0500 (Central Daylight Time)",
online: TODO FIX THIS,
location: "Online",
registerLink: TODO FIX THIS,
}
Kick off your Spring term with CSC! Come join us on Discord to learn more about what we'll be up to this term and how you can participate!
Afterwards, stick around for a relaxing and fun game night. See you there!
# Here, I am also testing with
## Many headings, as well as **bold text** and *italics*
#### More headings
- One
- Unordered
- List
<!-- -->
1. One
2. Ordered
3. List
<!-- -->

View File

@ -0,0 +1,19 @@
export const metadata = {
name: "CSC x SE Soc: Interview Prep",
short: "CSC and SE Soc are hosting an Interview Prep Workshop next week! Join Kristy Gao and Bimesh De Silva as they review the interview process, from behavioural to technical interviews. They'll finish off with live mock interviews, and the event will be held on Twitch (https://www.twitch.tv/uwcsclub).",
date: "Mon May 24 2021 19:00:00 GMT-0500 (Central Daylight Time)",
online: TODO FIX THIS,
location: "Online",
registerLink: TODO FIX THIS,
}
Browsing through your unsolved Leetcode problems? Flipping open CTCI for the first time? Have no clue what to expect from a technical interview or just need an interview refresher?
We've got you covered at our CSC x SE Soc Interview Prep Workshop this Monday, May 24th from 7:00-8:30pm ET! Live-streamed on Twitch, Kristy Gao and Bimesh De Silva will be walking through important aspects of the interview process from coding challenges to behavioural interviews to algorithmic interviews, go through some live mock interviews, and share their tips and techniques along the way!
Registration isn't required, we'll just be sending you an email reminder, as well as inviting you to our calendar event!
The event will be hosted on Twitch at [https://www.twitch.tv/uwcsclub](<https://www.twitch.tv/uwcsclub>)
Register at [http://bit.ly/csc-sesoc-interview-prep-signup](<http://bit.ly/csc-sesoc-interview-prep-signup>)!

View File

@ -1,22 +1,15 @@
const fs = require("fs");
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const { window } = new JSDOM('')
global.window = window
const { window } = new JSDOM("");
global.window = window;
var showdown = require("showdown");
const converterShowdown = new showdown.Converter();
const xmlJs = require("xml-js");
const useShowdown = (HTML) => {
return converterShowdown.makeMarkdown(HTML)
}
const Breakdance = require("breakdance");
const converterBreakdance = new Breakdance();
const useBreakdance = (HTML) => {
return converterBreakdance.render(HTML)
}
return converterShowdown.makeMarkdown(HTML);
};
fs.readFile("./event-test.xml", "utf8", (err, data) => {
if (err) {
@ -27,37 +20,26 @@ fs.readFile("./event-test.xml", "utf8", (err, data) => {
});
const parseXML = (XML) => {
const eventItemRegex = /<eventitem.*>(.|\n)*?<\/eventitem>/g;
const shortRegex = /(?<=<short>)(.|\n)*?(?=<\/short>)/g;
const abstractRegex = /(?<=<abstract>)(.|\n)*?(?=<\/abstract>)/g;
const js = xmlJs.xml2js(XML);
const dateRegex = /(?<=<eventitem(.*)date=")(.|\n)*?(?="(.*)>)/g;
const timeRegex = /(?<=<eventitem(.*)time=")(.|\n)*?(?="(.*)>)/g;
const roomRegex = /(?<=<eventitem(.*)room=")(.|\n)*?(?="(.*)>)/g;
const titleRegex = /(?<=<eventitem(.*)title=")(.|\n)*?(?="(.*)>)/g;
for (let i = 0; i < js.elements[0].elements.length; ++i) {
const title = js.elements[0].elements[i].attributes.title;
let short = useShowdown(
xmlJs.js2xml(js.elements[0].elements[i].elements[0])
);
short = short.replace(/\n+$/, "");
const dateStr = js.elements[0].elements[i].attributes.date;
const timeStr = js.elements[0].elements[i].attributes.time;
const date = new Date(`${dateStr} ${timeStr} EST`); // need to add EST
const room = js.elements[0].elements[i].attributes.room;
// const online
// const location
let eventItems = [];
const abstract = useShowdown(
xmlJs.js2xml(js.elements[0].elements[i].elements[1])
);
while ((eventItems = eventItemRegex.exec(XML)) !== null) {
dateRegex.lastIndex = 0;
timeRegex.lastIndex = 0;
roomRegex.lastIndex = 0;
titleRegex.lastIndex = 0;
shortRegex.lastIndex = 0;
abstractRegex.lastIndex = 0;
const eventItem = eventItems[0];
const dateStr = dateRegex.exec(eventItem);
const timeStr = timeRegex.exec(eventItem);
const title = titleRegex.exec(eventItem)[0];
const short = shortRegex.exec(eventItem)[0];
// const short = shortRegex.exec(eventItem)[0]; if we want shorts in mdx
const room = roomRegex.exec(eventItem)[0];
const date = new Date(`${dateStr[0]} ${timeStr[0]}`);
const abstract = useShowdown(abstractRegex.exec(eventItem)[0]);
const mdx = `export const metadata = {\n name: ${title},\n short: ${short},\n date: ${date},\n online: TODO FIX THIS,\n location: ${room},\n registerLink: TODO FIX THIS,\n}\n\n${abstract}`;
const mdx = `export const metadata = {\n name: "${title}",\n short: "${short}",\n date: "${date}",\n online: TODO FIX THIS,\n location: "${room}",\n registerLink: TODO FIX THIS,\n}\n\n${abstract}`;
const mdxTitle = title.replace(/(\s+|:+)/g, "-");
fs.writeFile(`${mdxTitle}.mdx`, mdx, function (err) {

View File

@ -1,4 +1,6 @@
<eventitem date="2021-05-24" time="07:00 PM" room="Online" title="CSC x SE Soc: Interview Prep">
<eventdefs>
<eventitem date="2021-05-24" time="7:00:00 PM" room="Online" title="CSC x SE Soc: Interview Prep">
<short>
<p>CSC and SE Soc are hosting an Interview Prep Workshop next week! Join Kristy Gao and Bimesh De Silva as they review the interview process, from behavioural to technical interviews. They'll finish off with live mock interviews, and the event will be held on Twitch (https://www.twitch.tv/uwcsclub).</p>
</short>
@ -34,3 +36,4 @@
</ol>
</abstract>
</eventitem>
</eventdefs>

View File

@ -6,7 +6,9 @@
"": {
"dependencies": {
"breakdance": "^3.0.1",
"showdown": "^1.9.1"
"cheerio": "^0.22.0",
"showdown": "^1.9.1",
"xml-js": "^1.6.11"
}
},
"node_modules/ansi-regex": {
@ -818,6 +820,11 @@
}
]
},
"node_modules/sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
},
"node_modules/self-closing-tags": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/self-closing-tags/-/self-closing-tags-1.0.1.tgz",
@ -1278,6 +1285,17 @@
"node": ">=6"
}
},
"node_modules/xml-js": {
"version": "1.6.11",
"resolved": "https://registry.npmjs.org/xml-js/-/xml-js-1.6.11.tgz",
"integrity": "sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==",
"dependencies": {
"sax": "^1.2.4"
},
"bin": {
"xml-js": "bin/cli.js"
}
},
"node_modules/y18n": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",
@ -1947,6 +1965,11 @@
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ=="
},
"sax": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz",
"integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
},
"self-closing-tags": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/self-closing-tags/-/self-closing-tags-1.0.1.tgz",
@ -2306,6 +2329,14 @@
"strip-ansi": "^5.0.0"
}
},
"xml-js": {
"version": "1.6.11",
"resolved": "https://registry.npmjs.org/xml-js/-/xml-js-1.6.11.tgz",
"integrity": "sha512-7rVi2KMfwfWFl+GpPg6m80IVMWXLRjO+PxTq7V2CDhoGak0wzYzFgUY2m4XJ47OGdXd8eLE8EmwfAmdjw7lC1g==",
"requires": {
"sax": "^1.2.4"
}
},
"y18n": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz",

View File

@ -1,6 +1,8 @@
{
"dependencies": {
"breakdance": "^3.0.1",
"showdown": "^1.9.1"
"cheerio": "^0.22.0",
"showdown": "^1.9.1",
"xml-js": "^1.6.11"
}
}