模組:VGNL
外观
![]() | 此模块使用Lua语言: |
本模组可生成最新出刊的《电子游戏专题简讯》页面名和标签。
示例
{{#invoke:VGNL|link}}
⇒ 第30行Lua错误:attempt to index local 'text' (a nil value){{#invoke:VGNL|target|upcoming}}
⇒ WikiProject:電子遊戲/簡訊/0000-00{{#invoke:VGNL|date|2024-01}}
⇒ 脚本错误:函数“date”不存在。{{#invoke:VGNL|toc|style=inline}}
⇒ Lua错误:bad argument #1 to 'find' (string expected, got nil)。{{#invoke:VGNL|toc}}
⇒ (以点列生成上方内容){{#invoke:VGNL|index}}
⇒ (生成简讯的目录表)
目录
資料定義於子模組Module:VGNL/items。
脚本错误:函数“index”不存在。
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