Модуль:Новости: различия между версиями
Материал из AbduloverA.com
Adept (обсуждение | вклад) Нет описания правки |
Adept (обсуждение | вклад) Нет описания правки |
||
| Строка 22: | Строка 22: | ||
-- for row in content:gmatch("{{Новость|date[^}}]+}}", "%a+") do | -- for row in content:gmatch("{{Новость|date[^}}]+}}", "%a+") do | ||
for row in content:gmatch("|text=[^ | 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 | ||
local result = {} | local result = {} | ||
str_p = rows[tonumber(index)] | |||
str_p = | local trunced = string.gsub(str_p, "|text=", ""); | ||
mw.log(trunced); | |||
-- str_p = content:gsub(str_p, "|text=", ""); | |||
-- str_p = "current index : " .. index; | -- str_p = "current index : " .. index; | ||
| Строка 34: | Строка 37: | ||
-- str_p = rows[index]; | -- str_p = rows[index]; | ||
return str_p; | return str_p; | ||
end | end | ||
Версия от 21:58, 27 января 2025
Для документации этого модуля может быть создана страница Модуль:Новости/doc
local p = {}
local str_p = ""
function p.render_once(frame)
-- local pageName = frame.args[1] or "Шаблон:Новости";
-- local index = frame.args[2] or "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
for row in content:gmatch("|text=.[^}]+}-", "%a") do
-- for row in content:gmatch("|%s*[%w%W]-}}%-") do
table.insert(rows, row)
end
local result = {}
str_p = rows[tonumber(index)]
local trunced = string.gsub(str_p, "|text=", "");
mw.log(trunced);
-- str_p = content:gsub(str_p, "|text=", "");
-- str_p = "current index : " .. index;
-- 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