keroosha.cybergulag.today/quartz/components/ReadingTime.tsx

26 lines
556 B
TypeScript
Raw Normal View History

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