feat(content-blog): new readingTime plugin option (#5702)

This commit is contained in:
Joshua Chen 2021-10-21 21:26:10 +08:00 committed by GitHub
parent 92002b6bd3
commit 9ad6de2b85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 179 additions and 1 deletions

View file

@ -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,
},