Документацію для цього модуля можна створити у Модуль:FetchData7/документація
local p = {}
function p.section_menu(frame)
local page_name = frame.args.page or mw.title.getCurrentTitle().text
local games = frame.args.games
local title = mw.title.new(page_name)
if not title or not title.exists then
return ""
end
local content = title:getContent()
if not content then
return ""
end
local sections = {}
local num = 0
for section_name in mw.ustring.gmatch(content, "\n==%s*([^=]+)%s*==") do
section_name = mw.text.trim(section_name)
local clean_name = mw.ustring.gsub(section_name, "%{%{.-%}%}", "")
clean_name = mw.ustring.gsub(clean_name, "%s*%(%s*%)%s*", "")
clean_name = mw.text.trim(clean_name)
if clean_name ~= "" then
num = num + 1
local display = clean_name
local anchor = clean_name
if mw.ustring.match(clean_name, "Записи ігор") and games then
display = clean_name .. " (" .. games .. ")"
anchor = clean_name .. "_(" .. games .. ")"
end
table.insert(sections, {
num = num,
display = display,
anchor = mw.ustring.gsub(anchor, " ", "_")
})
end
end
if #sections == 0 then
return ""
end
local html = '<nav class="toc-sidebar">'
html = html .. '<div class="toc-title">Зміст</div>'
html = html .. '<ul class="toc-list">'
for _, section in ipairs(sections) do
html = html .. '<li class="toc-item">'
html = html .. '<span class="toc-number">' .. section.num .. '</span>'
html = html .. '[[#' .. section.anchor .. '|' .. section.display .. ']]'
html = html .. '</li>'
end
html = html .. '</ul>'
html = html .. '</nav>'
return html
end
return p