Skip to content

Commit dc69661

Browse files
authored
feat: display the reading time in a formatted for the locale (nodejs#7495)
* feat: display the reading time in a formatted for the locale The display of the reading time for each page is currently based on the assumption that the page is in English. This change makes the Intl API is used to display the reading time in a format appropriate for the locale of the translated language. * maximumFractionDigits
1 parent 2f2fd25 commit dc69661

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

apps/site/components/withMetaBar.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const WithMetaBar: FC = () => {
2020
const lastUpdated = frontmatter.date
2121
? formatter.dateTime(new Date(frontmatter.date), DEFAULT_DATE_FORMAT)
2222
: undefined;
23+
const readingTimeText = formatter.number(readingTime.minutes, {
24+
style: 'unit',
25+
unit: 'minute',
26+
maximumFractionDigits: 0,
27+
});
2328

2429
const usernames =
2530
frontmatter.authors?.split(',').map(author => author.trim()) ?? [];
@@ -39,7 +44,7 @@ const WithMetaBar: FC = () => {
3944
<MetaBar
4045
items={{
4146
'components.metabar.lastUpdated': lastUpdated,
42-
'components.metabar.readingTime': readingTime.text,
47+
'components.metabar.readingTime': readingTimeText,
4348
...(usernames.length && {
4449
[`components.metabar.${usernames.length > 1 ? 'authors' : 'author'}`]:
4550
(

0 commit comments

Comments
 (0)