local p = {}
local getArgs = require('Module:Arguments').getArgs
local splitString = require('Module:Split2')
function p._main(args, frame)
local input = args[1] or ''
local ft = args.ft
local hairParts = splitString.split(input, '$', false)
local hairColor = hairParts.parts[1] or ''
local hairNote = hairParts.parts[2] or ''
local processed = hairColor
-- 截取第一个"["之前的内容
local bracketPos = mw.ustring.find(processed, "%[")
if bracketPos then
processed = mw.text.trim(mw.ustring.sub(processed, 1, bracketPos - 1))
end
hairColor = processed
--processed = hairColor
local multiColors = {
["双色"] = true, ["雙色"] = true, ["多色"] = true,
["混色"] = true, ["渐变色"] = true, ["漸變色"] = true
}
-- 预处理
--local processed = hairColor
if not multiColors[hairColor] then
local lastChar = mw.ustring.sub(hairColor, -1)
if lastChar == "发" or lastChar == "髮" or lastChar == "髪" or lastChar == "色" then
processed = mw.ustring.sub(hairColor, 1, -2) -- 去掉最后一个字
end
end
-- 修饰词
local modifiers = {
["浅"] = true, ["淺"] = true, ["深"] = true, ["亮"] = true,
["暗"] = true, ["浓"] = true, ["濃"] = true, ["淡"] = true,
["黑"] = true, ["灰"] = true, ["银"] = true, ["銀"] = true,
["碧"] = true, ["墨"] = true
}
local coreColor = processed
if not multiColors[hairColor] then
local firstChar = mw.ustring.sub(processed, 1, 1)
if modifiers[firstChar] and mw.ustring.len(processed) > 1 then
coreColor = mw.ustring.sub(processed, 2)
end
end
local colorMap = {
-- 粉
["粉"] = "粉发", ["粉紅"] = "粉发", ["粉红"] = "粉发", ["棕粉"] = "粉发",
["洋紅"] = "粉发", ["洋红"] = "粉发", ["樱"] = "粉发", ["櫻"] = "粉发",
["桃"] = "粉发", ["粉白"] = "粉发", ["桃紅"] = "粉发", ["桃红"] = "粉发",
-- 红
["绯"] = "红发", ["緋"] = "红发", ["赤"] = "红发", ["紅"] = "红发",
["红"] = "红发", ["酒红"] = "红发", ["酒紅"] = "红发", ["血紅"] = "红发",
["血红"] = "红发", ["珊红"] = "红发", ["珊紅"] = "红发",
-- 紫
["紫"] = "紫发", ["黛紫"] = "紫发", ["靛"] = "紫发", ["雪青"] = "紫发",
["雪靑"] = "紫发", ["紫藤"] = "紫发", ["紫紅"] = "紫发", ["紫红"] = "紫发",
["紫蓝"] = "紫发", ["紫藍"] = "紫发",
-- 蓝
["青"] = "蓝发", ["靑"] = "蓝发", ["藏青"] = "蓝发", ["藏靑"] = "蓝发",
["藍"] = "蓝发", ["蓝"] = "蓝发", ["天蓝"] = "蓝发", ["天藍"] = "蓝发",
["水蓝"] = "蓝发", ["水藍"] = "蓝发", ["青蓝"] = "蓝发", ["靑藍"] = "蓝发",
["海蓝"] = "蓝发", ["海藍"] = "蓝发",
-- 绿
["綠"] = "绿发", ["绿"] = "绿发", ["黃綠"] = "绿发", ["黄绿"] = "绿发",
["灰綠"] = "绿发", ["灰绿"] = "绿发", ["墨綠"] = "绿发", ["墨绿"] = "绿发",
["草綠"] = "绿发", ["草绿"] = "绿发", ["靑綠"] = "绿发", ["青绿"] = "绿发",
-- 金
["金"] = "金发", ["黃"] = "金发", ["黄"] = "金发", ["金黃"] = "金发",
["金黄"] = "金发", ["米"] = "金发", ["米黃"] = "金发", ["米黄"] = "金发",
["奶黄"] = "金发", ["奶黃"] = "金发", ["亞麻"] = "金发", ["亚麻"] = "金发",
-- 橙
["橘"] = "橙发", ["橙"] = "橙发", ["桔"] = "橙发", ["桔黃"] = "橙发",
["桔黄"] = "橙发", ["橘黃"] = "橙发", ["橘黄"] = "橙发", ["橙黄"] = "橙发",
["橙黃"] = "橙发", ["橘红"] = "橙发", ["橘紅"] = "橙发", ["橙紅"] = "橙发",
["橙红"] = "橙发", ["珊瑚"] = "橙发",
-- 棕
["褐"] = "棕发", ["棕"] = "棕发", ["棕褐"] = "棕发", ["棕黃"] = "棕发",
["棕黄"] = "棕发", ["棕红"] = "棕发", ["棕紅"] = "棕发", ["褐绿"] = "棕发",
["褐綠"] = "棕发", ["褐红"] = "棕发", ["红褐"] = "棕发", ["褐紅"] = "棕发",
["紅褐"] = "棕发", ["亞麻棕"] = "棕发", ["亚麻棕"] = "棕发", ["棕黑"] = "棕发",
["棕綠"] = "棕发", ["棕绿"] = "棕发", ["栗"] = "棕发", ["肉"] = "棕发",
["茶"] = "棕发", ["古铜"] = "棕发", ["古銅"] = "棕发", ["咖啡"] = "棕发",
["卡其"] = "棕发",
-- 黑
["黑"] = "黑发", ["藍黑"] = "黑发", ["蓝黑"] = "黑发",
-- 银
["白"] = "银发", ["灰"] = "银发", ["紫白"] = "银发", ["銀"] = "银发",
["银"] = "银发", ["銀灰"] = "银发", ["银灰"] = "银发", ["銀白"] = "银发",
["银白"] = "银发", ["白銀"] = "银发", ["白银"] = "银发", ["鐵灰"] = "银发",
["铁灰"] = "银发",
-- 其他
["虹"] = "彩虹发", ["彩虹"] = "彩虹发",
["双"] = "双色发", ["雙"] = "双色发", ["双色"] = "双色发", ["雙色"] = "双色发",
["阴阳"] = "阴阳发", ["陰陽"] = "阴阳发",
["多"] = "多色发", ["混"] = "多色发", ["多色"] = "多色发", ["混色"] = "多色发",
["渐变"] = "渐变色发", ["漸變"] = "渐变色发", ["渐变色"] = "渐变色发", ["漸變色"] = "渐变色发"
}
local category = colorMap[coreColor]
if category then
local displayText = processed .. "髮"
local categoryTemplate = frame:expandTemplate{title = "ArticleCategory", args = {category}}
return string.format("[[%s|%s]]%s%s", category, displayText, hairNote, categoryTemplate)
else
local lastChar = mw.ustring.sub(coreColor, -1)
local mappedChar = lastChar
local charMap = {
["灰"] = "银", ["白"] = "银",
["黄"] = "金", ["黃"] = "金",
["茶"] = "棕", ["褐"] = "棕"
}
if charMap[lastChar] then
mappedChar = charMap[lastChar]
end
local testCategory = mappedChar .. "发"
local title = mw.title.new(testCategory)
if title.exists then
local displayText = processed .. "髮"
local categoryTemplate = frame:expandTemplate{title = "ArticleCategory", args = {testCategory}}
return string.format("[[%s|%s]]%s%s", testCategory, displayText, hairNote, categoryTemplate)
else
if ft then
return processed .. "髮" .. hairNote
else
local categoryTemplate = frame:expandTemplate{title = "ArticleCategory", args = {"错误发色"}}
return processed .. "髮" .. hairNote .. categoryTemplate
end
end
end
end
function p.main(frame)
local args = getArgs(frame, {
parentFirst = true,
})
return p._main(args, frame)
end
return p