From b22c7058a5a8a58558a4541119083d3b3c3c6f1b Mon Sep 17 00:00:00 2001 From: Jared He <66887902+jaredjhe@users.noreply.github.com> Date: Sun, 13 Jun 2021 11:26:10 -0500 Subject: [PATCH] Reduce code complexity by using xml-js --- scripts/mdx-scripts/CSC-BOT-&-Game-Night.mdx | 31 ++++++++++ .../CSC-x-SE-Soc--Interview-Prep.mdx | 19 ++++++ scripts/mdx-scripts/event-conversion.js | 62 +++++++------------ scripts/mdx-scripts/event-test.xml | 7 ++- scripts/mdx-scripts/package-lock.json | 33 +++++++++- scripts/mdx-scripts/package.json | 4 +- 6 files changed, 112 insertions(+), 44 deletions(-) create mode 100644 scripts/mdx-scripts/CSC-BOT-&-Game-Night.mdx create mode 100644 scripts/mdx-scripts/CSC-x-SE-Soc--Interview-Prep.mdx diff --git a/scripts/mdx-scripts/CSC-BOT-&-Game-Night.mdx b/scripts/mdx-scripts/CSC-BOT-&-Game-Night.mdx new file mode 100644 index 0000000..4c90baf --- /dev/null +++ b/scripts/mdx-scripts/CSC-BOT-&-Game-Night.mdx @@ -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 + + + diff --git a/scripts/mdx-scripts/CSC-x-SE-Soc--Interview-Prep.mdx b/scripts/mdx-scripts/CSC-x-SE-Soc--Interview-Prep.mdx new file mode 100644 index 0000000..7a00e99 --- /dev/null +++ b/scripts/mdx-scripts/CSC-x-SE-Soc--Interview-Prep.mdx @@ -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]() + +Register at [http://bit.ly/csc-sesoc-interview-prep-signup]()! + diff --git a/scripts/mdx-scripts/event-conversion.js b/scripts/mdx-scripts/event-conversion.js index d9a91b7..0e34107 100644 --- a/scripts/mdx-scripts/event-conversion.js +++ b/scripts/mdx-scripts/event-conversion.js @@ -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 = /(.|\n)*?<\/eventitem>/g; - const shortRegex = /(?<=)(.|\n)*?(?=<\/short>)/g; - const abstractRegex = /(?<=)(.|\n)*?(?=<\/abstract>)/g; + const js = xmlJs.xml2js(XML); - const dateRegex = /(?<=)/g; - const timeRegex = /(?<=)/g; - const roomRegex = /(?<=)/g; - const titleRegex = /(?<=)/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) { diff --git a/scripts/mdx-scripts/event-test.xml b/scripts/mdx-scripts/event-test.xml index 5c26e05..7ae7c97 100644 --- a/scripts/mdx-scripts/event-test.xml +++ b/scripts/mdx-scripts/event-test.xml @@ -1,4 +1,6 @@ - + + +

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).

@@ -33,4 +35,5 @@
  • List
  • - \ No newline at end of file + + \ No newline at end of file diff --git a/scripts/mdx-scripts/package-lock.json b/scripts/mdx-scripts/package-lock.json index a4a418c..8738c9c 100644 --- a/scripts/mdx-scripts/package-lock.json +++ b/scripts/mdx-scripts/package-lock.json @@ -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", diff --git a/scripts/mdx-scripts/package.json b/scripts/mdx-scripts/package.json index 3efe112..a76ff11 100644 --- a/scripts/mdx-scripts/package.json +++ b/scripts/mdx-scripts/package.json @@ -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" } }