Module:曲师列表:修订间差异

Admin​(留言 | 贡献)
新增 |intro=0(页面自带引言时抑制模块引言)
Admin​(留言 | 贡献)
去掉小节下的「共 N 首曲目/张谱面」计数行;曲师列表新增 p.rank 自动排行榜
第144行: 第144行:


-- ===== 主渲染 =====
-- ===== 主渲染 =====
-- ===== 自动排行榜(子页面用): {{#invoke:曲师列表|rank|min=3}} =====
-- 实时统计每位主名义收录的曲目数;并列名次用 rowspan 合并;名字链到曲师列表对应小节
function p.rank(frame)
local args = frame.args or {}
local minN = tonumber(args['min']) or 3
local data = validator.load(DATA_TITLE)
if not data then return '<span class="error">数据页错误</span>' end
local map = loadJson(MAP_TITLE) or {}
local lk = buildLookup(map)
local counts, display = {}, {}
for _, song in ipairs(data.songs or {}) do
local raw = song['曲师']
if type(raw) == 'table' then raw = raw[1] end
local parts = attribute(lk, raw) or parse.parts(raw)
local seen = {}
for _, pt in ipairs(parts) do
local key = norm(pt.base)
if key ~= '' and not seen[key] then
seen[key] = true
local m = (lk and lk.extra[key]) or map[key] or {}
display[key] = m['显示名'] or pt.base
counts[key] = (counts[key] or 0) + 1
end
end
end
local byCount, nums = {}, {}
for k, c in pairs(counts) do
if c >= minN then
byCount[c] = byCount[c] or {}
table.insert(byCount[c], k)
end
end
for c in pairs(byCount) do table.insert(nums, c) end
table.sort(nums, function(a, b) return a > b end)
local out = { '{| class="wikitable"', '|+收录曲数量排行榜', '!名次!!数量!!名字' }
local emitted = 0
for _, c in ipairs(nums) do
local list = byCount[c]
table.sort(list, function(a, b)
return mw.ustring.lower(display[a]) < mw.ustring.lower(display[b])
end)
local r = emitted + 1
for i, k in ipairs(list) do
table.insert(out, '|-')
if i == 1 then
table.insert(out, '| rowspan="' .. #list .. '" |' .. r)
table.insert(out, '| rowspan="' .. #list .. '" |' .. c)
end
table.insert(out, '| [[' .. '曲师列表#' .. esc(display[k]) .. '|' .. esc(display[k]) .. ']]')
end
emitted = emitted + #list
end
table.insert(out, '|}')
if emitted == 0 then return '<span class="error">没有达到门槛(' .. minN .. ' 首)的曲师</span>' end
return frame:preprocess(table.concat(out, '\n'))
end
function p.render(frame)
function p.render(frame)
local songs, songsErr = loadSongs()
local songs, songsErr = loadSongs()
第200行: 第257行:
local a = artists[key]
local a = artists[key]
table.insert(out, '\n==' .. esc(a.display) .. '==')
table.insert(out, '\n==' .. esc(a.display) .. '==')
-- 曲目数实时统计(替代此前映射表里无法维护的 _曲目数)
table.insert(out, '<div style="font-size:92%;color:#555">共 ' .. "'''" .. #a.songs .. "'''" .. ' 首曲目</div>')
if a.unconfirmed then
if a.unconfirmed then
table.insert(out, '<div style="font-size:92%;color:#b45309">主名义待确认</div>')
table.insert(out, '<div style="font-size:92%;color:#b45309">主名义待确认</div>')