Skip to content

Commit fa90f7d

Browse files
committed
Improve docs
1 parent 67ce0e9 commit fa90f7d

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

website/docs/api/plugins/plugin-content-blog.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,14 @@ type ReadingTimeOptions = {
113113

114114
type ReadingTimeCalculator = (params: {
115115
content: string;
116+
locale: string;
116117
frontMatter?: BlogPostFrontMatter & Record<string, unknown>;
117118
options?: ReadingTimeOptions;
118119
}) => number;
119120

120121
type ReadingTimeFn = (params: {
121122
content: string;
123+
locale: string;
122124
frontMatter: BlogPostFrontMatter & Record<string, unknown>;
123125
defaultReadingTime: ReadingTimeCalculator;
124126
}) => number | undefined;

website/docs/blog.mdx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -476,8 +476,12 @@ export default {
476476
blog: {
477477
// highlight-start
478478
showReadingTime: true, // When set to false, the "x min read" won't be shown
479-
readingTime: ({content, frontMatter, defaultReadingTime}) =>
480-
defaultReadingTime({content, options: {wordsPerMinute: 300}}),
479+
readingTime: ({content, locale, frontMatter, defaultReadingTime}) =>
480+
defaultReadingTime({
481+
content,
482+
locale,
483+
options: {wordsPerMinute: 300},
484+
}),
481485
// highlight-end
482486
},
483487
},
@@ -486,7 +490,12 @@ export default {
486490
};
487491
```
488492

489-
The `readingTime` callback receives three parameters: the blog content text as a string, front matter as a record of string keys and their values, and the default reading time function. It returns a number (reading time in minutes) or `undefined` (disable reading time for this page).
493+
The `readingTime` callback receives the following parameters:
494+
495+
- `content`: the blog content text as a string
496+
- `frontMatter`: the front matter as a record of string keys and their values
497+
- `locale`: the locale of the current Docusaurus site
498+
- `defaultReadingTime`: the default built-in reading time function. It returns a number (reading time in minutes) or `undefined` (disable reading time for this page).
490499

491500
The default reading time is able to accept additional options:
492501

@@ -512,10 +521,10 @@ export default {
512521
blog: {
513522
showReadingTime: true,
514523
// highlight-start
515-
readingTime: ({content, frontMatter, defaultReadingTime}) =>
524+
readingTime: ({content, locale, frontMatter, defaultReadingTime}) =>
516525
frontMatter.hide_reading_time
517526
? undefined
518-
: defaultReadingTime({content}),
527+
: defaultReadingTime({content, locale}),
519528
// highlight-end
520529
},
521530
},
@@ -549,8 +558,12 @@ export default {
549558
{
550559
blog: {
551560
// highlight-start
552-
readingTime: ({content, defaultReadingTime}) =>
553-
defaultReadingTime({content, options: {wordsPerMinute: 100}}),
561+
readingTime: ({content, locale, defaultReadingTime}) =>
562+
defaultReadingTime({
563+
content,
564+
locale,
565+
options: {wordsPerMinute: 100},
566+
}),
554567
// highlight-end
555568
},
556569
},
@@ -576,7 +589,7 @@ export default {
576589
{
577590
blog: {
578591
// highlight-next-line
579-
readingTime: ({content}) => myReadingTime(content),
592+
readingTime: ({content, locale}) => myReadingTime(content, locale),
580593
},
581594
},
582595
],

0 commit comments

Comments
 (0)