readingTime()

document के reading time का अनुमान लगाएँ और इसे compile result में शामिल करें।

import { readingTime } from "@unifast/node";

Signature

function readingTime(options?: ReadingTimePluginOptions): UnifastPlugin

Parameters

options?

Reading time अनुमान के लिए Configuration

PropertyTypeDefaultविवरण
wordsPerMinutenumber200Latin text के लिए Words per minute
cjkCharsPerMinutenumber500CJK text के लिए Characters per minute

Returns

Plugin compile result में एक readingTime property जोड़ता है:

PropertyTypeविवरण
result.readingTime.minutesnumberminutes में अनुमानित reading time (न्यूनतम 1, निकटतम 0.5 तक rounded up)
result.readingTime.wordsnumberकुल word count (Latin words + CJK characters)

उपयोग

import { compile, readingTime } from "@unifast/node";

const md = `
# My Article

This is a short article with some content that demonstrates
reading time estimation.
`;

const result = compile(md, {
  plugins: [readingTime()],
});

console.log(result.readingTime);
// { minutes: 1, words: 16 }

उदाहरण

Custom words per minute

import { compile, readingTime } from "@unifast/node";

const md = `A long article with many words...`;

const result = compile(md, {
  plugins: [
    readingTime({
      wordsPerMinute: 150, // धीमी reading speed
    }),
  ],
});

console.log(result.readingTime.minutes);

CJK content

import { compile, readingTime } from "@unifast/node";

const md = `
# 日本語の記事

今日は天気がとても良いです。公園で散歩をしました。
`;

const result = compile(md, {
  plugins: [
    readingTime({
      cjkCharsPerMinute: 400, // CJK reading speed के लिए adjust करें
    }),
  ],
});

console.log(result.readingTime);
// { minutes: 1, words: ... }

Mixed Latin और CJK text

Reading time को Latin words और CJK characters के लिए अलग-अलग calculate किया जाता है, फिर combine किया जाता है। Code blocks को word count से बाहर रखा जाता है।

import { compile, readingTime } from "@unifast/node";

const md = `
# Getting Started ガイド

This guide explains how to use the 設定ファイル for configuration.
`;

const result = compile(md, {
  plugins: [readingTime()],
});

// Latin words 200 WPM पर, CJK characters 500 CPM पर count होते हैं
console.log(result.readingTime);