Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Reading time

From ProleWiki, the proletarian encyclopedia
Revision as of 14:46, 17 September 2023 by CriticalResist (talk | contribs) (Created page with "-- Module:ReadingTime local p = {} function p.estimateReadingTime(content) -- Calculate the reading time based on content length local words = mw.ustring.gmatch(content, "%S+") local wordCount = 0 for _ in words do wordCount = wordCount + 1 end -- Define the range of reading speeds local minSpeed = 183 local maxSpeed = 250 -- Calculate reading times for both minimum and maximum speeds local minReadingTime = math.ceil(wordCount / m...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
-- Module:ReadingTime

local p = {}

function p.estimateReadingTime(content)
   -- Calculate the reading time based on content length
   local words = mw.ustring.gmatch(content, "%S+")
   local wordCount = 0
   for _ in words do
       wordCount = wordCount + 1
   end

   -- Define the range of reading speeds
   local minSpeed = 183
   local maxSpeed = 250

   -- Calculate reading times for both minimum and maximum speeds
   local minReadingTime = math.ceil(wordCount / maxSpeed)
   local maxReadingTime = math.ceil(wordCount / minSpeed)

   -- Create the reading time string
   local readingTime = "Between " .. minReadingTime .. " and " .. maxReadingTime .. " minutes"

   return readingTime
end

return p

-- invoke on page with {{#invoke:ReadingTime|estimateReadingTime|{{PAGESIZE:{{PAGENAME}}}}}} ?