UNPKG

course-renderer

Version:

Manages CA School Courses file system storage and HTML conversion

47 lines (46 loc) 1.71 kB
"use strict"; /** * @module post-renderer */ Object.defineProperty(exports, "__esModule", { value: true }); const path = require("path"); const path_sanitizer_1 = require("./path-sanitizer"); const answer_generator_1 = require("./answer-generator"); const md_inline_1 = require("./md-inline"); const anchor_1 = require("./anchor"); const through = require('through2'); /** * post-renderer - post rendering hooks. This allows us to cleanup what the output of the MD render. * The current hooks are * - pathSanitize - this hook hide the internal file structure * - answerGenerator - Generates a question ID for each question and generates an answer key file for the whole courseName */ module.exports = (options) => (through.obj((file, i, cb) => { const pathSep = path.sep; const chapter = file.path .replace(`${options.dest}${pathSep}`, ''); const course = options.course; try { let includeList = false; if (/\.facts.json$/.test(file.path)) { includeList = true; } let content = JSON.parse(file.contents.toString()); content = md_inline_1.transform(content, includeList); content = anchor_1.anchor(content); content = path_sanitizer_1.pathSanitize(content, course, chapter); answer_generator_1.answerGenerator(content, options.dest, options.sourceCourse, (err, data) => { if (err) { cb(err); } else { file.contents = new Buffer(JSON.stringify(data, null, 4)); cb(null, file); } }); } catch (e) { cb(e); return; } }));