模块:少女前线图鉴图
来自OGAS数据中枢
更多操作
此模块的文档可以在Module:少女前线图鉴图/doc创建
local p = {}
local cache = {}
local function exists(name)
local ok, t = pcall(mw.title.new, "File:" .. name)
if not ok or not t then
return false
end
return t.fileExists == true
end
-- 把图鉴里引用的缩略图名(Pic_XXX_S.jpg)解析成本站真实存在的文件:
-- 先看原名,再退回 <base>.png / <base>_N.png。
function p.file(frame)
local raw = frame.args[1]
if not raw then
return ''
end
local name = mw.text.trim(raw)
if name == '' then
return ''
end
if cache[name] ~= nil then
return cache[name]
end
local out = name
if not exists(name) then
local base = name:gsub('_S%.[%a]+$', '')
local cands = { base .. '.png', base .. '_N.png' }
for _, c in ipairs(cands) do
if exists(c) then
out = c
break
end
end
end
cache[name] = out
return out
end
return p