Module:ComicInfoboxWikitext:修订间差异

来自有兽档案馆
(// Edit via Wikiplus)
标签已被回退
(撤销Baigei讨论)的版本33750)
标签撤销
第27行: 第27行:
end
end
local function fillInfobox(data, episode)
local function fillInfobox(data, episode)
-- 用漫画数据生成信息框
local function argsCheck(args, frame)
local noticetext = ''
if args['color'] == nil then
noticetext = noticetext .. '<li>此信息框缺少背景色,请添加<code>color</code>参数。</li>'
end
if args['title_weibo'] == nil then
noticetext = noticetext .. '<li>此信息框缺少微博标题,请添加<code>title_weibo</code>参数。</li>'
end
if args['title_bili'] == nil then
noticetext = noticetext .. '<li>此信息框缺少B漫标题,请添加<code>title_bili</code>参数。</li>'
end
if args['episode'] == nil then
noticetext = noticetext .. '<li>此信息框缺少时间线,请添加<code>episode</code>参数。</li>'
end
if args['date_weibo'] == nil then
noticetext = noticetext .. '<li>此信息框缺少微博发布时间,请添加<code>date_weibo</code>参数。</li>'
end
if args['date_bili'] == nil then
noticetext = noticetext .. '<li>此信息框缺少B漫发布时间,请添加<code>date_bili</code>参数。</li>'
end


return '<table class="mw-collapsible mw-collapsed wikitable"><tr><th>' ..
'信息框提示' .. '</th></tr><tr><td>' .. noticetext .. '</td></tr></table>'
end

local frame = mw.getCurrentFrame()
local res = ''

-- 补上前后话数据
if data['next'] == nil then
data['next'] = '[[第' .. episode+1 .. '话]]'
end
if data['last'] == nil then
data['last'] = '[[第' .. episode-1 .. '话]]'
end

--检查缺失数据
local args = {
local args = {
color = data['color'] ,
number = data and data['number'] or ' ',
title_weibo = data['title_weibo'],
color = data and data['color'] or ' ',
title_bili = data['title_bili'],
title_weibo = data and data['title_weibo'] or ' ',
episode = data['episode'],
title_bili = data and data['title_bili'] or ' ',
date_weibo = data['date_weibo'],
episode = data and data['episode'] or ' ',
date_bili = data['date_bili'],
date_weibo = data and data['date_weibo'] or ' ',
number = episode
date_bili = data and data['date_bili'] or ' ',
number = data and episode or ' '
}
}
local noticetext = argsCheck(args, frame)


local res = {}
local text = ''
local frame = mw.getCurrentFrame()


-- 漫画数据生成信息框
res[#res + 1] = frame:expandTemplate { title = 'nowiki', args = { '{{漫画信息框' } }
local infobox_args = {
for key, value in pairs(args) do
name='漫画信息框',
res[#res + 1] = '<br>'
bodystyle='border-radius: 10px',
text = '\n|' .. key .. '=' .. value
title='本话信息',
res[#res + 1] = frame:expandTemplate { title = 'nowiki', args = { text } }
header1 = '基本信息',
label2 = '话数',
data2 = '[[ComicInfo:number::'..data['number']..']]',
label3 = '微博标题',
data3 = '[[ComicInfo:titleWeibo::'..data['title_weibo']..']]',
label4 = 'B漫标题',
data4 = '[[ComicInfo:titleBili::'..data['title_bili']..']]',
label5 = '所属篇目',
data5 = '[[ComicInfo:episode::'..data['episode']..']]',
label6 = '微博发布日期',
data6 = '[[ComicInfo:dateWeibo::'..data['date_weibo']..']]',
label7 = 'B漫发布日期',
data7 = '[[ComicInfo:dateBili::'..data['date_bili']..']]',
header8 = '阅读向导',
label9 = '上一话',
data9 = data['last'],
label10 = '下一话',
data10 = data['next']
}
res = res .. mw.getCurrentFrame():expandTemplate { title = 'Infobox', args = infobox_args }

if noticetext ~= '' then
res = res .. noticetext
end
end
res[#res + 1] = frame:expandTemplate { title = 'nowiki', args = { '}}' } }

return res
return table.concat(res)
--return mw.getCurrentFrame():expandTemplate { title = 'Infobox', args = args }
end
end



2023年8月24日 (四) 15:29的版本

文档图示 模块文档[创建] [跳转到代码]

本模块还没有文档页面。

您可以创建文档以让编者更好地理解本模块的用途。
编者可以在本模块的沙盒创建 | 镜像和测试样例创建页面进行实验。
请将模块自身所属的分类添加在文档中。本模块的子页面
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 and data['number'] or ' ',
            color = data and data['color'] or ' ',
            title_weibo = data and data['title_weibo'] or ' ',
            title_bili = data and  data['title_bili'] or ' ',
            episode = data and data['episode'] or ' ',
            date_weibo = data and  data['date_weibo'] or ' ',
            date_bili = data and  data['date_bili'] or ' ',
            number = data and episode or ' '
        }

        local res = {}
        local text = ''
        local frame = mw.getCurrentFrame()

        res[#res + 1] = frame:expandTemplate { title = 'nowiki', args = { '{{漫画信息框' } }
        for key, value in pairs(args) do
            res[#res + 1] = '<br>'
            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