Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use newest unified packages specified in package.json #9488

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,11 @@
"rehype-sanitize": "^6.0.0",
"rehype-slug": "^6.0.0",
"rehype-toc": "^3.0.2",
"remark": "^13.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#9283 で追加したパッケージのため、削除して問題ない。

"remark-breaks": "^4.0.0",
"remark-directive": "^3.0.0",
"remark-frontmatter": "^5.0.0",
"remark-gfm": "^4.0.0",
"remark-html": "^11.0.0",
"remark-html": "^16.0.1",
"remark-math": "^6.0.0",
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class PageBulkExportJobCronService extends CronService implements IPageBulkExpor
await createPageSnapshotsAsync.bind(this)(user, pageBulkExportJob);
}
else if (pageBulkExportJob.status === PageBulkExportJobStatus.exporting) {
exportPagesToFsAsync.bind(this)(pageBulkExportJob);
await exportPagesToFsAsync.bind(this)(pageBulkExportJob);
}
else if (pageBulkExportJob.status === PageBulkExportJobStatus.uploading) {
compressAndUpload.bind(this)(user, pageBulkExportJob);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import fs from 'fs';
import path from 'path';
import { Writable, pipeline } from 'stream';

import { dynamicImport } from '@cspell/dynamic-import';
import { isPopulated } from '@growi/core';
import { getParentPath, normalizePath } from '@growi/core/dist/utils/path-utils';
import remark from 'remark';
import html from 'remark-html';

import type { Root } from 'mdast';
import type * as RemarkHtml from 'remark-html';
import type * as RemarkParse from 'remark-parse';
import type * as Unified from 'unified';

import { PageBulkExportFormat, PageBulkExportJobStatus } from '~/features/page-bulk-export/interfaces/page-bulk-export';

Expand All @@ -15,8 +17,8 @@ import type { PageBulkExportJobDocument } from '../../../models/page-bulk-export
import type { PageBulkExportPageSnapshotDocument } from '../../../models/page-bulk-export-page-snapshot';
import PageBulkExportPageSnapshot from '../../../models/page-bulk-export-page-snapshot';

async function convertMdToHtml(md: string, remarkHtml): Promise<string> {
const htmlString = (await remarkHtml
async function convertMdToHtml(md: string, htmlConverter: Unified.Processor<Root, undefined, undefined, Root, string>): Promise<string> {
const htmlString = (await htmlConverter
.process(md))
.toString();

Expand All @@ -26,12 +28,18 @@ async function convertMdToHtml(md: string, remarkHtml): Promise<string> {
/**
* Get a Writable that writes the page body temporarily to fs
*/
function getPageWritable(this: IPageBulkExportJobCronService, pageBulkExportJob: PageBulkExportJobDocument): Writable {
async function getPageWritable(this: IPageBulkExportJobCronService, pageBulkExportJob: PageBulkExportJobDocument): Promise<Writable> {
const unified = (await dynamicImport<typeof Unified>('unified', __dirname)).unified;
const remarkParse = (await dynamicImport<typeof RemarkParse>('remark-parse', __dirname)).default;
const remarkHtml = (await dynamicImport<typeof RemarkHtml>('remark-html', __dirname)).default;

const isHtmlPath = pageBulkExportJob.format === PageBulkExportFormat.pdf;
const format = pageBulkExportJob.format === PageBulkExportFormat.pdf ? 'html' : pageBulkExportJob.format;
const outputDir = this.getTmpOutputDir(pageBulkExportJob, isHtmlPath);
// define before the stream starts to avoid creating multiple instances
const remarkHtml = remark().use(html);
const htmlConverter = unified()
.use(remarkParse)
.use(remarkHtml);
return new Writable({
objectMode: true,
write: async(page: PageBulkExportPageSnapshotDocument, encoding, callback) => {
Expand All @@ -49,7 +57,7 @@ function getPageWritable(this: IPageBulkExportJobCronService, pageBulkExportJob:
await fs.promises.writeFile(fileOutputPath, markdownBody);
}
else {
const htmlString = await convertMdToHtml(markdownBody, remarkHtml);
const htmlString = await convertMdToHtml(markdownBody, htmlConverter);
await fs.promises.writeFile(fileOutputPath, htmlString);
}
pageBulkExportJob.lastExportedPagePath = page.path;
Expand Down Expand Up @@ -84,7 +92,7 @@ function getPageWritable(this: IPageBulkExportJobCronService, pageBulkExportJob:
* Export pages to the file system before compressing and uploading to the cloud storage.
* The export will resume from the last exported page if the process was interrupted.
*/
export function exportPagesToFsAsync(this: IPageBulkExportJobCronService, pageBulkExportJob: PageBulkExportJobDocument): void {
export async function exportPagesToFsAsync(this: IPageBulkExportJobCronService, pageBulkExportJob: PageBulkExportJobDocument): Promise<void> {
const findQuery = pageBulkExportJob.lastExportedPagePath != null ? {
pageBulkExportJob,
path: { $gt: pageBulkExportJob.lastExportedPagePath },
Expand All @@ -94,7 +102,7 @@ export function exportPagesToFsAsync(this: IPageBulkExportJobCronService, pageBu
.populate('revision').sort({ path: 1 }).lean()
.cursor({ batchSize: this.pageBatchSize });

const pagesWritable = getPageWritable.bind(this)(pageBulkExportJob);
const pagesWritable = await getPageWritable.bind(this)(pageBulkExportJob);

this.setStreamInExecution(pageBulkExportJob._id, pageSnapshotsReadable);

Expand Down
Loading
Loading