Skip to content

Commit

Permalink
refactor(v2): convert synchronous file write to asynchronous (#2936)
Browse files Browse the repository at this point in the history
* perf(v2): convert synchronous filewrite to asynchronous in feed file generate

This looks like should return a Promise list , other than a sync io operation

* perf(v2): convert synchronous filewrite to asynchronous in sitemap generate

* perf(v2): convert  Promise style to async/await style

for consistency
  • Loading branch information
moonrailgun committed Jun 15, 2020
1 parent 0c92f5a commit 930222e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-blog/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,15 @@ export default function pluginContentBlog(
const feedTypes = getFeedTypes(options.feedOptions?.type);

await Promise.all(
feedTypes.map((feedType) => {
feedTypes.map(async (feedType) => {
const feedPath = path.join(
outDir,
options.routeBasePath,
`${feedType}.xml`,
);
const feedContent = feedType === 'rss' ? feed.rss2() : feed.atom1();
try {
fs.writeFileSync(feedPath, feedContent);
await fs.outputFile(feedPath, feedContent);
} catch (err) {
throw new Error(`Generating ${feedType} feed failed: ${err}`);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-sitemap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

import fs from 'fs';
import fs from 'fs-extra';
import path from 'path';
import {PluginOptions} from './types';
import createSitemap from './createSitemap';
Expand Down Expand Up @@ -37,7 +37,7 @@ export default function pluginSitemap(
// Write sitemap file.
const sitemapPath = path.join(outDir, 'sitemap.xml');
try {
fs.writeFileSync(sitemapPath, generatedSitemap);
await fs.outputFile(sitemapPath, generatedSitemap);
} catch (err) {
throw new Error(`Sitemap error: ${err}`);
}
Expand Down

0 comments on commit 930222e

Please sign in to comment.