Modul:Page
Vzhled
Dokumentaci tohoto modulu lze vytvořit na stránce Nápověda:Modul:Page
-- Modul:Page
-- Pomocné funkce pro práci s obsahem aktuální stránky
-- Autor: ChatGPT (pro české Wikizdroje)
-- Funkce:
-- #invoke:Page|hasTemplate|NavigacePaP
-- #invoke:Page|getTemplateParameter|NavigacePaP|PŘEDCHOZÍ
local p = {}
local function getContent()
local title = mw.title.getCurrentTitle()
if not title then return "" end
local ok, content = pcall(function() return title:getContent() end)
if ok and content then return content else return "" end
end
function p.hasTemplate(frame)
local args = frame.args
local template = args[1]
if not template or template == "" then return "" end
local content = getContent()
if not content then return "" end
local pattern = "{{%s*" .. mw.ustring.lower(template)
local text = mw.ustring.lower(content)
if mw.ustring.find(text, pattern) then
return "1"
else
return ""
end
end
function p.getTemplateParameter(frame)
local args = frame.args
local template = args[1]
local param = args[2]
if not template or not param then return "" end
local content = getContent()
if not content then return "" end
-- Regulární výraz (case-insensitive)
local lowered = mw.ustring.lower(content)
local pattern = "{{%s*" .. mw.ustring.lower(template) .. "[^}]*|%s*" .. mw.ustring.lower(param) .. "%s*=%s*([^|}]*)"
local match = mw.ustring.match(lowered, pattern)
if match then
local trimmed = mw.text.trim(match)
if trimmed ~= "" then
return trimmed
end
end
return ""
end
return p