跳转到内容
打开/关闭菜单
  • 234 条目
  • 1561 文件
  • 67 用户
  • 9635 编辑
永雏塔菲百科
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模块:MusicInfoBox

来自永雏塔菲百科

此模块的文档可以在模块:MusicInfoBox/doc创建

local p = {}

local function trim(s)
	if s == nil then return nil end
	s = tostring(s)
	s = mw.text.trim(s)
	if s == '' then return nil end
	return s
end

local function link(text, url)
	text = trim(text)
	url = trim(url)
	if not text then return '' end
	if url then
		return '[' .. url .. ' ' .. text .. ']'
	end
	return text
end

local function makeRow(label, value)
	value = trim(value)
	if not value then return '' end

	return mw.html.create('div')
		:addClass('songinfo-row')
		:tag('div')
			:addClass('songinfo-label')
			:wikitext(label)
			:done()
		:tag('div')
			:addClass('songinfo-value')
			:wikitext(value)
			:done()
end

local function makeCreatorRows(args)
	local rows = {}

	local i = 1
	while true do
		local role = trim(args['创作者' .. i .. '职务'])
		local name = trim(args['创作者' .. i .. '名称'])
		local note = trim(args['创作者' .. i .. '备注'])

		if not role and not name then
			break
		end

		if role or name then
			local value = name or ''
			if note then
				value = value .. ' ' .. note
			end

			local block = mw.html.create('div')
				:addClass('songinfo-creator-block')
				:tag('div')
					:addClass('songinfo-section')
					:wikitext(role or '创作者')
					:done()
				:tag('div')
					:addClass('songinfo-mainvalue')
					:wikitext(value)
					:done()

			table.insert(rows, tostring(block))
		end

		i = i + 1
	end

	return table.concat(rows, '\n')
end

function p.main(frame)
	local args = frame:getParent().args

	local root = mw.html.create('div'):addClass('songinfo-box')

	local image = trim(args['图片'])
	if image then
		root:tag('div')
			:addClass('songinfo-image')
			:wikitext('[[File:' .. image .. '|frameless]]')
	end

	local illust = trim(args['曲绘'])
	local illustUrl = trim(args['曲绘链接'])
	if illust then
		root:tag('div')
			:addClass('songinfo-illust')
			:wikitext('Illustration by ' .. link(illust, illustUrl))
	end

	local title = trim(args['歌曲名称'] or args['歌名'])
	if title then
		root:tag('div')
			:addClass('songinfo-section songinfo-section-dark')
			:wikitext('歌曲名称')

		root:tag('div')
			:addClass('songinfo-title')
			:wikitext(title)
	end

	local desc = trim(args['投稿说明'] or args['投稿信息'])
	if desc then
		root:tag('div')
			:addClass('songinfo-section songinfo-section-dark songinfo-desc')
			:wikitext(desc)
	end

	local singer = trim(args['原唱'])
	if singer then
		root:tag('div')
			:addClass('songinfo-section')
			:wikitext('原唱')

		root:tag('div')
			:addClass('songinfo-mainvalue')
			:wikitext(singer)
	end

	local producer = trim(args['P主'] or args['制作者'])
	if producer then
		root:tag('div')
			:addClass('songinfo-section')
			:wikitext('P主')

		root:tag('div')
			:addClass('songinfo-mainvalue')
			:wikitext(producer)
	end

	local links = {}
	local nico = trim(args['N站链接'] or args['Niconico'])
	local yt = trim(args['YouTube链接'] or args['Youtube链接'] or args['YouTube'])
	local bilibili = trim(args['B站链接'] or args['Bilibili'])
	local netease = trim(args['网易云音乐链接'] or args['网易云'] or args['NetEase'])
	local qqmusic = trim(args['QQ音乐链接'] or args['QQ音乐'] or args['QQMusic'])
	
	if nico then table.insert(links, '[' .. nico .. ' Niconico↗]') end
	if yt then table.insert(links, '[' .. yt .. ' YouTube↗]') end
	if bilibili then table.insert(links, '[' .. bilibili .. ' Bilibili↗]') end
	if netease then table.insert(links, '[' .. netease .. ' 网易云音乐↗]') end
	if qqmusic then table.insert(links, '[' .. qqmusic .. ' QQ音乐↗]') end

	if #links > 0 then
		root:tag('div')
			:addClass('songinfo-section')
			:wikitext('连结')

		root:tag('div')
			:addClass('songinfo-links')
			:wikitext(table.concat(links, ' '))
	end

	local quote = trim(args['投稿文'])
	local quoteAuthor = trim(args['投稿文署名'])
	local quoteCn = trim(args['投稿文翻译'])

	if quote then
		local q = root:tag('div'):addClass('songinfo-quote')
		q:tag('div')
			:addClass('songinfo-quote-main')
			:wikitext('“' .. quote .. '”')

		if quoteCn then
			q:tag('div')
				:addClass('songinfo-quote-cn')
				:wikitext('"' .. quoteCn .. '"')
		end

		if quoteAuthor then
			q:tag('div')
				:addClass('songinfo-quote-author')
				:wikitext('——' .. quoteAuthor)
		end
	end

	local creators = makeCreatorRows(args)
	if creators ~= '' then
		root:tag('div')
			:addClass('songinfo-creators songinfo-creators-grid')
			:wikitext(creators)
	end

	return tostring(root)
end

return p