Reduce code complexity by using xml-js

mdx-conversion
Jared He 2 years ago
parent b5981ecab1
commit b22c7058a5
  1. 31
      scripts/mdx-scripts/CSC-BOT-&-Game-Night.mdx
  2. 19
      scripts/mdx-scripts/CSC-x-SE-Soc--Interview-Prep.mdx
  3. 68
      scripts/mdx-scripts/event-conversion.js
  4. 7
      scripts/mdx-scripts/event-test.xml
  5. 33
      scripts/mdx-scripts/package-lock.json
  6. 4
      scripts/mdx-scripts/package.json

@ -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
<!-- -->

@ -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>)!

@ -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 dateRegex = /(?<=<eventitem(.*)date=")(.|\n)*?(?="(.*)>)/g;
const timeRegex = /(?<=<eventitem(.*)time=")(.|\n)*?(?="(.*)>)/g;
const roomRegex = /(?<=<eventitem(.*)room=")(.|\n)*?(?="(.*)>)/g;
const titleRegex = /(?<=<eventitem(.*)title=")(.|\n)*?(?="(.*)>)/g;
let eventItems = [];
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 js = xmlJs.xml2js(XML);
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
const abstract = useShowdown(
xmlJs.js2xml(js.elements[0].elements[i].elements[1])
);
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) {

@ -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>
@ -33,4 +35,5 @@
<li>List</li>
</ol>
</abstract>
</eventitem>
</eventitem>
</eventdefs>

@ -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",

@ -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"
}
}

Loading…
Cancel
Save