小 (// Edit via Wikiplus) 标签:手工回退 |
小 (// Edit via Wikiplus) |
||
第40行: | 第40行: | ||
} |
} |
||
local |
local res = '' |
||
local text = '' |
|||
local frame = mw.getCurrentFrame() |
|||
res[#res+1] = frame:expandTemplate { title = 'nowiki', args = {'{{漫画信息框'} } |
|||
for key, value in pairs(args) do |
for key, value in pairs(args) do |
||
text = '\n|'..key..'='..value |
|||
res[#res+1] = frame:expandTemplate { title = 'nowiki', args = {text} } |
|||
end |
end |
||
res[#res+1] = frame:expandTemplate { title = 'nowiki', args = {'}}'}} |
|||
return |
return table.concat(res) |
||
--return mw.getCurrentFrame():expandTemplate { title = 'Infobox', args = args } |
--return mw.getCurrentFrame():expandTemplate { title = 'Infobox', args = args } |
||
end |
end |
2023年8月23日 (三) 22:38的版本
local p = {}
local getArgs = require('Module:Arguments').getArgs
function p.main(frame)
local args = getArgs(frame)
local function getComicData(episode)
-- 去ComicData.json获取漫画数据
local comicList = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate { title = '漫画信息框/ComicData.json' })
return comicList[episode]
end
local function margeData(data_from_json, data_from_args)
-- 用模板数据替换自动获取的数据
local data = {}
for k, v in pairs(data_from_json) do
data[k] = v
end
for k, v in pairs(data_from_args) do
if v ~= '' then
-- 当模板数据为空值时 使用自动获取的数据
data[k] = v
end
end
return data
end
local function fillInfobox(data, episode)
-- 用漫画数据生成信息框
local args = {
number = data['number'],
color = data['color'],
title_weibo = data['title_weibo'],
title_bili = data['title_bili'],
episode = data['episode'],
date_weibo = data['date_weibo'],
date_bili = data['date_bili'],
number = episode
}
local res = ''
local text = ''
local frame = mw.getCurrentFrame()
res[#res+1] = frame:expandTemplate { title = 'nowiki', args = {'{{漫画信息框'} }
for key, value in pairs(args) do
text = '\n|'..key..'='..value
res[#res+1] = frame:expandTemplate { title = 'nowiki', args = {text} }
end
res[#res+1] = frame:expandTemplate { title = 'nowiki', args = {'}}'}}
return table.concat(res)
--return mw.getCurrentFrame():expandTemplate { title = 'Infobox', args = args }
end
-- 默认输出第一话的信息框
local episode = 1
-- 获取话数
if args[1] ~= nil then
episode = tonumber(args[1])
end
if args['number'] ~= nil then
episode = tonumber(args['number'])
end
local episodeData_autoFill = getComicData(episode)
local episodeData = margeData(episodeData_autoFill, args)
return fillInfobox(episodeData, episode)
end
return p