const download_lecture_article = async (content, chapter_path) => { if (content['asset']['asset_type'] !== 'Article') { return; } const {object_index, supplementary_assets, title, asset} = content; const article_response_index = `${object_index}`.padStart(3, '0'); if (supplementary_assets.length > 0) { await download_supplementary_assets( supplementary_assets, chapter_path, article_response_index ); } const article_name = safe_name(`${article_response_index} ${title}.html`); const article_body = asset['body'].replace(/\\"/g, '"').replace(/\n+/g, '<br>'); const new_article_body = `<html><head><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/components/image.min.css"></head><body><div class="container"><div class="row"><div class="col-md-10 col-md-offset-1 ui image"><p class="lead">${article_body}</p></div></div></div></body></html>`; const article_path = path.join(chapter_path, article_name); fs.writeFileSync(article_path, new_article_body); console.log(`\n ${magenta().inverse(' Lecture ')} ${article_name} ${green_bg('Done')}`); }
return console.log(`\n ${magenta().inverse(' Lecture ')} ${lecture_name} ${yellow('(already downloaded)')}`); lecture_url, lecture_path ).catch(error => { process.stderr.write(`\n ${magenta().inverse(' Lecture ')} ${lecture_name}`); console.log(`\n ${magenta().inverse(' Lecture ')} ${lecture_name} ${green_bg('Done')}`);