5261
редагування
Admin (обговорення | внесок) (Сторінка очищена) Мітка: Очищення |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 1: | Рядок 1: | ||
-- ================================================ | |||
-- АВТОМАТИЧНЕ МЕНЮ СЕКЦІЙ | |||
-- ================================================ | |||
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 | |||
local html = mw.html.create('div') | |||
:addClass('l-box') | |||
:css('position', 'fixed') | |||
:css('top', '20px') | |||
:css('left', '20px') | |||
:css('z-index', '100') | |||
:css('border-radius', '16px') | |||
:css('background-color', '#23232c') | |||
:css('width', '220px') | |||
:css('box-sizing', 'border-box') | |||
:css('overflow', 'hidden') | |||
-- Заголовок меню | |||
html:tag('div') | |||
:css('padding', '15px 20px') | |||
:css('font-weight', 'bold') | |||
:css('font-size', '15px') | |||
:css('color', '#fff') | |||
:css('border-bottom', '1px solid rgba(255,255,255,0.1)') | |||
:wikitext('Зміст') | |||
-- Пункти меню | |||
for i, section in ipairs(sections) do | |||
local anchor = mw.ustring.gsub(section, " ", "_") | |||
local link = html:tag('a') | |||
:attr('href', '#' .. anchor) | |||
:css('display', 'block') | |||
:css('padding', '12px 20px') | |||
:css('color', '#ccc') | |||
:css('text-decoration', 'none') | |||
:wikitext(section) | |||
if i < #sections then | |||
link:css('border-bottom', '1px solid rgba(255,255,255,0.05)') | |||
end | |||
end | |||
return tostring(html) | |||
end | |||