跳转到内容

Module:首页链接

来自Bleap Wiki

此模块的文档可以在Module:首页链接/doc创建

local p = {}

local function render(url, text)
	url = url or ''
	text = text or url
	if mw.ustring.match(url, '^https?://') then
		return '[' .. url .. ' ' .. text .. ']'
	end
	return '[[' .. url .. '|' .. text .. ']]'
end

function p.focus(frame)
	return render(frame.args['url'], frame.args['text'])
end

-- 新闻条目链接: 未指定文字时, 站外用标题、站内用页面名
function p.item(frame)
	local url = frame.args['url'] or ''
	local text = frame.args['text']
	if text == nil or text == '' then
		if mw.ustring.match(url, '^https?://') then
			text = frame.args['title'] or '外部链接'
		else
			text = url
		end
	end
	return render(url, text)
end

return p