6369
редагувань
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| (Не показано 13 проміжних версій цього користувача) | |||
| Рядок 1: | Рядок 1: | ||
local p = {} | local p = {} | ||
local page_cache = {} | local page_cache = {} | ||
| Рядок 20: | Рядок 19: | ||
local function get_section_content(content, section_start) | local function get_section_content(content, section_start) | ||
local | local section_end = mw.ustring.find(content, "\n==[^=]", section_start + 1) | ||
if | |||
return mw.ustring.sub(content, section_start, | if section_end then | ||
return mw.ustring.sub(content, section_start, section_end - 1) | |||
else | else | ||
return mw.ustring.sub(content, section_start) | return mw.ustring.sub(content, section_start) | ||
| Рядок 28: | Рядок 28: | ||
end | end | ||
local function | local function count_facts(section_content) | ||
local count = 0 | local count = 0 | ||
for | for line in mw.ustring.gmatch(section_content, "[^\n]+") do | ||
count = count + 1 | if mw.ustring.match(line, "^%*[^%*]") then | ||
count = count + 1 | |||
end | |||
end | end | ||
return count | |||
return | |||
end | end | ||
local function | local function count_awards(section_content) | ||
local count = 0 | local count = 0 | ||
for _ in mw.ustring.gmatch(section_content, " | for _ in mw.ustring.gmatch(section_content, "%[%[File:[^%]]+%.png") do | ||
count = count + 1 | count = count + 1 | ||
end | end | ||
return count | return count | ||
end | |||
-- Секції, які треба ігнорувати в меню | |||
local function should_skip_section(section_name) | |||
local skip_patterns = { | |||
"Записи ігор", | |||
"Ігри гравця" | |||
} | |||
for _, pattern in ipairs(skip_patterns) do | |||
if mw.ustring.match(section_name, pattern) then | |||
return true | |||
end | |||
end | |||
return false | |||
end | end | ||
| Рядок 62: | Рядок 71: | ||
local sections = {} | local sections = {} | ||
table.insert(sections, { | |||
display = "Біографія", | |||
anchor = "top" | |||
}) | |||
for line in mw.ustring.gmatch(content, "[^\n]+") do | for line in mw.ustring.gmatch(content, "[^\n]+") do | ||
| Рядок 68: | Рядок 82: | ||
if section_name and section_name ~= "" then | if section_name and section_name ~= "" then | ||
local | local processed = frame:preprocess(section_name) | ||
processed = mw.text.trim(processed) | |||
local anchor = | -- Пропускаємо секції з ігор | ||
if not should_skip_section(processed) then | |||
local anchor = mw.ustring.gsub(processed, " ", "_") | |||
local display = processed | |||
local section_pos = mw.ustring.find(content, line, 1, true) | |||
if section_pos then | |||
local section_content = get_section_content(content, section_pos) | |||
if mw.ustring.match(processed, "Цікаві факти") then | |||
local facts_count = count_facts(section_content) | |||
if facts_count > 0 then | |||
display = processed .. " (" .. facts_count .. ")" | |||
end | |||
elseif mw.ustring.match(processed, "Нагороди") then | |||
local awards_count = count_awards(section_content) | |||
if awards_count > 0 then | |||
display = processed .. " (" .. awards_count .. ")" | |||
end | |||
end | |||
end | |||
if | if processed ~= "" then | ||
table.insert(sections, { | |||
display = display, | |||
anchor = anchor | |||
}) | |||
end | end | ||
end | end | ||
end | end | ||
| Рядок 108: | Рядок 125: | ||
local html_parts = {} | local html_parts = {} | ||
table.insert(html_parts, '<div class="l-box" | table.insert(html_parts, '<div class="l-box">') | ||
for i, section in ipairs(sections) do | for i, section in ipairs(sections) do | ||
local | local last_class = "" | ||
if i | if i == #sections then | ||
last_class = " l-box-item-last" | |||
end | end | ||
table.insert(html_parts, | table.insert(html_parts, '<div class="l-box-item' .. last_class .. '" data-target="' .. section.anchor .. '"><span>' .. section.display .. '</span></div>') | ||
end | end | ||