Module:ConvertLink
可在Module:ConvertLink/doc创建此模块的帮助文档
local p = {}
-- local mad = require 'Module:AnotherData'
local function link(l, d)
if d then
return '[[' .. l .. '|' .. d .. ']]'
else
return '[[' .. l .. ']]'
end
end
local NotJaArtist = {['旅人E']=''}
function p.artistLink(artistName)
-- 将songlist中纯文本形式的曲师名称转换为带一个或多个链接的曲师名称,同时进行日文转换
-- 输入:曲师名称(需要与songlist内完全一致,或仅存在空格差异)(不要手打!!)
-- 返回:带链接的曲师名称
-- 若预期返回多个链接,实际返回一个链接;或曲师使用了马甲未能正确识别,请在 Template:ComplexArtistsList.json 添加新规则
-- 注意事项:json转义符,如曲师名称有 " 需要写成 \"(点名Gram(DJ Genki));
-- lua匹配转义符,CALv2使用匹配简化结构,注意默认格式下value即显示部分(冒号右侧) . * 等符号需要在之前添加%转义
if artistName then artistName=tostring(artistName) else return end
local CALv2 = mw.loadJsonData 'Template:ComplexArtistsList.json'
-- local CALv2 = mw.loadJsonData 'User:Economy666/ComplexArtistsList.json'
local function formatJapaneseText(text)
if not text then return text end
if NotJaArtist[text] then return text end
return mw.ustring.gsub(
text, '[一-龠ぁ-ゔァ-ヴー々〆〤ヶ]+',
function(v) return ('<span lang="ja">-{%s}-</span>'):format(v) end
)
end
local artist = ''
local artist_list = CALv2[artistName]
if artist_list then
if artist_list.__FullData__ then
for _, data in ipairs(artist_list.__FullData__) do
local display_ja = formatJapaneseText(data.display)
if data.link then
artist = artist .. (display_ja and link('曲师列表#' .. data.link, display_ja) or '')
else
artist = artist .. (display_ja or '')
end
end
else
artist = artistName
for theLink, display in pairs(artist_list) do
if type(display)=='string' then
local display_ja = formatJapaneseText(display)
artist = string.gsub(artist, display, display_ja and link('曲师列表#' .. theLink, display_ja) or '')
elseif type(display)=='table' then
for _,d in pairs(display) do
local d_ja = formatJapaneseText(d)
artist = string.gsub(artist, d, d_ja and link('曲师列表#' .. theLink, d_ja) or '')
end
end
end
end
else
artist = formatJapaneseText(artistName)
artist = link('曲师列表#' .. artistName, artist)
end
return artist
end
function p.artistLinkFrame(frame)
local name
if frame and frame.args[1] then
name = frame.args[1]
else
return ''
end
local al = p.artistLink(name)
return al
end
function p.packLink(packName, short, ns)
-- 曲包名称转换成链接
-- short
-- true 简短(x Collaboration y)
-- false 完整(x Collaboration - Collaboration y)
-- ns 适用于Arcaea和Memory Archive曲包
-- true NS版曲包
-- false 移动版曲包
local discrete_pack = {['Arcaea']='曲包', ['Memory Archive']=''}
-- 分离双平台页的曲包,value为后缀附加内容: '曲包'->' (xx版曲包)' ; ''->' (xx版)'
local cc = 'Collaboration %- Collaboration'
local ccl = 'Collaboration#Collaboration'
local linkFlag = ''
if discrete_pack[packName] then
if ns then
linkFlag = (' (NS版%s)'):format(discrete_pack[packName])
else
linkFlag = (' (移动版%s)'):format(discrete_pack[packName])
end
end
local packLink = string.gsub(packName, cc, ccl) .. linkFlag
local packDisplay
if short then
local ccd = 'Collaboration'
packDisplay = string.gsub(packName, cc, ccd)
else
packDisplay = packName
end
local pack = link(packLink, packDisplay)
return pack
end
function p.packLinkFrame(frame)
if frame then
local name = frame.args['name'] or nil
local short = frame.args['short'] or nil
local ns = frame.args['ns'] or nil
return p.packLink(name, short, ns)
else
return 'none'
end
end
return p