Module:Sandbox/LVL: Difference between revisions

Jump to navigation Jump to search
LVL (talk | contribs)
No edit summary
LVL (talk | contribs)
No edit summary
Line 4: Line 4:
local generic_module = require('Module:GenericData')
local generic_module = require('Module:GenericData')
local util_module = require('Module:Utilities')
local util_module = require('Module:Utilities')
-- Helper function to flatten item data (stats, descriptions, etc.) into a searchable string
local function extract_search_terms(data)
    local terms = {}
    local function recurse(tbl)
        if type(tbl) ~= "table" then return end
        for k, v in pairs(tbl) do
            table.insert(terms, tostring(k)) -- Add the key (e.g., "SlowPercent", "Damage")
            if type(v) == "table" then
                recurse(v)
            elseif type(v) == "string" then
                local str = v
                -- Clean up description HTML tags and inline attributes
                str = str:gsub("<[^>]+>", " ")
                str = str:gsub("{g:citadel_inline_attribute:'(.-)'}", "%1")
                str = mw.text.decode(str)
                table.insert(terms, str)
            else
                table.insert(terms, tostring(v)) -- Add the value (e.g., "30", "Passive")
            end
        end
    end
    recurse(data)
    local result = string.lower(table.concat(terms, " "))
    result = result:gsub("%s+", " ") -- Normalize spaces
    return result
end


--exceptions if the link is different from the item name
--exceptions if the link is different from the item name
Line 75: Line 102:
                     end
                     end
                      
                      
                     -- Build data attribute for searching (includes both English and localized names)
                     -- Build data attribute for searching (names + stats + description)
                     local search_data = item_name_english
                     local search_data = string.lower(item_name_english)
                     if lang_code ~= "en" and item_name_local then
                     if lang_code ~= "en" and item_name_local then
                         search_data = search_data .. " " .. item_name_local
                         search_data = search_data .. " " .. string.lower(item_name_local)
                     end
                     end
                   
                    -- Append flattened item data (stats, descriptions, shop filters)
                    search_data = search_data .. " " .. extract_search_terms(item_data)
                   
                    -- Escape double quotes so it doesn't break the HTML attribute
                    search_data = search_data:gsub('"', '&quot;')
                      
                      
                     -- Wrap item and its bullet separator in a searchable span
                     -- Wrap item and its bullet separator in a searchable span