Modul:Archívum nav
Megjelenés
Archívum nav[mi ez?] • [dokumentáció: mutat, ] • [tesztek: létrehozás]
require('strict')
local p = {}
local getArgs = require('Modul:Arguments').getArgs
function p.main(frame)
local args = getArgs(frame)
local title = args[1] or tostring(mw.title.getCurrentTitle())
local prefix, n = title:match('(.-[Aa]rchív.-)(%d+)$')
if not n then
return nil
end
local pattern = '%0' .. n:len() .. 'd'
n = tonumber(n)
local m = math.max(n + 6, 12)
local prevTarget = prefix .. pattern:format(n - 1)
local nextTarget = prefix .. pattern:format(n + 1)
if (n == 10 or n == 100) and not mw.title.new(prefix .. pattern:format(n - 1)).exists then
prevTarget = prefix .. (n - 1)
end
local i = n + 1
title = mw.title.new(prefix .. pattern:format(i))
while i < m and title.exists do
n = i
i = i + 1
title = mw.title.new(prefix .. pattern:format(i))
end
m = math.max(0, n - 11)
local pages = ''
while n > m do
if n == 9 or n == 99 then
title = mw.title.new(prefix .. pattern:format(n))
if not title.exists then
pattern = '%d'
end
end
pages = '[[' .. prefix .. pattern:format(n) .. '|' .. n .. ']] ' .. pages
n = n - 1
end
return ([=[<hr><div style="display:flex">
<div style="width:14ch">[[%s|« előző]]</div>
<div style="width:100%%; text-align:center">%s</div>
<div style="width:14ch; text-align:right">[[%s|következő »]]</div>
</div>]=]):format(prevTarget, pages, nextTarget)
end
return p