Module:Chabad Days
Appearance
Documentation for this module may be created at Module:Chabad Days/doc
-- Module:Chabad Days
-- Shows today's events from the "Chabad Days" section of the matching day article
-- (e.g. "10 Kislev"), as on the Hebrew main page's ימי חב"ד box.
local p = {}
-- #time English month names -> Chabadpedia spelling
local MONTHS = {
['Tevet'] = 'Teves', ['Tamuz'] = 'Tammuz', ['Av'] = 'Menachem Av',
['Adar II'] = 'Adar', ['Heshvan'] = 'Cheshvan', ['Tishri'] = 'Tishrei',
}
local function cleanLine(line)
-- "5587 (10/12/1826 by the [[Gentile Calendar|secular count]]) - text" -> "[[5587]] (1826) – text"
line = line:gsub("^(%*+)%s*('*)(%d%d%d%d)('*)%s*%(%d+/%d+/(%d+)[^%)]*%)%s*('*)%s*%-%s*",
function(stars, b1, year, b2, greg, b3)
return '* ' .. b1 .. '[[' .. year .. ']]' .. b2 .. ' (' .. greg .. ') ' .. b3 .. '– '
end)
line = line:gsub("^(%*+)%s*('*)(%d%d%d%d)('*)%s*%-%s*", '* %2[[%3]]%4 – ')
return line
end
function p.main(frame)
local args = frame.args
local day = args.day
local month = args.month
if not day or day == '' then
day = frame:callParserFunction('#time', 'xjj')
end
if not month or month == '' then
month = frame:callParserFunction('#time', 'xjF')
end
month = MONTHS[month] or month
local pageName = day .. ' ' .. month
local title = mw.title.new(pageName)
local content = title and title.exists and title:getContent()
local out = {}
if content then
local section = content:match('\n==%s*Chabad Days%s*==%s*\n(.-)\n==[^=]') or
content:match('\n==%s*Chabad Days%s*==%s*\n(.*)$')
if section then
local prefix = ''
for line in (section .. '\n'):gmatch('(.-)\n') do
local head = line:match('^===%s*(.-)%s*===%s*$')
if head then
head = head:gsub('%[%[[^|%]]*|', ''):gsub('[%[%]]', '')
if head == 'Born' then prefix = "''Born:'' "
elseif head == 'Passed Away' then prefix = "''Passed away:'' "
else prefix = '' end
elseif line:match('^%*') then
local l = cleanLine(line)
if prefix ~= '' then
l = l:gsub(' – ', ' – ' .. prefix, 1)
end
table.insert(out, l)
end
end
end
end
local body
if #out > 0 then
body = table.concat(out, '\n')
else
body = "''No Chabad events are recorded for this day yet.''"
end
local year = frame:callParserFunction('#time', 'xjY')
local footer = '<div style="clear:both; text-align:right; margin-top:0.4em;">' ..
"'''[[" .. pageName .. "]] [[" .. year .. "]]''' – " ..
"'''[[" .. pageName .. "#Chabad Days|More on this day]]'''</div>"
return '<div style="text-align:justify;">\n' .. body .. '\n</div>\n' .. footer
end
return p