refactor(content-blog): replace reading-time with Intl.Segmenter API (#11138)

Co-authored-by: sebastien <lorber.sebastien@gmail.com>
This commit is contained in:
Shreedhar Bhat 2025-05-15 16:52:00 +05:30 committed by GitHub
parent c419d7ec88
commit 9f6360ba82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 96 additions and 69 deletions

View file

@ -387,15 +387,10 @@ declare module '@docusaurus/plugin-content-blog' {
};
/**
* Duplicate from ngryman/reading-time to keep stability of API.
* Options for reading time calculation using Intl.Segmenter.
*/
type ReadingTimeOptions = {
wordsPerMinute?: number;
/**
* @param char The character to be matched.
* @returns `true` if this character is a word bound.
*/
wordBound?: (char: string) => boolean;
};
/**
@ -405,24 +400,22 @@ declare module '@docusaurus/plugin-content-blog' {
export type ReadingTimeFunction = (params: {
/** Markdown content. */
content: string;
/** Locale for word segmentation. */
locale: string;
/** Front matter. */
frontMatter?: BlogPostFrontMatter & {[key: string]: unknown};
/** Options accepted by ngryman/reading-time. */
/** Options for reading time calculation. */
options?: ReadingTimeOptions;
}) => number;
/**
* @returns The reading time directly plugged into metadata. `undefined` to
* hide reading time for a specific post.
* @returns The reading time directly plugged into metadata.
* `undefined` to hide reading time for a specific post.
*/
export type ReadingTimeFunctionOption = (
/**
* The `options` is not provided by the caller; the user can inject their
* own option values into `defaultReadingTime`
*/
params: Required<Omit<Parameters<ReadingTimeFunction>[0], 'options'>> & {
/**
* The default reading time implementation from ngryman/reading-time.
* The default reading time implementation.
*/
defaultReadingTime: ReadingTimeFunction;
},