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

Admin​(留言 | 贡献)
改用 模块:署名解析 统一拆词;标题下显示实时曲目数(替代映射表中无法维护的 _曲目数)
Admin​(留言 | 贡献)
支持两段式映射(主名义/合作名义):整串查表归并到主名义,不再拆词;旧结构仍兼容
第7行: 第7行:
local DATA_TITLE = '模板:曲目列表.json'
local DATA_TITLE = '模板:曲目列表.json'
local validator = require('模块:数据页校验')
local validator = require('模块:数据页校验')
-- ===== 两段式名义表(映射页新结构: 主名义 / 合作名义)=====
-- 新结构下: 署名整串查表 → 归并到主名义; 查不到则原样。旧结构(平表)保持原逻辑,便于平滑切换。
local function buildLookup(data)
if type(data) ~= 'table' or type(data['主名义']) ~= 'table' then return nil end
local alias, collab, extra = {}, {}, {}
for _, m in pairs(data['主名义']) do
if type(m) == 'table' and m['显示名'] then
local dn = m['显示名']
extra[parse.norm(dn)] = m
for _, a in ipairs(m['马甲'] or {}) do alias[parse.norm(a)] = dn end
end
end
for _, c in pairs(data['合作名义']) do
if type(c) == 'table' and c['名义'] then
collab[parse.norm(c['名义'])] = c['组合'] or {}
end
end
return { alias = alias, collab = collab, extra = extra }
end
-- 把一个署名原串解析成归属列表: 合作名义 → 每位成员; 马甲 → 主名义(备注里标出名义); 其余 → 原样
local function attribute(lk, raw)
if not lk then return nil end
local key = parse.norm(raw)
local c = lk.collab[key]
if c then
local out = {}
for _, m in ipairs(c) do out[#out + 1] = { base = m, ann = '', other = c } end
return out
end
local m = lk.alias[key]
if m then return { { base = m, ann = '名义:' .. raw } } end
return { { base = raw, ann = '' } }
end
local MAP_TITLE = '模板:曲师映射.json'
local MAP_TITLE = '模板:曲师映射.json'
local INTRO_TITLE = '模板:曲师简介'  -- 手工简介数据页(可编辑 wikitext)
local INTRO_TITLE = '模板:曲师简介'  -- 手工简介数据页(可编辑 wikitext)
第97行: 第132行:
end
end
local map = loadJson(MAP_TITLE) or {}
local map = loadJson(MAP_TITLE) or {}
local lk = buildLookup(map)
local intros = loadIntros()
local intros = loadIntros()


第104行: 第140行:
local raw = song['曲师']
local raw = song['曲师']
if type(raw) == 'table' then raw = raw[1] end
if type(raw) == 'table' then raw = raw[1] end
local parts = parse.parts(raw)
local parts = attribute(lk, raw) or parse.parts(raw)
local seen = {}
local seen = {}
for _, pt in ipairs(parts) do
for _, pt in ipairs(parts) do
第111行: 第147行:
seen[key] = true
seen[key] = true
if not artists[key] then
if not artists[key] then
local m = map[key] or {}
local m = (lk and lk.extra[key]) or map[key] or {}
artists[key] = {
artists[key] = {
display = m['显示名'] or pt.base,
display = m['显示名'] or pt.base,