mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-18 11:36:53 +02:00
perf(v2): improve blog mdx-loader and postcss loader (#4355)
* perf(v2): improve blog mdx-loader and postcss loader * Adjust advanced preset settings * Update css-loader
This commit is contained in:
parent
620b8f8fd7
commit
36dc206888
8 changed files with 80 additions and 32 deletions
|
@ -12,6 +12,7 @@ import path from 'path';
|
|||
import {resolve} from 'url';
|
||||
import readingTime from 'reading-time';
|
||||
import {Feed} from 'feed';
|
||||
import {keyBy} from 'lodash';
|
||||
import {
|
||||
PluginOptions,
|
||||
BlogPost,
|
||||
|
@ -30,12 +31,17 @@ import {
|
|||
getDateTimeFormat,
|
||||
} from '@docusaurus/utils';
|
||||
import {LoadContext} from '@docusaurus/types';
|
||||
import {keyBy} from 'lodash';
|
||||
|
||||
export function truncate(fileString: string, truncateMarker: RegExp): string {
|
||||
return fileString.split(truncateMarker, 1).shift()!;
|
||||
}
|
||||
|
||||
export function getPostsBySource(
|
||||
blogPosts: BlogPost[],
|
||||
): Record<string, BlogPost> {
|
||||
return keyBy(blogPosts, (item) => item.metadata.source);
|
||||
}
|
||||
|
||||
// YYYY-MM-DD-{name}.mdx?
|
||||
// Prefer named capture, but older Node versions do not support it.
|
||||
const FILENAME_PATTERN = /^(\d{4}-\d{1,2}-\d{1,2})-?(.*?).mdx?$/;
|
||||
|
@ -247,7 +253,7 @@ export type LinkifyParams = {
|
|||
fileContent: string;
|
||||
} & Pick<
|
||||
BlogMarkdownLoaderOptions,
|
||||
'blogPosts' | 'siteDir' | 'contentPaths' | 'onBrokenMarkdownLink'
|
||||
'blogPostsBySource' | 'siteDir' | 'contentPaths' | 'onBrokenMarkdownLink'
|
||||
>;
|
||||
|
||||
export function linkify({
|
||||
|
@ -255,18 +261,12 @@ export function linkify({
|
|||
contentPaths,
|
||||
fileContent,
|
||||
siteDir,
|
||||
blogPosts,
|
||||
blogPostsBySource,
|
||||
onBrokenMarkdownLink,
|
||||
}: LinkifyParams): string {
|
||||
// TODO temporary, should consider the file being in localized folder!
|
||||
const folderPath = contentPaths.contentPath;
|
||||
|
||||
// TODO perf refactor: do this earlier (once for all md files, not per file)
|
||||
const blogPostsBySource: Record<string, BlogPost> = keyBy(
|
||||
blogPosts,
|
||||
(item) => item.metadata.source,
|
||||
);
|
||||
|
||||
let fencedBlock = false;
|
||||
const lines = fileContent.split('\n').map((line) => {
|
||||
if (line.trim().startsWith('```')) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue