Added animated auto-opening link modal, custom image node with isolated caption deletion, fixed single-select category data binding, improved featured image layout, and updated README.
23 lines
981 B
TypeScript
23 lines
981 B
TypeScript
import { READING_TIME_LABEL, WORDS_PER_MINUTE } from '../data/constants'
|
|
import { toPersianDigits } from './digits'
|
|
import { docToText } from './tiptapDoc'
|
|
|
|
export { WORDS_PER_MINUTE, READING_TIME_LABEL }
|
|
|
|
/** شمارش واژههای متن سند (بدون شمارش نویسههای قالببندی) */
|
|
export function countWords(body: unknown): number {
|
|
return docToText(body)
|
|
.split(/\s+/)
|
|
.filter(Boolean).length
|
|
}
|
|
|
|
/** زمان مطالعه بر حسب دقیقه — سقف واژهها تقسیم بر سرعت مطالعه، حداقل یک دقیقه */
|
|
export function readingTimeMinutes(body: unknown): number {
|
|
return Math.max(1, Math.ceil(countWords(body) / WORDS_PER_MINUTE))
|
|
}
|
|
|
|
/** زمان مطالعه آماده نمایش با ارقام فارسی — مثل «۵ دقیقه مطالعه» */
|
|
export function formatReadingTime(body: unknown): string {
|
|
return `${toPersianDigits(readingTimeMinutes(body))} ${READING_TIME_LABEL}`
|
|
}
|