Module:ElementAchievementBadges: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 39: Line 39:
             -- Get all badge-type achievements using the centralized function
             -- Get all badge-type achievements using the centralized function
             local badgeAchievements = Achievements.getBadgeAchievements(pageId, frame)
             local badgeAchievements = Achievements.getBadgeAchievements(pageId, frame)
            -- Inject achievement categories onto the page
            for _, ach in ipairs(badgeAchievements) do
                if ach.category and ach.category ~= "" then
                    mw.addCategory(ach.category)
                end
            end
              
              
             -- Minimal debug info for troubleshooting
             -- Minimal debug info for troubleshooting
Line 72: Line 66:
                 or p.defaultConfig.badgeClass
                 or p.defaultConfig.badgeClass
              
              
             -- Build the badges HTML
             -- Build the badges HTML and category links
             local badgesHtml = {}
             local badgesHtml = {}
            local categoryLinks = {}
              
              
             -- Add a table row to contain the badges
             -- Add a table row to contain the badges
             table.insert(badgesHtml, '|-\n| colspan="2" class="' .. containerClass .. '" | ')
             table.insert(badgesHtml, '|-\n| colspan="2" class="' .. containerClass .. '" | ')
              
              
             -- Add each badge
             -- Add each badge and collect category links
             for _, achievement in ipairs(badgeAchievements) do
             for _, achievement in ipairs(badgeAchievements) do
                 -- For each badge, create a span with appropriate classes
                 -- For each badge, create a span with appropriate classes
Line 89: Line 84:
                     )
                     )
                     table.insert(badgesHtml, badgeSpan)
                     table.insert(badgesHtml, badgeSpan)
                end
                -- Add category link if it exists
                if achievement.category and achievement.category ~= "" then
                    table.insert(categoryLinks, "[[Category:" .. achievement.category .. "]]")
                 end
                 end
             end
             end
              
              
             -- Return the complete HTML with debug info
             -- Return the complete HTML with debug info and category links
             return table.concat(badgesHtml) .. debugInfo
             return table.concat(badgesHtml) .. table.concat(categoryLinks) .. debugInfo
         end
         end