×
Create a new article
Write your page title here:
We currently have 1,652 articles on The Quelmar Wiki. Type your article name above or click on one of the titles below and start writing!



The Quelmar Wiki

Module:CampaignNavbox: Difference between revisions

No edit summary
No edit summary
 
(14 intermediate revisions by the same user not shown)
Line 9: Line 9:
     -- Check if the page content is available
     -- Check if the page content is available
     if not wikitext then
     if not wikitext then
        return "Error: Unable to fetch content for page '" .. pageTitle .. "'."
return "Campaign Page not found?"
     end
     end


Line 15: Line 15:
         PA = {},
         PA = {},
         MD = {},
         MD = {},
         Online = {}
        Twitch = {},
         Online = {},
                International = {}
     }
     }
   
local function processRow(row)
    -- Extract everything up to the first "]]"
    local campaignWithLink = row:match("^.-]]")
    -- Extract the location, which is the last element before the end of the row
    local location = row:match("[^\n]+$")


     -- Function to process each campaign row
     if campaignWithLink and location then
    local function processRow(row)
        campaignWithLink = campaignWithLink:gsub("^|", ""):gsub("'''%s*$", ""):gsub("'''", ""):gsub("|%[%[", "%[%[")
        -- General pattern to capture the campaign name and locations
    location = location:gsub("^|", ""):gsub("'''%s*$", "")
        local campaignNamePattern = "|'''%[%[(.-)%]%]'''"
   
        local locationPattern = "|(.-)\n"
         -- Add the campaign to the relevant location list
        local campaign, location = row:match(campaignNamePattern .. "%s*|%s*.-|.-|.-|.-|.-|" .. locationPattern)
       
        -- Debug output to check matches (remove this line in production)
        mw.log("Campaign: " .. (campaign or "nil") .. ", Location: " .. (location or "nil"))
       
         -- If the campaign name or location are not captured, return without processing
        if not campaign or not location then return end
 
        -- Trim whitespace from the location string
        location = mw.text.trim(location)
 
        -- Check and add to the relevant location
         if location:find("PA") then
         if location:find("PA") then
             table.insert(campaigns.PA, campaign)
             table.insert(campaigns.PA, campaignWithLink)
        end
            end
         if location:find("MD") then
         if location:find("MD") then
             table.insert(campaigns.MD, campaign)
             table.insert(campaigns.MD, campaignWithLink)
        end
            end
         if location:find("Online") then
         if location:find("Online") then
             table.insert(campaigns.Online, campaign)
             table.insert(campaigns.Online, campaignWithLink)
         end
         end
                if location:find("Twitch") then
            table.insert(campaigns.Twitch, campaignWithLink)
                end
                if location:find("🇩🇪") then
            table.insert(campaigns.International, campaignWithLink)
                end
                        if location:find("🏴󠁧󠁢󠁳󠁣󠁴󠁿") then
            table.insert(campaigns.International, campaignWithLink)
            end
     end
     end
end


     -- Split the wikitext into rows and process each
     -- Split the wikitext into rows and process each
local rowPattern = "|%-(.-)\n|%-"
local rowPattern = "|-%s*(.-)\n|%-"
wikitext = wikitext .. '|-'  -- Append delimiter to capture the last row
wikitext = wikitext .. '|-\n'  -- Append delimiter to capture the last row
local skipRows = 1  -- Number of rows to skip to get rid of pre-table text
for row in wikitext:gmatch(rowPattern) do
for row in wikitext:gmatch(rowPattern) do
     processRow(row)
     if skipRows > 0 then
        -- Skip the row
        skipRows = skipRows - 1  -- Decrement the counter
    else
        -- Process the row (e.g., print it)
        processRow(row)
    end
end
end


Line 59: Line 72:
     end
     end
     navbox = navbox .. '|}'
     navbox = navbox .. '|}'
     return navbox
     return navbox
end
end


return p
return p

Latest revision as of 21:12, 25 April 2024

Documentation for this module may be created at Module:CampaignNavbox/doc

local p = {}

function p.getCampaigns(frame)
    -- Fetch the content of the "Campaign" page
    local pageTitle = "Campaign"
    local page = mw.title.new(pageTitle)
    local wikitext = page:getContent()

    -- Check if the page content is available
    if not wikitext then
	return "Campaign Page not found?"
    end

    local campaigns = {
        PA = {},
        MD = {},
         Twitch = {},
        Online = {},
                International = {}
    }
    
local function processRow(row)
    -- Extract everything up to the first "]]"
    local campaignWithLink = row:match("^.-]]")
    -- Extract the location, which is the last element before the end of the row
    local location = row:match("[^\n]+$")

    if campaignWithLink and location then
    	    campaignWithLink = campaignWithLink:gsub("^|", ""):gsub("'''%s*$", ""):gsub("'''", ""):gsub("|%[%[", "%[%[")
    location = location:gsub("^|", ""):gsub("'''%s*$", "")
    
        -- Add the campaign to the relevant location list
        if location:find("PA") then
            table.insert(campaigns.PA, campaignWithLink)
            end
        if location:find("MD") then
            table.insert(campaigns.MD, campaignWithLink)
            end
        if location:find("Online") then
            table.insert(campaigns.Online, campaignWithLink)
        end
                if location:find("Twitch") then
            table.insert(campaigns.Twitch, campaignWithLink)
                end
                if location:find("🇩🇪") then
            table.insert(campaigns.International, campaignWithLink)
                end
                        if location:find("🏴󠁧󠁢󠁳󠁣󠁴󠁿") then
            table.insert(campaigns.International, campaignWithLink)
            end
    end
end

    -- Split the wikitext into rows and process each
local rowPattern = "|-%s*(.-)\n|%-"
wikitext = wikitext .. '|-\n'  -- Append delimiter to capture the last row
local skipRows = 1  -- Number of rows to skip to get rid of pre-table text
for row in wikitext:gmatch(rowPattern) do
    if skipRows > 0 then
        -- Skip the row
        skipRows = skipRows - 1  -- Decrement the counter
    else
        -- Process the row (e.g., print it)
        processRow(row)
    end
end

    -- Build the navbox
    local navbox = '{| class="wikitable"\n!Location\n!Campaigns\n'
    for loc, camps in pairs(campaigns) do
        navbox = navbox .. '|-\n|' .. loc .. '\n|' .. table.concat(camps, ', ') .. '\n'
    end
    navbox = navbox .. '|}'
    return navbox
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies. (Hi Margarita's Table. 🇩🇪)
Cookies help us deliver our services. By using our services, you agree to our use of cookies. (Hi Margarita's Table. 🇩🇪)