Модуль:RandomPageFromCategory: различия между версиями
Материал из Поле цифровой дидактики
Patarakin (обсуждение | вклад) Нет описания правки Метка: ручная отмена |
Patarakin (обсуждение | вклад) Нет описания правки |
||
| Строка 1: | Строка 1: | ||
-- Module:RandomPageFromCategory | -- Module:RandomPageFromCategory | ||
local p = {} | local p = {} | ||
local function pick(list) | |||
if #list == 0 then | |||
return nil | |||
end | |||
math.randomseed(os.time()) | |||
return list[math.random(#list)] | |||
end | |||
function p.fromCategory(frame) | function p.fromCategory(frame) | ||
local cat = frame.args[1] or "Book" | local cat = frame.args[1] or "Book" | ||
return "[[Special:RandomInCategory/" .. cat .. "|случайная страница из " .. cat .. "]]" | return "[[Special:RandomInCategory/" .. cat .. "|случайная страница из " .. cat .. "]]" | ||
end | |||
function p.fromList(frame) | |||
local items = {} | |||
local i = 1 | |||
while frame.args[i] do | |||
table.insert(items, frame.args[i]) | |||
i = i + 1 | |||
end | |||
local page = pick(items) | |||
if not page then | |||
return "Нет страниц в списке" | |||
end | |||
return page | |||
end | end | ||
return p | return p | ||
Версия от 08:44, 19 мая 2026
-- Module:RandomPageFromCategory
local p = {}
local function pick(list)
if #list == 0 then
return nil
end
math.randomseed(os.time())
return list[math.random(#list)]
end
function p.fromCategory(frame)
local cat = frame.args[1] or "Book"
return "[[Special:RandomInCategory/" .. cat .. "|случайная страница из " .. cat .. "]]"
end
function p.fromList(frame)
local items = {}
local i = 1
while frame.args[i] do
table.insert(items, frame.args[i])
i = i + 1
end
local page = pick(items)
if not page then
return "Нет страниц в списке"
end
return page
end
return p
