Module:DidYouKnow
Documentation for this module may be created at Module:DidYouKnow/doc
local p = {}
-- CONFIG
local DATA_PAGE = "Template:Did you know/Data"
function p.main(frame)
local title = mw.title.new(DATA_PAGE)
if not title or not title.exists then
return "<span class='error'>DidYouKnow: data page not found</span>"
end
local content = title:getContent()
if not content then
return "<span class='error'>DidYouKnow: no content</span>"
end
local items = {}
-- Parse bullet list
for line in content:gmatch("[^\r\n]+") do
local item = line:match("^%*%s*(.+)")
if item then
table.insert(items, item)
end
end
if #items == 0 then
return "<span class='error'>DidYouKnow: no items found</span>"
end
-- Random selection
math.randomseed(os.time() + tonumber(tostring({}):match("0x(.*)"), 16))
local choice = items[math.random(#items)]
return choice
end
return p