×
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
Line 19: Line 19:


local function processRow(row)
local function processRow(row)
     local campaign, location = row:match("|'''%[%[(.-)%]%]'''%s*|%s*.-|.-|.-|.-|.-|.-|.-|.-|(.-)|\n")
    -- Extract the campaign name which is in the form of a wiki link
     local campaign = row:match("|%[%[(.-)|'''")
    if not campaign then
        campaign = row:match("|'''%[%[(.-)%]%]'''")  -- Fallback for rows without a pipe in the wiki link
    end
   
    -- Extract the location, which is the last element before the end of the row
    local location = row:match("|([^|]-)\n$")
 
     if campaign and location then
     if campaign and location then
         location = mw.text.trim(location) -- Trim whitespace from the location string
         location = mw.text.trim(location) -- Trim whitespace from the location string
Line 33: Line 41:
     end
     end
end
end


     -- Split the wikitext into rows and process each
     -- Split the wikitext into rows and process each

Revision as of 15:44, 23 January 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 "Error: Unable to fetch content for page '" .. pageTitle .. "'."
    end

    local campaigns = {
        PA = {},
        MD = {},
        Online = {}
    }

local function processRow(row)
    -- Extract the campaign name which is in the form of a wiki link
    local campaign = row:match("|%[%[(.-)|'''")
    if not campaign then
        campaign = row:match("|'''%[%[(.-)%]%]'''")  -- Fallback for rows without a pipe in the wiki link
    end
    
    -- Extract the location, which is the last element before the end of the row
    local location = row:match("|([^|]-)\n$")

    if campaign and location then
        location = mw.text.trim(location) -- Trim whitespace from the location string
        if location:find("PA") then
            table.insert(campaigns.PA, campaign)
        end
        if location:find("MD") then
            table.insert(campaigns.MD, campaign)
        end
        if location:find("Online") then
            table.insert(campaigns.Online, campaign)
        end
    end
end


    -- Split the wikitext into rows and process each
local rowPattern = "|%-(.-)\n|%-"
wikitext = wikitext .. '|-'  -- Append delimiter to capture the last row
for row in wikitext:gmatch(rowPattern) do
    processRow(row)
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. 🇩🇪)