模組:Recent Records in New Page
外观
本模组可截取专题新进条目页的近若干日记录,可用于专题首页等处,以免完整新条目列表屠版。
例子
[编辑]截取Portal:动漫/新进条目最近5日记录:
{{#invoke:Recent Records in New Page|main|5|page=Portal:动漫/新进条目}}
效果:
已知问题
[编辑]- 新進頁面不能有其他點列語法,否則本模組可能輸出不期待的結果,如此例。其他點列可考慮使用{{Bulleted list}}等模板生成。
--- Fetch recent new page records for the last n days.
---
--- All first-level unordered list items are considered (i.e., lines
--- that begin with ``*`` and are not immediately followed by another
--- ``*``). Bullet items other than new page records should use
--- ``{{Bulleted list}}`` or so for handling.
require("strict")
local getArgs = require("Module:Arguments").getArgs
--- Filter the first n lines of first-level unordered list items.
--- @param text string @Wikitext to filter.
--- @param n number @Maximum number of lines to keep.
--- @return string @Filtered and parsed Wikitext.
local function filter_n(text, n)
local lines = {}
for line in mw.text.gsplit(text, "\n", true) do
if n <= 0 then
break
end
if mw.ustring.find(line, "^%*%f[^*]") then
table.insert(lines, line)
n = n - 1
end
end
local raw_code = table.concat(lines, "\n")
return mw.getCurrentFrame():preprocess(raw_code)
end
local p = {}
local function makeInvokeFunc(funcName)
return function(frame)
local args = getArgs(frame)
return p[funcName](args)
end
end
p.main = makeInvokeFunc("_main")
function p._main(args)
local text = mw.title.new(args.page):getContent()
local n = tonumber(args[1])
return filter_n(text, n)
end
return p