def _render_source_files(self, course_intro: dict, course_content: list, out_dir: str, force: bool = False, **kwargs) -> None: """ 下载课程源文件 """ articles = course_content column_title = course_intro['column_title'] _out_dir = os.path.join(out_dir, column_title) if not os.path.isdir(_out_dir): os.makedirs(_out_dir) render = Render(_out_dir) # introduction if not force and os.path.isfile(os.path.join(_out_dir, '简介.html')): sys.stdout.write('{}简介 exists\n'.format(column_title)) else: render.render_article_html('简介', course_intro['column_intro'], **kwargs) sys.stdout.write('下载{}简介 done\n'.format(column_title)) # cover if not force and os.path.isfile(os.path.join(_out_dir, 'cover.jpg')): sys.stdout.write('{}封面 exists\n'.format(column_title)) else: render.generate_cover_img(course_intro['column_cover']) sys.stdout.write('下载{}封面 done\n'.format(column_title)) # toc ebook_name = self._format_title(course_intro) render.render_toc_md( ebook_name, ['简介'] + [render.format_file_name(t['article_title']) for t in articles]) sys.stdout.write('下载{}目录 done\n'.format(column_title)) # articles articles = tqdm(articles) for article in articles: articles.set_description('HTML 文件下载中:{}'.format( article['article_title'][:10])) title = render.format_file_name(article['article_title']) fn = os.path.join(_out_dir, '{}.html'.format(title)) if not force and os.path.isfile(fn): continue render.render_article_html(title, article['article_content'], **kwargs)
def render(output_folder) -> Render: r = Render(output_folder) return r