Модуль:FetchData2: відмінності між версіями

нема опису редагування
Немає опису редагування
Мітки: Ручний відкіт Скасовано
Немає опису редагування
Мітка: Скасовано
Рядок 21: Рядок 21:
     page_cache[page_name] = content
     page_cache[page_name] = content
     return content
     return content
end
-- ================================================
-- ПІДРАХУНОК ЕЛЕМЕНТІВ
-- ================================================
-- Знаходимо кінець секції (початок наступної == або кінець файлу)
local function get_section_content(content, section_start)
    local next_section = mw.ustring.find(content, "\n==[^=]", section_start + 1)
    if next_section then
        return mw.ustring.sub(content, section_start, next_section - 1)
    else
        return mw.ustring.sub(content, section_start)
    end
end
-- Рахуємо рядки в таблиці
local function count_table_rows(section_content)
    local table_start = mw.ustring.find(section_content, "{|")
    if not table_start then return 0 end
   
    local table_end = mw.ustring.find(section_content, "|}", table_start)
    if not table_end then return 0 end
   
    local table_content = mw.ustring.sub(section_content, table_start, table_end)
   
    local count = 0
    for _ in mw.ustring.gmatch(table_content, "|-") do
        count = count + 1
    end
   
    -- Перший |- це заголовок
    return math.max(0, count - 1)
end
-- Рахуємо bullet points (*)
local function count_bullet_points(section_content)
    local count = 0
    for _ in mw.ustring.gmatch(section_content, "\n%*[^%*]") do
        count = count + 1
    end
    -- Перевіряємо чи секція починається з *
    if mw.ustring.match(section_content, "^%*[^%*]") or mw.ustring.match(section_content, "\n%*[^%*]") then
        -- вже пораховано
    end
    return count
end
end


Рядок 43: Рядок 89:
              
              
             if section_name and section_name ~= "" then
             if section_name and section_name ~= "" then
                 -- Виконуємо шаблони щоб отримати реальний текст
                 -- Виконуємо шаблони
                 local processed = frame:preprocess(section_name)
                 local processed = frame:preprocess(section_name)
                 processed = mw.text.trim(processed)
                 processed = mw.text.trim(processed)
                  
                  
                 -- Anchor
                -- Знаходимо позицію секції
                 local anchor = mw.ustring.gsub(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(section_name, "Нагороди") then
                        local count = count_table_rows(section_content)
                        if count > 0 then
                            processed = processed .. " (" .. count .. ")"
                        end
                   
                    -- Сезони - рахуємо рядки таблиці
                    elseif mw.ustring.match(section_name, "Сезони") then
                        local count = count_table_rows(section_content)
                        if count > 0 then
                            processed = processed .. " (" .. count .. ")"
                        end
                   
                    -- Цікаві факти - рахуємо bullet points
                    elseif mw.ustring.match(section_name, "Цікаві факти") then
                        local count = count_bullet_points(section_content)
                        if count > 0 then
                            processed = processed .. " (" .. count .. ")"
                        end
                    end
                end
               
                 -- Anchor (без доданих чисел для стандартних секцій)
                 local anchor = frame:preprocess(section_name)
                anchor = mw.text.trim(anchor)
                anchor = mw.ustring.gsub(anchor, " ", "_")
                  
                  
                 if processed ~= "" then
                 if processed ~= "" then