Add direct links to categories

This commit is contained in:
Knoch 2019-09-04 20:07:09 +02:00
parent 331e4c206a
commit 3ccff54fa4

View File

@ -33,36 +33,41 @@ function processInput (section, chair, category, audience, abbreviation,
* The resulting markup is written to ./result.txt. * The resulting markup is written to ./result.txt.
*/ */
function createHTML() { function createHTML() {
let resultString = ''
const recordsBySection = groupBy(records, x => x.section) 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']) sections.forEach(function (section) {
.forEach(function (section) { resultString += `<a
if (recordsBySection.has(section)) { style="display: inline-block; padding: .5rem; border: 1px solid lightgray; border-radius: 2px; box-shadow: 0px 1px 2px rgba(0,0,0,0.3);"
resultString += `<h1>${section}</h1>\n` href="#${convertToID(section)}">${section}</a>\n`
})
let recordsByChair = groupBy(recordsBySection.get(section), x => x.chair) sections.forEach(function (section) {
let chairs = [...recordsByChair.keys()].sort() resultString += `<h1 id="${convertToID(section)}">${section}</h1>\n`
chairs.forEach(function (chair) {
resultString += `<h3>${chair}</h3>\n`
let recordsByCategory = groupBy(recordsByChair.get(chair), x => x.category) let recordsByChair = groupBy(recordsBySection.get(section), x => x.chair)
let categories = [...recordsByCategory.keys()].sort() let chairs = [...recordsByChair.keys()].sort()
categories.forEach(function (category) { chairs.forEach(function (chair) {
resultString += `<h3>${chair}</h3>\n`
recordsByCategory.get(category).forEach(function (cur) { let recordsByCategory = groupBy(recordsByChair.get(chair), x => x.category)
resultString += `<div style="border: 1px solid lightgray; box-shadow: 0px 2px 4px rgba(0,0,0,0.3); padding: 1rem; margin-bottom: 1rem;"><h5>${category}` let categories = [...recordsByCategory.keys()].sort()
resultString += cur.abbreviation ? ` ${cur.abbreviation}` : '' categories.forEach(function (category) {
resultString += `: ${cur.topic} (${cur.audience})</h5>\n`
resultString += `<p><strong>Kurzbeschreibung:</strong> ${cur.description}</p>\n` recordsByCategory.get(category).forEach(function (cur) {
resultString += `<p><strong>Anmeldefrist</strong>: ${cur.deadline}</p>\n` resultString += `<div style="border: 1px solid lightgray; box-shadow: 0px 2px 4px rgba(0,0,0,0.3); padding: 1rem; margin-bottom: 1rem;"><h5>${category}`
resultString += `<p><strong>Weitere Informationen und Anmeldung:</strong> ` resultString += cur.abbreviation ? ` ${cur.abbreviation}` : ''
resultString += cur.link.startsWith('http') ? `<br/><a href="${cur.link}">${cur.link}</a>` : cur.link resultString += `: ${cur.topic} (${cur.audience})</h5>\n`
resultString += `</p></div>\n` resultString += `<p><strong>Kurzbeschreibung:</strong> ${cur.description}</p>\n`
}) resultString += `<p><strong>Anmeldefrist</strong>: ${cur.deadline}</p>\n`
}) resultString += `<p><strong>Weitere Informationen und Anmeldung:</strong> `
resultString += cur.link.startsWith('http') ? `<br/><a href="${cur.link}">${cur.link}</a>` : cur.link
resultString += `</p></div>\n`
}) })
} })
})
}) })
fs.writeFileSync('result.txt', resultString) fs.writeFileSync('result.txt', resultString)
@ -93,3 +98,10 @@ function groupBy(list, keyGetter) {
}); });
return map; return map;
} }
/**
* Convert to ID-compatible string by replacing non-word characters with dashes.
*/
function convertToID(string) {
return string.replace(/\W/g, '-')
}