Module:Breadcrumb

来自Minecraft基岩版开发Wiki
[创建 | 历史 | 清除缓存]文档页面
此模块没有文档页面。如果你知道如何使用模块,请创建它。
local p = {}

function p.auto(_)
	local args = require('Module:ProcessArgs').merge(true)
	local display = args.title
	local title = mw.title.getCurrentTitle()
	local namespace = title.nsText
	local breadcrumbs = {}
	local pages = mw.text.split(title.text, '/', true)
	local current = table.remove(pages)
	if (require('Module:Yesno')(args.snakecase, true)) then
		current = mw.ustring.lower(mw.ustring.gsub(current, ' ', '_'))
	end
	local temp = namespace
	if (temp ~= '') then
		temp = temp .. ':'
	end
	for _, page in ipairs(pages) do
		temp = temp .. page
		table.insert(breadcrumbs, '[[:' .. temp .. '|' .. page .. ']]')
		temp = temp .. '/'
	end
	if (display) then
		table.insert(breadcrumbs, display)
	else
		table.insert(breadcrumbs, current)
	end
	return table.concat(breadcrumbs, '&nbsp;<wbr>&gt;&nbsp;')
end

local function parse(title, namespace)
	title = mw.ustring.match(title, '^%[%[(.*)%]%]&') or title
	local suffix = mw.text.split(title, '|', true)
	if (#suffix > 1) then
		title = table.remove(suffix, 1)
		suffix = table.concat(suffix, '|')
	else
		suffix = nil
	end
	if title == '...' or title == '…' then
		return suffix or '…'
	end
	local split = mw.text.split(title, ':', true)
	local size = #split
	if suffix then
		suffix = '|' .. suffix .. ']]'
	else
		local pages = mw.text.split(split[size], '/', true)
		suffix = '|' .. pages[#pages] .. ']]'
	end
	if (size > 1) then
		namespace = table.remove(split, 1)
		title = table.concat(split, ':')
	end
	if (namespace and namespace ~= '') then
		return '[[:' .. namespace .. ':' .. title .. suffix
	else
		return '[[:' .. title .. suffix
	end
end

function p.breadcrumb(_)
	local args = require('Module:ProcessArgs').merge(true)
	local title = mw.title.getCurrentTitle()
	local namespace = args.namespace or title.nsText
	local display = args.title
	local breadcrumbs = {}
	for _, page in ipairs(args) do
		table.insert(breadcrumbs, parse(page, namespace))
	end
	if (display) then
		table.insert(breadcrumbs, display)
	elseif (require('Module:Yesno')(args.snakecase, true)) then
		table.insert(breadcrumbs, mw.ustring.lower(mw.ustring.gsub(title.subpageText, ' ', '_')))
	else
		table.insert(breadcrumbs, title.subpageText)
	end
	return table.concat(breadcrumbs, '&nbsp;<wbr>&gt;&nbsp;')
end

return p