Module:UpdateExcerpt: Difference between revisions

Jump to navigation Jump to search
No edit summary
Tags: Mobile edit Mobile web edit
No edit summary
Line 1: Line 1:
-- Module:UpdateExcerpt
-- Usage: {{#invoke:UpdateExcerpt|render|Month|Day|Year|number_of_lines}}
local p = {}
local p = {}


Line 9: Line 6:
     local day      = args[2]
     local day      = args[2]
     local year    = args[3]
     local year    = args[3]
     local maxLines = tonumber(args[4]) or 5
     local maxLines = tonumber(args[4]) or 10


     if not month or not day or not year then
     if not month or not day or not year then
Line 47: Line 44:
     end
     end


     local lines = {}
     local maxHeight = maxLines * 1.7
    for line in notesRaw:gmatch("[^\n]+") do
        if mw.text.trim(line) ~= "" then
            table.insert(lines, line)
        end
    end
 
    if #lines == 0 then
        return ""
    end
 
    local count  = math.min(maxLines, #lines)
    local result = {}
    for i = 1, count do
        table.insert(result, lines[i])
    end


    local output = table.concat(result, "\n")
     local html = '<div style="flex:1; min-height:0; overflow-y:auto; max-height:'
    local hasMore = #lines > maxLines
        .. maxHeight
 
        .. 'em; padding:14px 18px; font-family:\'Retail Demo\',\'Open Sans\',sans-serif; font-size:0.92em; line-height:1.7;">\n'
     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;">\n'
         .. frame:preprocess(notesRaw)
         .. frame:preprocess(output)
         .. '\n</div>'
         .. '\n</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="class="plain" style="color:#e8be86; font-weight:bold; text-shadow: 0px 2px 2px black, 0px 0px 2px black;">Read more →</span>]]')
            .. '</div>'
    end


     return html
     return html