Module:Subpages 2

-- subpages = require('Module:Subpages).subpages -- for page in subpages('Page') do ... end

local sp = {}

local majorpages = { -- ["Main"] = true, ["Analysis"] = true, ["Characters"] = true, ["Laconic"] = true, ["Recap"] = true, ["Trivia"] = true, ["Setting"] = true, ["YMMV"] = true, } local cmoapages = { ["Awesome"] = true, ["Funny"] = true, ["Heartwarming"] = true, ["Nightmare Fuel"] = true, ["Tear Jerker"] = true, } local minorpages = { ["Fridge"] = true, ["Fanfic Recs"] = true, ["Haiku"] = true, ["Headscratchers"] = true, ["Ho Yay"] = true, ["Image Links"] = true, ["Memes"] = true, ["Radar"] = true, ["Quotes"] = true, ["Reviews"] = true, ["Shout Out"] = true, ["Useful Notes"] = true, ["WMG"] = true, ["All Subpages"] = true, -- ["Wikipedia"] = true, }

function sp.subpages( frame ) page = frame.args[1] or frame:callParserFunction('TOPLEVELPAGE') allsp = frame:callParserFunction('SUBPAGES', { page, sep = "~" }) links = {} local major = {} local cmoa = {} local minor = {} local other = {} for i in string.gmatch(allsp, page .. "/([^~]+)") do		links[i] = true if majorpages[i] then table.insert(major, i)		elseif cmoapages[i] then table.insert(cmoa, i)		elseif minorpages[i] then table.insert(minor, i)		else table.insert(other, i)		end --table.insert(links, "" .. page .. "/" .. i .. "\n\n") end

-- initialize result with Main link local linkout = { "* Main\n" } for _, sp in ipairs(major) do		table.insert(linkout, linkup( page, sp )) end for _, sp in ipairs(cmoa) do		table.insert(linkout, linkup( page, sp )) end for _, sp in ipairs(minor) do		table.insert(linkout, linkup( page, sp )) end table.insert(linkout, "* Wikipedia\n")

return '{| class="wikitable"\n| \n' .. table.concat(linkout) .. '* All Subpages' .. ' ' ..	table.concat(other, "\t") .. ' '		.. ' ' ..		'  \n|}' end

function linkup( pagename, subpage ) return "* " .. subpage .."\n" end

return sp