七日内新公告:全站维护公告
  • 你好~!欢迎来到萌娘百科镜像站!如需查看或编辑,请联系本站管理员注册账号。
  • 本镜像站和其他萌娘百科的镜像站无关,请注意分别。

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..'&nbsp;/ '..authors(author[1], author[2], color3, frame)
			end
			if item[3] and item[3] ~= '' then
				local author = mw.text.split(item[3], ':')
				inner = inner..'&nbsp;'..authors(author[1], author[2], color3, frame)
			end
			if #item > 3 then
				inner = inner..'&nbsp;'..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..'&nbsp;/ '..authors(args[2], args.link2, color3, frame)
	end
	if args[3] then
		result = result..'&nbsp;'..authors(args[3], args.link3, color3, frame)
	end
	return result
end

return p