Module:NavboxUtil

local p = {}

function p.makeSuffixedLink(link, display, suffix) if suffix and suffix ~= '' then local newlink, class = p.pickLink(link, suffix) return string.format(' %s ',			class or ,			newlink or ,			display or ''		) else return string.format('%s',			link or,			display or 		) end end

function p.pickLink(link, suffix) local target = p.doesSuffixExist(link, suffix) if target then return target, '' else return link, 'no-subpage' end end

function p.doesSuffixExist(link, suffix) if not suffix then return link end local target = string.format('%s/%s',link or ,suffix or ) local targetpage = mw.title.makeTitle('',target) return targetpage.exists and targetpage.text end

function p.getSuffix(args, title) if args.suffix == 'Yes' then titleparts = mw.text.split(title.text,'/') table.remove(titleparts,1) if #titleparts == 0 then return nil end -- make a table where the first entry is the full suffix -- subsequent suffixes are shorter and shorter local output = table.concat(titleparts,'/') return output else return nil end end

return p