mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-15 09:12:24 +02:00
refactor(content-blog): replace reading-time
with Intl.Segmenter
API (#11138)
Co-authored-by: sebastien <lorber.sebastien@gmail.com>
This commit is contained in:
parent
c419d7ec88
commit
9f6360ba82
13 changed files with 96 additions and 69 deletions
|
@ -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;
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue