2023-06-12 13:46:38 +07:00
|
|
|
import { QuartzComponentConstructor, QuartzComponentProps } from "./types"
|
2023-06-10 13:06:02 +07:00
|
|
|
import readingTime from "reading-time"
|
|
|
|
|
2023-06-12 13:46:38 +07:00
|
|
|
function ReadingTime({ fileData }: QuartzComponentProps) {
|
2023-06-10 13:06:02 +07:00
|
|
|
const text = fileData.text
|
2023-07-05 00:08:32 +07:00
|
|
|
if (text) {
|
2023-06-10 13:06:02 +07:00
|
|
|
const { text: timeTaken, words } = readingTime(text)
|
2023-07-23 07:27:41 +07:00
|
|
|
return (
|
|
|
|
<p class="reading-time">
|
|
|
|
{words} words, {timeTaken}
|
|
|
|
</p>
|
|
|
|
)
|
2023-06-10 13:06:02 +07:00
|
|
|
} else {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReadingTime.css = `
|
|
|
|
.reading-time {
|
|
|
|
margin-top: 0;
|
2023-07-05 06:48:36 +07:00
|
|
|
color: var(--gray);
|
2023-06-10 13:06:02 +07:00
|
|
|
}
|
|
|
|
`
|
2023-06-12 13:46:38 +07:00
|
|
|
|
|
|
|
export default (() => ReadingTime) satisfies QuartzComponentConstructor
|