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