mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
feat(content-blog): new readingTime plugin option (#5702)
This commit is contained in:
parent
92002b6bd3
commit
9ad6de2b85
8 changed files with 179 additions and 1 deletions
|
@ -16,6 +16,7 @@ import {
|
|||
BlogContentPaths,
|
||||
BlogMarkdownLoaderOptions,
|
||||
BlogTags,
|
||||
ReadingTimeFunction,
|
||||
} from './types';
|
||||
import {
|
||||
parseMarkdownFile,
|
||||
|
@ -111,6 +112,10 @@ async function parseBlogPostMarkdownFile(blogSourceAbsolute: string) {
|
|||
};
|
||||
}
|
||||
|
||||
const defaultReadingTime: ReadingTimeFunction = ({content, options}) => {
|
||||
return readingTime(content, options).minutes;
|
||||
};
|
||||
|
||||
async function processBlogSourceFile(
|
||||
blogSourceRelative: string,
|
||||
contentPaths: BlogContentPaths,
|
||||
|
@ -227,7 +232,13 @@ async function processBlogSourceFile(
|
|||
date,
|
||||
formattedDate,
|
||||
tags: normalizeFrontMatterTags(tagsBasePath, frontMatter.tags),
|
||||
readingTime: showReadingTime ? readingTime(content).minutes : undefined,
|
||||
readingTime: showReadingTime
|
||||
? options.readingTime({
|
||||
content,
|
||||
frontMatter,
|
||||
defaultReadingTime,
|
||||
})
|
||||
: undefined,
|
||||
truncated: truncateMarker?.test(content) || false,
|
||||
authors,
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue