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

Module:ReadingTime

From the only original and legitimate Battlestar Wiki: the free-as-in-beer, non-corporate, open-content encyclopedia, analytical reference, and episode guide on all things Battlestar Galactica. Accept neither subpar substitutes nor subpar clones.

Documentation for this module may be created at Module:ReadingTime/doc

local p = {}

function p.getReadingTime(frame)
    -- Get the content of the current page
    local title = mw.title.getCurrentTitle()
    local content = title:getContent()
    
    if not content then return "1 min" end

    -- Strip out some wiki-markup to get a cleaner word count
    -- This removes HTML comments, category links, and some formatting
    local cleanContent = content:gsub("<!%-%-.-%-%->", "")
                               :gsub("%[%[Category:.-%]%]", "")
                               :gsub("%[%[File:.-%]%]", "")

    -- Count words (simple whitespace split)
    local _, wordCount = cleanContent:gsub("%S+", "")
    
    -- Average reading speed (200-250 words per minute)
    local wpm = 225
    local minutes = math.ceil(wordCount / wpm)
    
    if minutes < 1 then minutes = 1 end
    
    return minutes .. " min read"
end

return p