5441
редагування
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 17: | Рядок 17: | ||
page_cache[page_name] = content | page_cache[page_name] = content | ||
return content | return content | ||
end | |||
local function count_facts(content, section_start) | |||
local section_end = mw.ustring.find(content, "\n==[^=]", section_start + 1) | |||
local section_content | |||
if section_end then | |||
section_content = mw.ustring.sub(content, section_start, section_end - 1) | |||
else | |||
section_content = mw.ustring.sub(content, section_start) | |||
end | |||
local count = 0 | |||
for line in mw.ustring.gmatch(section_content, "[^\n]+") do | |||
if mw.ustring.match(line, "^%*[^%*]") then | |||
count = count + 1 | |||
end | |||
end | |||
return count | |||
end | end | ||
| Рядок 42: | Рядок 62: | ||
processed = mw.text.trim(processed) | processed = mw.text.trim(processed) | ||
local anchor = mw.ustring.gsub(processed, " ", "_") | local anchor = mw.ustring.gsub(processed, " ", "_") | ||
local display = processed | |||
if mw.ustring.match(processed, "Цікаві факти") then | |||
local section_pos = mw.ustring.find(content, line, 1, true) | |||
if section_pos then | |||
local facts_count = count_facts(content, section_pos) | |||
if facts_count > 0 then | |||
display = processed .. " (" .. facts_count .. ")" | |||
end | |||
end | |||
end | |||
if processed ~= "" then | if processed ~= "" then | ||
table.insert(sections, { | table.insert(sections, { | ||
display = | display = display, | ||
anchor = anchor | anchor = anchor | ||
}) | }) | ||