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

нема опису редагування
Немає опису редагування
Немає опису редагування
Рядок 37: Рядок 37:
     local sections = {}
     local sections = {}
      
      
    -- Обробляємо рядок за рядком
     for line in mw.ustring.gmatch(content, "[^\n]+") do
     for line in mw.ustring.gmatch(content, "[^\n]+") do
         -- Шукаємо ТІЛЬКИ заголовки рівня 2: == Назва ==
         -- ТІЛЬКИ заголовки рівня 2: == Назва ==
        -- Перевіряємо що це НЕ рівень 3 (===) і НЕ рівень 4 (====)
         if mw.ustring.match(line, "^==[^=]") and mw.ustring.match(line, "[^=]==$") then
         if mw.ustring.match(line, "^==[^=]") and mw.ustring.match(line, "[^=]==$") then
             local section_name = mw.ustring.match(line, "^==%s*(.-)%s*==$")
             local section_name = mw.ustring.match(line, "^==%s*(.-)%s*==$")
              
              
             if section_name and section_name ~= "" then
             if section_name and section_name ~= "" then
                 -- Очищаємо назву для відображення
                 -- Виконуємо шаблони щоб отримати реальний текст
                 local display_name = mw.ustring.gsub(section_name, "%{%{.-%}%}", "")
                 local processed = frame:preprocess(section_name)
                display_name = mw.ustring.gsub(display_name, "%s*%([^%)]*%)%s*", "") -- прибираємо дужки з вмістом
                 processed = mw.text.trim(processed)
                 display_name = mw.text.trim(display_name)
                  
                  
                 -- Створюємо anchor
                 -- Anchor
                 local anchor = mw.ustring.gsub(section_name, "%{%{.-%}%}", "")
                 local anchor = mw.ustring.gsub(processed, " ", "_")
                anchor = mw.text.trim(anchor)
                anchor = mw.ustring.gsub(anchor, "%s*%([^%)]*%)%s*", "") -- прибираємо дужки з вмістом
                anchor = mw.ustring.gsub(anchor, " ", "_")
                  
                  
                 if display_name ~= "" then
                 if processed ~= "" then
                     table.insert(sections, {
                     table.insert(sections, {
                         display = display_name,
                         display = processed,
                         anchor = anchor
                         anchor = anchor
                     })
                     })
Рядок 75: Рядок 69:
     table.insert(html_parts, '<div class="l-box" style="position:fixed; top:20px; left:20px; z-index:100; border-radius:16px; background-color:#23232c; width:220px; box-sizing:border-box; overflow:hidden;">')
     table.insert(html_parts, '<div class="l-box" style="position:fixed; top:20px; left:20px; z-index:100; border-radius:16px; background-color:#23232c; width:220px; box-sizing:border-box; overflow:hidden;">')
      
      
    -- Заголовок
     table.insert(html_parts, '<div style="padding:15px 20px; font-weight:bold; font-size:15px; color:#fff; border-bottom:1px solid rgba(255,255,255,0.1);">Зміст</div>')
     table.insert(html_parts, '<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, section in ipairs(sections) do
     for i, section in ipairs(sections) do
         local border = ""
         local border = ""