Module:Chabad Days: Difference between revisions

Handle year-only and bold lines; capitalize first word
Follow redirects, heading variants, Nissan spelling
Line 7: Line 7:
local MONTHS = {
local MONTHS = {
['Tevet'] = 'Teves', ['Tamuz'] = 'Tammuz', ['Av'] = 'Menachem Av',
['Tevet'] = 'Teves', ['Tamuz'] = 'Tammuz', ['Av'] = 'Menachem Av',
['Adar II'] = 'Adar', ['Heshvan'] = 'Cheshvan', ['Tishri'] = 'Tishrei',
['Adar II'] = 'Adar', ['Nisan'] = 'Nissan', ['Heshvan'] = 'Cheshvan', ['Tishri'] = 'Tishrei',
}
}


Line 43: Line 43:
local pageName = day .. ' ' .. month
local pageName = day .. ' ' .. month
local title = mw.title.new(pageName)
local title = mw.title.new(pageName)
if title and title.exists and title.isRedirect and title.redirectTarget then
title = title.redirectTarget
end
local content = title and title.exists and title:getContent()
local content = title and title.exists and title:getContent()
local out = {}
local out = {}
Line 52: Line 55:
for line in (section .. '\n'):gmatch('(.-)\n') do
for line in (section .. '\n'):gmatch('(.-)\n') do
local head = line:match('^===%s*(.-)%s*===%s*$')
local head = line:match('^===%s*(.-)%s*===%s*$')
if head then
if line:match('^====') then
head = head:gsub('%[%[[^|%]]*|', ''):gsub('[%[%]]', '')
-- sub-sub-heading: ignore
if head == 'Born' then prefix = "''Born:'' "
elseif head then
elseif head == 'Passed Away' then prefix = "''Passed away:'' "
head = head:gsub('%[%[[^|%]]*|', ''):gsub('[%[%]]', ''):lower()
if head:find('born') or head:find('birth') then prefix = "''Born:'' "
elseif head:find('pass') or head:find('death') or head:find('died') then prefix = "''Passed away:'' "
else prefix = '' end
else prefix = '' end
elseif line:match('^%*') then
elseif line:match('^%*') then
Line 76: Line 81:
local year = frame:callParserFunction('#time', 'xjY')
local year = frame:callParserFunction('#time', 'xjY')
local footer = '<div style="clear:both; text-align:right; margin-top:0.4em;">' ..
local footer = '<div style="clear:both; text-align:right; margin-top:0.4em;">' ..
"'''[[" .. pageName .. "]] [[" .. year .. "]]''' – " ..
"'''" .. (content and ('[[' .. title.fullText .. '|' .. pageName .. ']]') or pageName) ..
"'''[[" .. pageName .. "#Chabad Days|More on this day]]'''</div>"
' [[' .. year .. "]]'''" ..
(content and (" – '''[[" .. title.fullText .. "#Chabad Days|More on this day]]'''") or '') ..
'</div>'
return '<div style="text-align:justify;">\n' .. body .. '\n</div>\n' .. footer
return '<div style="text-align:justify;">\n' .. body .. '\n</div>\n' .. footer
end
end


return p
return p