Модуль:FetchData2: відмінності між версіями
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 48: | Рядок 48: | ||
end | end | ||
-- Будуємо HTML вручну | |||
local html_parts = {} | |||
table.insert(html_parts, '<div class="l-box" style="position:fixed; top:20px; left:20px; z-index:100; border-radius:16px; background-color:#23232c; width:220px; box-sizing:border-box; overflow:hidden;">') | |||
-- Заголовок | |||
table.insert(html_parts, '<div style="padding:15px 20px; font-weight:bold; font-size:15px; color:#fff; border-bottom:1px solid rgba(255,255,255,0.1);">Зміст</div>') | |||
-- Пункти меню | |||
for i, section in ipairs(sections) do | for i, section in ipairs(sections) do | ||
local anchor = mw.ustring.gsub(section, " ", "_") | local anchor = mw.ustring.gsub(section, " ", "_") | ||
local | local border = "" | ||
if i < #sections then | if i < #sections then | ||
border = "border-bottom:1px solid rgba(255,255,255,0.05);" | |||
end | end | ||
table.insert(html_parts, string.format( | |||
'<div class="l-box-item" style="padding:12px 20px; %s">[[#%s|%s]]</div>', | |||
border, anchor, section | |||
)) | |||
end | end | ||
return | table.insert(html_parts, '</div>') | ||
return table.concat(html_parts, '\n') | |||
end | end | ||
return p | return p | ||
Версія за 09:15, 8 грудня 2025
Документацію для цього модуля можна створити у Модуль:FetchData2/документація
local p = {}
-- ================================================
-- КЕШУВАННЯ
-- ================================================
local page_cache = {}
local function get_page_content(page_name)
if page_cache[page_name] then
return page_cache[page_name]
end
local title = mw.title.new(page_name)
if not title or not title.exists then
page_cache[page_name] = nil
return nil
end
local content = title:getContent()
page_cache[page_name] = content
return content
end
-- ================================================
-- АВТОМАТИЧНЕ МЕНЮ СЕКЦІЙ
-- ================================================
function p.section_menu(frame)
local page_name = frame.args.page or mw.title.getCurrentTitle().text
local content = get_page_content(page_name)
if not content then
return ""
end
local sections = {}
for section_name in mw.ustring.gmatch(content, "\n==%s*([^=]+)%s*==") do
section_name = mw.text.trim(section_name)
if section_name ~= "" then
table.insert(sections, section_name)
end
end
if #sections == 0 then
return ""
end
-- Будуємо HTML вручну
local html_parts = {}
table.insert(html_parts, '<div class="l-box" style="position:fixed; top:20px; left:20px; z-index:100; border-radius:16px; background-color:#23232c; width:220px; box-sizing:border-box; overflow:hidden;">')
-- Заголовок
table.insert(html_parts, '<div style="padding:15px 20px; font-weight:bold; font-size:15px; color:#fff; border-bottom:1px solid rgba(255,255,255,0.1);">Зміст</div>')
-- Пункти меню
for i, section in ipairs(sections) do
local anchor = mw.ustring.gsub(section, " ", "_")
local border = ""
if i < #sections then
border = "border-bottom:1px solid rgba(255,255,255,0.05);"
end
table.insert(html_parts, string.format(
'<div class="l-box-item" style="padding:12px 20px; %s">[[#%s|%s]]</div>',
border, anchor, section
))
end
table.insert(html_parts, '</div>')
return table.concat(html_parts, '\n')
end
return p