소스 검색

create remark instance before pdf conversion stream starts

Futa Arai 1 년 전
부모
커밋
4bae4435cf
1개의 변경된 파일5개의 추가작업 그리고 4개의 파일을 삭제
  1. 5 4
      apps/app/src/features/page-bulk-export/server/service/page-bulk-export/index.ts

+ 5 - 4
apps/app/src/features/page-bulk-export/server/service/page-bulk-export/index.ts

@@ -297,6 +297,8 @@ class PageBulkExportService implements IPageBulkExportService {
   private getPageWritable(pageBulkExportJob: PageBulkExportJobDocument): Writable {
     const isHtmlPath = pageBulkExportJob.format === PageBulkExportFormat.pdf;
     const outputDir = this.getTmpOutputDir(pageBulkExportJob, isHtmlPath);
+    // define before the stream starts to avoid creating multiple instances
+    const remarkHtml = remark().use(html);
     return new Writable({
       objectMode: true,
       write: async(page: PageBulkExportPageSnapshotDocument, encoding, callback) => {
@@ -315,7 +317,7 @@ class PageBulkExportService implements IPageBulkExportService {
               await fs.promises.writeFile(fileOutputPath, markdownBody);
             }
             else {
-              const htmlString = await this.convertMdToHtml(markdownBody);
+              const htmlString = await this.convertMdToHtml(markdownBody, remarkHtml);
               await fs.promises.writeFile(fileOutputPath, htmlString);
             }
             pageBulkExportJob.lastExportedPagePath = page.path;
@@ -334,9 +336,8 @@ class PageBulkExportService implements IPageBulkExportService {
     });
   }
 
-  private async convertMdToHtml(md: string): Promise<string> {
-    const htmlString = (await remark()
-      .use(html)
+  private async convertMdToHtml(md: string, remarkHtml): Promise<string> {
+    const htmlString = (await remarkHtml
       .process(md))
       .toString();