Spiderjjr45 (talk | contribs) (Created page with "local p = {} function p.getCampaigns(frame) local wikitext = frame.args[1] -- Get the wikitext passed to the module local campaigns = { PA = {}, MD = {}, Online = {} } -- Function to process each campaign row local function processRow(row) local campaign, location = row:match("|'''%[%[(.-)%]%]'''%s*|%s*.-|.-|.-|.-|.-|.-|(.-)|") if campaign and location then if location:find("PA") then...") |
Spiderjjr45 (talk | contribs) No edit summary |
||
| (18 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
function p.getCampaigns(frame) |
function p.getCampaigns(frame) |
||
-- Fetch the content of the "Campaign" page |
|||
local wikitext = frame.args[1] -- Get the wikitext passed to the module |
|||
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 = { |
local campaigns = { |
||
PA = {}, |
PA = {}, |
||
MD = {}, |
MD = {}, |
||
MN = {}, |
|||
Twitch = {}, |
|||
Online = {}, |
|||
International = {} |
|||
} |
} |
||
-- Function to process each campaign row |
|||
local function processRow(row) |
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 |
|||
| ⚫ | |||
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 |
if location:find("PA") then |
||
table.insert(campaigns.PA, |
table.insert(campaigns.PA, campaignWithLink) |
||
end |
end |
||
if location:find("MD") then |
if location:find("MD") then |
||
table.insert(campaigns.MD, |
table.insert(campaigns.MD, campaignWithLink) |
||
end |
|||
if location:find("MN") then |
|||
table.insert(campaigns.MN, campaignWithLink) |
|||
end |
end |
||
if location:find("Online") then |
if location:find("Online") then |
||
table.insert(campaigns.Online, |
table.insert(campaigns.Online, campaignWithLink) |
||
end |
|||
if location:find("Twitch") then |
|||
table.insert(campaigns.Twitch, campaignWithLink) |
|||
end |
|||
if location:find("🇩🇪") or location:find("🏴") then |
|||
table.insert(campaigns.International, campaignWithLink) |
|||
end |
end |
||
end |
end |
||
| Line 26: | Line 58: | ||
-- Split the wikitext into rows and process each |
-- 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 |
|||
skipRows = skipRows - 1 |
|||
else |
|||
| ⚫ | |||
end |
|||
end |
end |
||
| Line 36: | Line 75: | ||
end |
end |
||
navbox = navbox .. '|}' |
navbox = navbox .. '|}' |
||
return navbox |
return navbox |
||
end |
end |
||
Latest revision as of 17:22, 5 November 2025
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 = {},
MN = {},
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("MN") then
table.insert(campaigns.MN, 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("🇩🇪") or 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
skipRows = skipRows - 1
else
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
