Module:UpdateExcerpt: Difference between revisions

From The Deadlock Wiki
Jump to navigation Jump to search
Added __NOEDITSECTION__ so the preview no longer shows edit buttons
Performance optimizations
Line 24: Line 24:
     end
     end


     local notesStart = content:find("|%s*notes%s*=")
     local notesRaw = content:match("|%s*notes%s*=(.*)")
     if not notesStart then
     if not notesRaw then
         return '<span class="error">No notes parameter found on [[' .. pageTitle .. ']]</span>'
         return '<span class="error">No notes parameter found on [[' .. pageTitle .. ']]</span>'
     end
     end


     local sub  = content:sub(notesStart)
     notesRaw = notesRaw:gsub("%s*}}%s*$", "")
    local eqPos = sub:find("=")
    local notesRaw = sub:sub(eqPos + 1)
 
    local lastClose = notesRaw:find("}}%s*$")
    if lastClose then
        notesRaw = notesRaw:sub(1, lastClose - 1)
    end
 
     notesRaw = mw.text.trim(notesRaw)
     notesRaw = mw.text.trim(notesRaw)


Line 46: Line 38:
     local maxHeight = maxLines * 1.7
     local maxHeight = maxLines * 1.7


local html = '<div style="flex:1; min-height:0; overflow-y:auto; max-height:'
    local html = string.format(
    .. maxHeight
        '<div style="flex:1; min-height:0; overflow-y:auto; max-height:%.1fem; padding:14px 18px; font-family: sans-serif; font-size:0.92em; line-height:1.7;">\n__NOEDITSECTION__\n%s\n</div>',
    .. 'em; padding:14px 18px; font-family: sans-serif; font-size:0.92em; line-height:1.7;">\n'
        maxHeight,
    .. '__NOEDITSECTION__\n'
        frame:preprocess(notesRaw)
    .. frame:preprocess(notesRaw)
    )
    .. '\n</div>'


     return html
     return html

Revision as of 22:38, 27 June 2026

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

local p = {}

function p.render(frame)
    local args = frame.args
    local month    = args[1]
    local day      = args[2]
    local year     = args[3]
    local maxLines = tonumber(args[4]) or 10

    if not month or not day or not year then
        return '<span class="error">Usage: {{#invoke:UpdateExcerpt|render|Month|Day|Year|lines}}</span>'
    end

    local pageTitle = "Update:" .. month .. " " .. day .. ", " .. year

    local titleObj = mw.title.new(pageTitle)
    if not titleObj then
        return '<span class="error">Invalid page title: ' .. pageTitle .. '</span>'
    end

    local content = titleObj:getContent()
    if not content then
        return '<span class="error">Page not found: [[' .. pageTitle .. ']]</span>'
    end

    local notesRaw = content:match("|%s*notes%s*=(.*)")
    if not notesRaw then
        return '<span class="error">No notes parameter found on [[' .. pageTitle .. ']]</span>'
    end

    notesRaw = notesRaw:gsub("%s*}}%s*$", "")
    notesRaw = mw.text.trim(notesRaw)

    if notesRaw == "" then
        return ""
    end

    local maxHeight = maxLines * 1.7

    local html = string.format(
        '<div style="flex:1; min-height:0; overflow-y:auto; max-height:%.1fem; padding:14px 18px; font-family: sans-serif; font-size:0.92em; line-height:1.7;">\n__NOEDITSECTION__\n%s\n</div>',
        maxHeight,
        frame:preprocess(notesRaw)
    )

    return html
end

return p