Skip to content

Commit f5cf183

Browse files
committed
feat: add note with full course info, ref #115
1 parent e716163 commit f5cf183

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

collection-export/syllabus.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,25 @@ export function addOriginInfo(doc) {
281281
* @returns {Document} transformed document
282282
*/
283283
export function addFullCourseInfoNote(doc) {
284+
const semester = safeSelectFirst("//local/courseInfo/semester", doc)
285+
const division = safeSelectFirst("//local/division", doc)
286+
const department = safeSelectFirst("//local/department", doc)
287+
const courseNumber = safeSelectFirst("//local/courseInfo/courseName", doc)
288+
const courseTitle = safeSelectFirst("//local/courseInfo/course", doc)
289+
const section = safeSelectFirst("//local/courseInfo/section", doc)
290+
const faculty = safeSelectFirst("//local/courseInfo/faculty", doc)
291+
292+
const infoParts = [semester, division, department, courseNumber, courseTitle, section, faculty]
293+
.filter(el => hasDirectTextContent(el))
294+
.map(el => el.textContent.trim())
295+
296+
if (infoParts.length > 0) {
297+
const mods = safeSelectFirst("//mods", doc)
298+
const note = createElement(doc, 'note')
299+
note.textContent = infoParts.join(' | ')
300+
mods.appendChild(note)
301+
}
302+
284303
return doc
285304
}
286305

collection-export/syllabus.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,19 @@ describe('addOriginInfo', () => {
281281
})
282282
})
283283

284+
describe('addFullCourseInfoNote', () => {
285+
it('should add a note with the full course info', async () => {
286+
const courseName = 'FASHN-360'
287+
const courseTitle = 'Media History'
288+
const semester = 'Fall 2026'
289+
const inputXML = x(`<local><courseInfo><courseName>${courseName}</courseName><course>${courseTitle}</course><semester>${semester}</semester></courseInfo></local>`)
290+
const result = convertSyllabusXMLtoMODS(inputXML)
291+
const note = xpath.select1('//mods/note[@type="full course info"]', result)
292+
assert.ok(note)
293+
assert.strictEqual(note.textContent, `${semester} | ${courseName} | ${courseTitle}`)
294+
})
295+
})
296+
284297
describe('convertSyllabusXMLtoMODS', () => {
285298
it('should include the MODS namespaces & attributes', async () => {
286299
// <mods> must be non-empty or it is dropped

0 commit comments

Comments
 (0)