Module:VolDiff

From JoJo's Bizarre Encyclopedia - JoJo Wiki
Revision as of 20:01, 28 July 2024 by Vish (talk | contribs)
Jump to navigation Jump to search

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

local p = {}

-- Helper function to parse chapter number from the chapter link
local function getChapterNumber(chapterLink)
    local match = mw.ustring.match(chapterLink, "Chapter (%d+)")
    return match
end

-- Main function to process the DiffBox template
function p.main(frame)
    local args = frame:getParent().args
    local currentTitle = mw.title.getCurrentTitle().text
    local result = ""

    -- Labels for the DiffBox
    local label1 = args.Label1 or ""
    local label2 = args.Label2 or ""

    -- Iterate through each Diff entry
    for i = 1, 50 do
        local part = args["Part" .. i]
        local chapter = args["Chapter" .. i]
        local page = args["Page" .. i]
        local image1 = args["Image1" .. i]
        local image2 = args["Image2" .. i]
        local desc = args["Desc" .. i]
        local diffLabel1 = args["Label1" .. i] or label1
        local diffLabel2 = args["Label2" .. i] or label2

        if part and chapter and page and image1 and image2 and desc then
            local chapterNumber = getChapterNumber(chapter)

            -- Check if the current page title matches the chapter number
            if chapterNumber and mw.ustring.match(currentTitle, chapterNumber) then
                result = result .. string.format('{{Diff|Part=%s|Chapter=%s|Page=%s|Image1=%s|Image2=%s|Desc=%s|Label1=%s|Label2=%s}}\n',
                    part, chapter, page, image1, image2, desc, diffLabel1, diffLabel2)
            end
        end
    end

    return result
end

return p