Модуль:Новости: различия между версиями
Материал из AbduloverA.com
Adept (обсуждение | вклад) Нет описания правки |
Adept (обсуждение | вклад) Нет описания правки |
||
| Строка 2: | Строка 2: | ||
function p.render(frame) | function p.render(frame) | ||
local pageName = frame.args[1] or "Шаблон:Новости" | |||
local pageName = "Шаблон:Новости" | local pageName = "Шаблон:Новости" | ||
local content = mw.title.new(pageName):getContent() | local content = mw.title.new(pageName):getContent() | ||
| Строка 11: | Строка 9: | ||
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) | ||
Версия от 11:44, 26 декабря 2024
Для документации этого модуля может быть создана страница Модуль:Новости/doc
local p = {}
function p.render(frame)
local pageName = frame.args[1] or "Шаблон:Новости"
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, "\n")
end
return p