Skip to content

Commit 85beec3

Browse files
authored
Merge pull request #15202 from ethereum/hotfix-read-time
Hotfix reading time for tutorials
2 parents 352f15c + 8906a43 commit 85beec3

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

app/[locale]/[...slug]/page.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export default async function Page({
6363
lastEditLocaleTimestamp,
6464
isTranslated,
6565
contributors,
66+
timeToRead,
6667
} = await getPageData({
6768
locale,
6869
slug,
@@ -97,8 +98,7 @@ export default async function Page({
9798
lastEditLocaleTimestamp={lastEditLocaleTimestamp}
9899
contentNotTranslated={!isTranslated}
99100
contributors={contributors}
100-
// TODO: Remove this once we have a real timeToRead value
101-
timeToRead={2}
101+
timeToRead={Math.round(timeToRead.minutes)}
102102
>
103103
{content}
104104
</Layout>

src/lib/md/data.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { MDXRemoteProps } from "next-mdx-remote"
2+
import readingTime, { ReadTimeResults } from "reading-time"
23

34
import {
45
CommitHistory,
@@ -32,6 +33,7 @@ interface PageData {
3233
lastEditLocaleTimestamp: string
3334
contributors: FileContributor[]
3435
isTranslated: boolean
36+
timeToRead: ReadTimeResults
3537
}
3638

3739
export async function getPageData({
@@ -76,12 +78,15 @@ export async function getPageData({
7678
lastUpdatedDate
7779
)
7880

81+
const timeToRead = readingTime(markdown)
82+
7983
return {
8084
content,
8185
frontmatter,
8286
tocItems: tocItems as ToCItem[],
8387
lastEditLocaleTimestamp,
8488
contributors,
8589
isTranslated,
90+
timeToRead,
8691
}
8792
}

0 commit comments

Comments
 (0)