Module:UpdateExcerpt: Difference between revisions

Jump to navigation Jump to search
Undo revision 62037 by Monster Domosed (talk)
Tag: Undo
No edit summary
Line 12: Line 12:
     local maxLines = tonumber(args[4]) or 5
     local maxLines = tonumber(args[4]) or 5


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


    -- Build the page title  (e.g. "Update:March 6, 2026")
     local pageTitle = "Update:" .. month .. " " .. day .. ", " .. year
     local pageTitle = "Update:" .. month .. " " .. day .. ", " .. year


Line 30: Line 28:
     end
     end


    -----------------------------------------------------------------
    -- Locate the  | notes =  parameter inside {{Update layout …}}
    -----------------------------------------------------------------
     local notesStart = content:find("|%s*notes%s*=")
     local notesStart = content:find("|%s*notes%s*=")
     if not notesStart then
     if not notesStart then
Line 38: Line 33:
     end
     end


    -- Grab everything after the '=' sign
     local sub  = content:sub(notesStart)
     local sub  = content:sub(notesStart)
     local eqPos = sub:find("=")
     local eqPos = sub:find("=")
     local notesRaw = sub:sub(eqPos + 1)
     local notesRaw = sub:sub(eqPos + 1)


    -- Strip the final closing  }}  that belongs to {{Update layout}}
    -- Using the *last* occurrence so nested templates inside notes
    -- (if any) are preserved.
     local lastClose = notesRaw:find("}}%s*$")
     local lastClose = notesRaw:find("}}%s*$")
     if lastClose then
     if lastClose then
Line 57: Line 48:
     end
     end


    -----------------------------------------------------------------
    -- Split into non-empty lines
    -----------------------------------------------------------------
     local lines = {}
     local lines = {}
     for line in notesRaw:gmatch("[^\n]+") do
     for line in notesRaw:gmatch("[^\n]+") do
        -- keep the line only if it isn't pure whitespace
         if mw.text.trim(line) ~= "" then
         if mw.text.trim(line) ~= "" then
             table.insert(lines, line)
             table.insert(lines, line)
Line 72: Line 59:
     end
     end


    -----------------------------------------------------------------
    -- Build output: first N lines, then "…" linking to the full page
    -----------------------------------------------------------------
     local count  = math.min(maxLines, #lines)
     local count  = math.min(maxLines, #lines)
     local result = {}
     local result = {}
Line 82: Line 66:


     local output = table.concat(result, "\n")
     local output = table.concat(result, "\n")
    local hasMore = #lines > maxLines


     if #lines > maxLines then
    -- Wrap content in a scrollable div, put "Read more" outside it
         output = output .. "\n[[" .. pageTitle .. "|Read more]]"
    local html = '<div style="flex:1; min-height:0; overflow-y:auto; padding:14px 18px; font-family:\'Retail Demo\',\'Open Sans\',sans-serif; font-size:0.92em; line-height:1.7;">'
        .. frame:preprocess(output)
        .. '</div>'
 
     if hasMore then
         html = html .. '<div style="flex-shrink:0; padding:10px 18px; text-align:center; border-top:1px solid rgba(255,255,255,0.1); font-family:\'Retail Demo\',\'Open Sans\',sans-serif;">'
            .. frame:preprocess('[[' .. pageTitle .. '|<span style="color:#e8be86; font-weight:bold;">Read more →</span>]]')
            .. '</div>'
     end
     end


     return frame:preprocess(output)
     return html
end
end


return p
return p