diff --git a/index.js b/index.js index 066e433..5b3dafe 100644 --- a/index.js +++ b/index.js @@ -33,36 +33,41 @@ function processInput (section, chair, category, audience, abbreviation, * The resulting markup is written to ./result.txt. */ function createHTML() { - let resultString = '' const recordsBySection = groupBy(records, x => x.section) + let resultString = '' + let sections = Array.from(['Informatik', 'Angewandte Informatik', 'Wirtschaftsinformatik']) + .filter(section => recordsBySection.has(section)) - Array.from(['Informatik', 'Angewandte Informatik', 'Wirtschaftsinformatik']) - .forEach(function (section) { - if (recordsBySection.has(section)) { - resultString += `

${section}

\n` + sections.forEach(function (section) { + resultString += `${section}\n` + }) - let recordsByChair = groupBy(recordsBySection.get(section), x => x.chair) - let chairs = [...recordsByChair.keys()].sort() - chairs.forEach(function (chair) { - resultString += `

${chair}

\n` + sections.forEach(function (section) { + resultString += `

${section}

\n` - let recordsByCategory = groupBy(recordsByChair.get(chair), x => x.category) - let categories = [...recordsByCategory.keys()].sort() - categories.forEach(function (category) { + let recordsByChair = groupBy(recordsBySection.get(section), x => x.chair) + let chairs = [...recordsByChair.keys()].sort() + chairs.forEach(function (chair) { + resultString += `

${chair}

\n` - recordsByCategory.get(category).forEach(function (cur) { - resultString += `
${category}` - resultString += cur.abbreviation ? ` ${cur.abbreviation}` : '' - resultString += `: ${cur.topic} (${cur.audience})
\n` - resultString += `

Kurzbeschreibung: ${cur.description}

\n` - resultString += `

Anmeldefrist: ${cur.deadline}

\n` - resultString += `

Weitere Informationen und Anmeldung: ` - resultString += cur.link.startsWith('http') ? `
${cur.link}` : cur.link - resultString += `

\n` - }) - }) + let recordsByCategory = groupBy(recordsByChair.get(chair), x => x.category) + let categories = [...recordsByCategory.keys()].sort() + categories.forEach(function (category) { + + recordsByCategory.get(category).forEach(function (cur) { + resultString += `
${category}` + resultString += cur.abbreviation ? ` ${cur.abbreviation}` : '' + resultString += `: ${cur.topic} (${cur.audience})
\n` + resultString += `

Kurzbeschreibung: ${cur.description}

\n` + resultString += `

Anmeldefrist: ${cur.deadline}

\n` + resultString += `

Weitere Informationen und Anmeldung: ` + resultString += cur.link.startsWith('http') ? `
${cur.link}` : cur.link + resultString += `

\n` }) - } + }) + }) }) fs.writeFileSync('result.txt', resultString) @@ -93,3 +98,10 @@ function groupBy(list, keyGetter) { }); return map; } + +/** + * Convert to ID-compatible string by replacing non-word characters with dashes. + */ +function convertToID(string) { + return string.replace(/\W/g, '-') +} \ No newline at end of file