mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-20 12:37:01 +02:00
refactor(v2): convert synchronous file write to asynchronous (#2936)
* 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
This commit is contained in:
parent
0c92f5aacd
commit
930222ea87
2 changed files with 4 additions and 4 deletions
|
@ -441,7 +441,7 @@ export default function pluginContentBlog(
|
||||||
const feedTypes = getFeedTypes(options.feedOptions?.type);
|
const feedTypes = getFeedTypes(options.feedOptions?.type);
|
||||||
|
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
feedTypes.map((feedType) => {
|
feedTypes.map(async (feedType) => {
|
||||||
const feedPath = path.join(
|
const feedPath = path.join(
|
||||||
outDir,
|
outDir,
|
||||||
options.routeBasePath,
|
options.routeBasePath,
|
||||||
|
@ -449,7 +449,7 @@ export default function pluginContentBlog(
|
||||||
);
|
);
|
||||||
const feedContent = feedType === 'rss' ? feed.rss2() : feed.atom1();
|
const feedContent = feedType === 'rss' ? feed.rss2() : feed.atom1();
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(feedPath, feedContent);
|
await fs.outputFile(feedPath, feedContent);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(`Generating ${feedType} feed failed: ${err}`);
|
throw new Error(`Generating ${feedType} feed failed: ${err}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import fs from 'fs';
|
import fs from 'fs-extra';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import {PluginOptions} from './types';
|
import {PluginOptions} from './types';
|
||||||
import createSitemap from './createSitemap';
|
import createSitemap from './createSitemap';
|
||||||
|
@ -37,7 +37,7 @@ export default function pluginSitemap(
|
||||||
// Write sitemap file.
|
// Write sitemap file.
|
||||||
const sitemapPath = path.join(outDir, 'sitemap.xml');
|
const sitemapPath = path.join(outDir, 'sitemap.xml');
|
||||||
try {
|
try {
|
||||||
fs.writeFileSync(sitemapPath, generatedSitemap);
|
await fs.outputFile(sitemapPath, generatedSitemap);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(`Sitemap error: ${err}`);
|
throw new Error(`Sitemap error: ${err}`);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue