Модуль:Новости: различия между версиями

Материал из AbduloverA.com
Adept
Adept (обсуждение | вклад) (Отмена правки 1370, сделанной Adept (обсуждение))
Строка 3: Строка 3:
function td.render(frame)
function td.render(frame)
     -- local pageName = frame.args[1] or "Шаблон:Новости"
     -- local pageName = frame.args[1] or "Шаблон:Новости"
    local pageName = "Шаблон:Новости"
     local pageName = "Шаблон:Новости"
     local pageName = "Шаблон:Новости"
     local content = mw.title.new(pageName):getContent()
     local content = mw.title.new(pageName):getContent()
Строка 20: Строка 21:
     -- Вывод первых 5 строк
     -- Вывод первых 5 строк
     local result = {}
     local result = {}
   
     for i = 1, math.min(5, #rows) do
     for i = 1, math.min(5, #rows) do
    -- concated_result = concat(rows[i], "\n")
    rows[i] = rows[i] .. "\n"
         table.insert(result, rows[i])
         table.insert(result, rows[i])
        -- concated_result = {}
         -- mw.log(i);
         -- mw.log(i);
         mw.log(rows[i]);
         -- mw.log(rows[i]);
     end
     end


     return table.concat(result, "\n")
     return table.concat(result)
end
end


return td
return td

Версия от 21:00, 26 декабря 2024

Для документации этого модуля может быть создана страница Модуль:Новости/doc

local td = {}

function td.render(frame)
    -- local pageName = frame.args[1] or "Шаблон:Новости"
    local pageName = "Шаблон:Новости"
    local pageName = "Шаблон:Новости"
    local content = mw.title.new(pageName):getContent()
	
    if not content then
        return "Страница не найдена или пуста."
    end

    local rows = {}

    for row in content:gmatch("{{Новость|date[^}}]+}}", "%a+") do
        table.insert(rows, row)
        -- mw.log(row);
    end
    

    -- Вывод первых 5 строк
    local result = {}
    for i = 1, math.min(5, #rows) do
        table.insert(result, rows[i])
        -- mw.log(i);
        -- mw.log(rows[i]);
    end

    return table.concat(result)
end

return td