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

912 байтів вилучено ,  У понеділок о 19:42
нема опису редагування
Немає опису редагування
Мітка: Ручний відкіт
Немає опису редагування
Рядок 1: Рядок 1:
local p = {}
local p = {}
-- ================================================
-- КЕШУВАННЯ
-- ================================================


local page_cache = {}
local page_cache = {}
Рядок 22: Рядок 18:
     return content
     return content
end
end
-- ================================================
-- АВТОМАТИЧНЕ МЕНЮ СЕКЦІЙ
-- ================================================


function p.section_menu(frame)
function p.section_menu(frame)
Рядок 38: Рядок 30:
      
      
     for line in mw.ustring.gmatch(content, "[^\n]+") do
     for line in mw.ustring.gmatch(content, "[^\n]+") do
        -- ТІЛЬКИ заголовки рівня 2: == Назва ==
         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 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 anchor = mw.ustring.gsub(processed, " ", "_")
                  
                  
Рядок 64: Рядок 52:
     end
     end
      
      
    -- Будуємо HTML
     local html_parts = {}
     local html_parts = {}
      
      
     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">')
   
    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 last_class = ""
         if i < #sections then
         if i == #sections then
             border = "border-bottom:1px solid rgba(255,255,255,0.05);"
             last_class = " l-box-item-last"
         end
         end
          
          
         table.insert(html_parts, string.format(
         table.insert(html_parts, string.format(
             '<div class="l-box-item" style="padding:12px 20px; %s">[[#%s|%s]]</div>',
             '<a href="#%s" class="l-box-item%s">%s</a>',
             border, section.anchor, section.display
             section.anchor, last_class, section.display
         ))
         ))
     end
     end