跳转到内容

模組:VGNL

维基百科,自由的百科全书

这是本页的一个历史版本,由Lopullinen留言 | 贡献2023年3月17日 (五) 16:33编辑。这可能和当前版本存在着巨大的差异。

require('strict')

local p = {}
local getArgs = require('Module:Arguments').getArgs
local function makeInvokeFunc(funcName)
    return function(frame)
        local args = getArgs(frame)
        return p[funcName](args)
    end
end

p.target = makeInvokeFunc('_target')
function p._target(args)
    local cur_date = '00000000'
    local text = mw.title.new('WikiProject:電子遊戲/簡訊/目錄'):getContent()
    local published_dates = text:gmatch('data%-sort%-value%s*=%s*"(%d%d%d%d%d%d%d%d)"')
    for v in published_dates do
        if (v > cur_date) and (v < '29999999') then
            cur_date = v
        end
    end
    local issue = cur_date:sub(1, 4) .. '-' .. cur_date:sub(5, 6)
    return 'WikiProject:電子遊戲/簡訊/' .. issue
end

p.label = makeInvokeFunc('_label')
function p._label(args)
    local target = p._target(args)
    local text = mw.title.new(target):getContent()
    return text:match('%d%d%d%d年第.-季')
end

p.link = makeInvokeFunc('_link')
function p._link(args)
    local target = p._target(args)
    local label = p._label(args)
    return '[[' .. target .. '|' .. label .. ']]'
end

p.content = makeInvokeFunc('_content')
function p._content(args)
    local target = p._target(args)
    return mw.getCurrentFrame():expandTemplate { title = target }
end

p.toc = makeInvokeFunc('_toc')
function p._toc(args)
    local target = p._target(args)
    local text = mw.title.new(target):getContent()

    local items = {}
    local pattern = mw.ustring.gsub(target, 'WikiProject:', '維基專題:')
    pattern = '%[%[' .. mw.ustring.gsub(pattern, '%-', '%-') .. '/.-|.-%]%]'
    local pos = 1

    mw.log(mw.ustring.find(text, pattern, pos))
    while true do
        local s, e = mw.ustring.find(text, pattern, pos, false)
        if s == nil then
            break
        end
        table.insert(items, '*' .. mw.ustring.sub(text, s, e))
        pos = e + 1
    end

    return table.concat(items, '\n')
end
return p