Module:日文歌单
跳转到导航
跳转到搜索
local p = {}
local getArgs = require('module:arguments').getArgs
function fallback(a, b)
return a ~= '' and a or b
end
function authors(author1, author2, color, frame)
local jauthor = frame:expandTemplate{title = 'cj', args = {color, author1}}
if author2 == '0' then
return jauthor
else
return '[['..fallback(author2, author1)..'|'..jauthor..']]'
end
end
function p.main(frame)
local args = getArgs(frame)
local color1 = frame:callParserFunction('#var', 'color1')
local color2 = frame:callParserFunction('#var', 'color2')
local color3 = frame:callParserFunction('#var', 'color3')
local ol = mw.html.create('ol')
:css('margin-left', '1.7em')
for num, line in ipairs(args) do
local indent = line:sub(1, 1) == ':'
if indent then
line = line:sub(2)
end
local inner = ''
if line:sub(1, 1) == ';' then
inner = line:sub(2)
else
local item = mw.text.split(line, ';')
if #item > 4 then
inner = item[5]
end
local song = mw.text.split(item[1], ':')
local ja = frame:expandTemplate{title = 'cj', args = {color1, song[1]}}
if song[2] == '0' then
inner = inner..ja
else
inner = inner..'[['..fallback(song[2], song[1])..'|'..ja..']]'
end
local translation = fallback(fallback(song[3], song[2]), '0')
if translation ~= '0' then
inner = inner..'<small> '..frame:expandTemplate{title = 'color', args = {color2, '('..translation..')'}}..' </small>'
end
if item[2] and item[2] ~= '' then
local author = mw.text.split(item[2], ':')
inner = inner..' / '..authors(author[1], author[2], color3, frame)
end
if item[3] and item[3] ~= '' then
local author = mw.text.split(item[3], ':')
inner = inner..' '..authors(author[1], author[2], color3, frame)
end
if #item > 3 then
inner = inner..' '..item[4]
end
end
if indent then
ol:tag('dl')
:css('margin-bottom', 0)
:tag('dd')
:wikitext(inner)
else
ol:tag('li')
:wikitext(inner)
end
end
return tostring(ol)
end
function p.single(frame)
local args = getArgs(frame)
local color1 = args.color1 or frame:callParserFunction('#var', 'color1', '#007fff')
local color2 = args.color2 or frame:callParserFunction('#var', 'color2', '#0047ab')
local color3 = args.color3 or frame:callParserFunction('#var', 'color3', color1)
local result = ''
local ja = frame:expandTemplate{title = 'cj', args = {color1, args[1]}}
if args.link1 == '0' then
result = result..ja
else
result = result..'[['..(args.link1 or args[1])..'|'..ja..']]'
end
if fallback(fallback(args.trans, args.link1), '0') ~= '0' then
result = result..'<small> '..frame:expandTemplate{title = 'color', args = {color2, '('..(args.trans or args.link1)..')'}}..' </small>'
end
if args[2] then
result = result..' / '..authors(args[2], args.link2, color3, frame)
end
if args[3] then
result = result..' '..authors(args[3], args.link3, color3, frame)
end
return result
end
return p