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

Материал из AbduloverA.com
 
(не показано 11 промежуточных версий этого же участника)
Строка 3: Строка 3:




function p.render_once(frame)
function p.render_text(frame)
     -- local pageName = frame.args[1] or "Шаблон:Новости";
     local pageName = frame.args[1];
     -- local index = frame.args[2] or "2";
     local index = frame.args[2];
      
      
     local pageName = "Шаблон:Новости";
     -- local pageName = "Шаблон:Новости";
     local index = 1;
     -- local index = 1;


      
      
Строка 19: Строка 19:
     local rows = {}
     local rows = {}


 
     -- for row in content:gmatch("|text=.[^}]+|", "%a") do
 
     -- for row in content:gmatch("{{Новость|date[^}}]+}}", "%a+") do
     for row in content:gmatch("|text=.[^}]+}-", "%a") do
     for row in content:gmatch("|text=.[^}]+}-", "%a") do
    -- for row in content:gmatch("|%s*[%w%W]-}}%-") do
         table.insert(rows, row)
         table.insert(rows, row)
     end
     end
Строка 29: Строка 26:
     local result = {}
     local result = {}
str_p = rows[tonumber(index)]
str_p = rows[tonumber(index)]
-- mw.log(str_p);
local trunced = string.gsub(str_p, "|text=", "");
local trunced = string.gsub(str_p, "|text=", "");
    mw.log(trunced);
-- local str_p = string.gsub(trunced, "|", "");
    -- str_p = content:gsub(str_p, "|text=", "");
-- mw.log(trunced);
   
-- str_p = "current index : " .. index;
    -- local rows = {}
 
    -- str_p = rows[index];
return trunced;
return trunced;
end  
end  


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


function p.render_date(frame)
    local pageName = frame.args[1];
    local index = frame.args[2];
   
    -- local pageName = "Шаблон:Новости";
    -- local index = 1;


   
    local content = mw.title.new(pageName):getContent()


--     -- Вывод первых 5 строк
     if not content then
--    local result = {}
         return "Страница не найдена или пуста."
--    for i = 1, math.min(5, #rows) do
    end
--         table.insert(result, rows[index])
--        str_p = rows[index];
     local rows = {}
--        -- str_p = str_p .. "\n"
--        -- mw.log(str_p);
--        -- mw.log(rows[i]);
--     end


--     -- return table.concat(result)
     for row in content:gmatch("|date=.[^}]+|", "%a") do
--     return str_p
        table.insert(rows, row)
-- end
     end


    local result = {}
str_p = rows[tonumber(index)]
local trunced = string.gsub(str_p, "|date=", "");
local str_p = string.gsub(trunced, "|", "");
    mw.log(str_p);


return str_p;
end




-- return p
return p;

Текущая версия от 23:38, 27 января 2025

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

local p = {}
local str_p = ""


function p.render_text(frame)
    local pageName = frame.args[1];
    local index = frame.args[2];
    
    -- local pageName = "Шаблон:Новости";
    -- local index = 1;

    
    local content = mw.title.new(pageName):getContent()

    if not content then
        return "Страница не найдена или пуста."
    end
	
    local rows = {}

    -- for row in content:gmatch("|text=.[^}]+|", "%a") do
    for row in content:gmatch("|text=.[^}]+}-", "%a") do
        table.insert(rows, row)
    end

    local result = {}
	str_p = rows[tonumber(index)]
	-- mw.log(str_p);
	local trunced = string.gsub(str_p, "|text=", "");
	-- local str_p = string.gsub(trunced, "|", "");
	-- mw.log(trunced);
	return trunced;
end 


function p.render_date(frame)
    local pageName = frame.args[1];
    local index = frame.args[2];
    
    -- local pageName = "Шаблон:Новости";
    -- local index = 1;

    
    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

    local result = {}
	str_p = rows[tonumber(index)]
	local trunced = string.gsub(str_p, "|date=", "");
	local str_p = string.gsub(trunced, "|", "");
    mw.log(str_p);

	return str_p;
end 


return p;