Module:User:DTLHS/subpages

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This is a private module sandbox of DTLHS, for his own experimentation. Items in this module may be added and removed at DTLHS's discretion; do not rely on this module's stability.


export = {}

function namespace(title)
	for i in mw.ustring.gmatch(title, '[^:]+:') do
		return i
	end
	return ''
end

function load_page(frame, pagename)
	return frame:expandTemplate{ title = ':' .. pagename }
end

function all_subpages(frame, pagename)
	local result = {}
    local index = mw.text.unstrip(frame:preprocess('{{Special:PrefixIndex/'..pagename..'/}}'))
    local ns = namespace(pagename)
    for link in mw.ustring.gmatch(index, "<a.->(.-)</a>") do
    	table.insert(result, ns..link)
	end
	
    return result
    
end

function export.display(frame)
	local args = frame:getParent().args
	local pagename = args[1]
	local pages = all_subpages(frame, pagename)
	local result = {}
	for i, v in ipairs(pages) do
		table.insert(result, load_page(frame, v))
	end
	return table.concat(result, '\n\n')
	
end

return export