Модуль:Новости: различия между версиями
Материал из AbduloverA.com
![]() Adept (обсуждение | вклад) |
![]() Adept (обсуждение | вклад) |
||
Строка 8: | Строка 8: | ||
local content = mw.title.new(pageName):getContent() | local content = mw.title.new(pageName):getContent() | ||
if not content then | |||
return "Страница не найдена или пуста." | |||
end | |||
for row in content:gmatch("{{Новость|date[^}}]+}}", "%a+") do | |||
table.insert(rows, row) | |||
end | |||
local rows = {} | |||
str_p = rows[index]; | |||
return str_p; | return str_p; | ||
end | end | ||
Строка 25: | Строка 36: | ||
-- local rows = {} | -- local rows = {} | ||
-- -- Вывод первых 5 строк | -- -- Вывод первых 5 строк |
Версия от 15:00, 27 января 2025
Для документации этого модуля может быть создана страница Модуль:Новости/doc
local p = {} local str_p = "" function p.render_once(frame, index) local pageName = frame.args[1]; local index = frame.args[2]; local content = mw.title.new(pageName):getContent() if not content then return "Страница не найдена или пуста." end for row in content:gmatch("{{Новость|date[^}}]+}}", "%a+") do table.insert(rows, row) end local rows = {} str_p = rows[index]; return str_p; end return p; -- mw.log(index); -- -- local pageName = "Шаблон:Новости" -- local content = mw.title.new(pageName):getContent() -- if not content then -- return "Страница не найдена или пуста." -- end -- local rows = {} -- -- Вывод первых 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) -- return str_p -- end -- return p