Модуль: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 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 "" | ||
| Рядок 63: | Рядок 16: | ||
local sections = {} | local sections = {} | ||
for | for section_name in mw.ustring.gmatch(content, "\n==%s*([^=]+)%s*==") do | ||
section_name = mw.text.trim(section_name) | |||
section_name = mw.ustring.gsub(section_name, "%{%{.-%}%}", "") | |||
section_name = mw.ustring.gsub(section_name, "%s*%(.-%)", "") | |||
section_name = mw.text.trim(section_name) | |||
if section_name ~= "" then | |||
table.insert(sections, section_name) | |||
end | end | ||
end | end | ||
| Рядок 106: | Рядок 31: | ||
end | end | ||
local | local html = '<div class="l-box" style="position:fixed; top:20px; left:20px; z-index:100; border-radius:16px; background-color:#23232c; width:220px; overflow:hidden;">' | ||
html = html .. '<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, | for i, name in ipairs(sections) do | ||
local anchor = mw.ustring.gsub(name, " ", "_") | |||
local border = "" | local border = "" | ||
if i < #sections then | if i < #sections then | ||
border = "border-bottom:1px solid rgba(255,255,255,0.05);" | border = "border-bottom:1px solid rgba(255,255,255,0.05);" | ||
end | end | ||
html = html .. '<div class="l-box-item" style="padding:12px 20px;' .. border .. '">[[#' .. anchor .. '|' .. name .. ']]</div>' | |||
end | end | ||
html = html .. '</div>' | |||
return | return html | ||
end | end | ||
return p | return p | ||
Версія за 19:20, 8 грудня 2025
Документацію для цього модуля можна створити у Модуль:FetchData7/документація
local p = {}
function p.section_menu(frame)
local page_name = frame.args.page or mw.title.getCurrentTitle().text
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 = {}
for section_name in mw.ustring.gmatch(content, "\n==%s*([^=]+)%s*==") do
section_name = mw.text.trim(section_name)
section_name = mw.ustring.gsub(section_name, "%{%{.-%}%}", "")
section_name = mw.ustring.gsub(section_name, "%s*%(.-%)", "")
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 = '<div class="l-box" style="position:fixed; top:20px; left:20px; z-index:100; border-radius:16px; background-color:#23232c; width:220px; overflow:hidden;">'
html = html .. '<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, name in ipairs(sections) do
local anchor = mw.ustring.gsub(name, " ", "_")
local border = ""
if i < #sections then
border = "border-bottom:1px solid rgba(255,255,255,0.05);"
end
html = html .. '<div class="l-box-item" style="padding:12px 20px;' .. border .. '">[[#' .. anchor .. '|' .. name .. ']]</div>'
end
html = html .. '</div>'
return html
end
return p