Spiderjjr45 (talk | contribs) No edit summary |
Spiderjjr45 (talk | contribs) No edit summary |
||
| Line 20: | Line 20: | ||
-- Function to process each campaign row |
-- Function to process each campaign row |
||
local function processRow(row) |
local function processRow(row) |
||
-- General pattern to capture the campaign name and locations |
|||
| ⚫ | |||
local campaignNamePattern = "|'''%[%[(.-)%]%]'''" |
|||
| ⚫ | |||
local locationPattern = "|(.-)\n" |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
-- 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 |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
-- Trim whitespace from the location string |
|||
location = mw.text.trim(location) |
|||
-- Check and add to the relevant location |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
end |
|||
if location:find("Online") then |
|||
| ⚫ | |||
end |
end |
||
end |
end |
||
Revision as of 15:28, 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 = {}
}
-- Function to process each campaign row
local function processRow(row)
-- General pattern to capture the campaign name and locations
local campaignNamePattern = "|'''%[%[(.-)%]%]'''"
local locationPattern = "|(.-)\n"
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
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
-- Split the wikitext into rows and process each
for row in wikitext:gmatch("|%-.-\n") 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
