Repository: facebook/docusaurus
File: packages/docusaurus-plugin-content-blog/src/index.ts (TypeScript)

Code before:

      const baseBlogPermalink = normalizeUrl([baseUrl, routeBasePath]);

      // Create routes for blog entries.
      await Promise.all(
        blogPosts.map(async (blogPost) => {
          const {id, metadata} = blogPost;
          await createData(
            // Note that this created data path must be in sync with
            // metadataPath provided to mdx-loader.
            `${docuHash(metadata.source)}.json`,
            JSON.stringify(metadata, null, 2),
          );

          const blogMetadataPath = await createData(
            `${docuHash(`${metadata.source}-blogMetadata`)}.json`,
            JSON.stringify(
              {
                baseBlogPermalink,
                blogTitle,
              },
              null,
              2,
            ),
          );

          addRoute({
            path: metadata.permalink,
            component: blogPostComponent,
            exact: true,
            modules: {
              sidebar: aliasedSource(sidebarProp),
              content: metadata.source,
              blogMetadata: aliasedSource(blogMetadataPath),
            },
          });

          blogItemsToMetadata[id] = metadata;
        }),
      );

      // Create routes for blog's paginated list entries.
      await Promise.all(
        blogListPaginated.map(async (listPage) => {
          const {metadata, items} = listPage;
          const {permalink} = metadata;
          const pageMetadataPath = await createData(
            `${docuHash(permalink)}.json`,
            JSON.stringify(metadata, null, 2),
          );


Review comment (performance):
we'd want to create one bundle/path and reuse it for all blog posts here

since it's always the same data it's not worth it to create one new bundle per blog post: we can optimize and make it fetch the bundle only once for all the blog posts

Code after:
      );

      const blogMetadata: BlogMetadata = {
        blogBasePath: normalizeUrl([baseUrl, routeBasePath]),
        blogTitle,
      };
      const blogMetadataPath = await createData(
        `blogMetadata-${pluginId}.json`,
        JSON.stringify(blogMetadata, null, 2),
      );

      // Create routes for blog entries.
      await Promise.all(
        blogPosts.map(async (blogPost) => {
          const {id, metadata} = blogPost;
          await createData(
            // Note that this created data path must be in sync with
            // metadataPath provided to mdx-loader.
            `${docuHash(metadata.source)}.json`,
            JSON.stringify(metadata, null, 2),
          );

          addRoute({
            path: metadata.permalink,
            component: blogPostComponent,
            exact: true,
            modules: {
              sidebar: aliasedSource(sidebarProp),
              content: metadata.source,
            },
            context: {
              blogMetadata: aliasedSource(blogMetadataPath),
            },
          });

          blogItemsToMetadata[id] = metadata;
        }),
      );

      // Create routes for blog's paginated list entries.
      await Promise.all(
        blogListPaginated.map(async (listPage) => {
          const {metadata, items} = listPage;
          const {permalink} = metadata;
          const pageMetadataPath = await createData(
            `${docuHash(permalink)}.json`,
            JSON.stringify(metadata, null, 2),
          );

          addRoute({
            path: permalink,