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

Материал из AbduloverA.com
Строка 1: Строка 1:
local p = {}
local p = {}
local str_p = ""
local str_p = ""
local index = 2;


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


     for row in content:gmatch("{{Новость|date[^}}]+}}", "%a+") do
     for row in content:gmatch("{{Новость|date[^}}]+}}", "%a+") do
         table.insert(rows, row)
         table.insert(rows, row)
        -- mw.log(row);
     end
     end
      
      
Строка 23: Строка 25:
     local result = {}
     local result = {}
     for i = 1, math.min(5, #rows) do
     for i = 1, math.min(5, #rows) do
         table.insert(result, rows[i])
         table.insert(result, rows[index])
         str_p = str_p .. rows[i];
         str_p = rows[index];
         -- str_p = str_p .. "\n"
         -- str_p = str_p .. "\n"
         -- mw.log(str_p);
         -- mw.log(str_p);
Строка 31: Строка 33:


     -- return table.concat(result)
     -- return table.concat(result)
     -- mw.log(str_p)
     mw.log(str_p)
     return str_p
     return str_p
end
end


-- mw.log(p)
return p




-- return str_p
 
return p

Версия от 14:37, 27 января 2025

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

local p = {}
local str_p = ""
local index = 2;


function p.render_once(frame, index)
    mw.log(index);
	
    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)
    end
    

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

    -- return table.concat(result)
    mw.log(str_p)
    return str_p
end




return p