Модуль:FetchData7: відмінності між версіями
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування Мітка: Скасовано |
||
| Рядок 1: | Рядок 1: | ||
local p = {} | 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) | local title = mw.title.new(page_name) | ||
if not title or not title.exists then | if not title or not title.exists then | ||
return "" | |||
return | |||
end | end | ||
local content = title:getContent() | local content = title:getContent() | ||
if not content then | if not content then | ||
return "" | return "" | ||
| Рядок 36: | Рядок 16: | ||
local sections = {} | local sections = {} | ||
local num = 0 | |||
for | 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 | if mw.ustring.match(clean_name, "Записи ігор") and games then | ||
display = clean_name .. " (" .. games .. ")" | |||
anchor = clean_name .. "_(" .. games .. ")" | |||
end | end | ||
table.insert(sections, { | |||
num = num, | |||
display = display, | |||
anchor = mw.ustring.gsub(anchor, " ", "_") | |||
}) | |||
end | end | ||
end | end | ||
| Рядок 64: | Рядок 47: | ||
end | 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 .. ']]' | |||
for | html = html .. '</li>' | ||
end | end | ||
html = html .. '</ul>' | |||
html = html .. '</nav>' | |||
return | return html | ||
end | end | ||
return p | return p | ||
Версія за 19:32, 8 грудня 2025
Документацію для цього модуля можна створити у Модуль: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