Module:Description2

From Palia Wiki
Jump to navigation Jump to search

Usage

{{Module:Description2}} is a Lua module that invokes Description2 after removing any links. This allows simple reuse of text without leaving incomplete wikitext in the SEO/OpenGraph description.

Syntax

{{#invoke|Description2|main}}

local common = require('Module:Common')
local p = {}

function p.main(frame)
	local args = common.getArgs(frame)
	
	if #args <= 0 then
		return ""
	end
	
	-- First argument is our input
	local input = args[1]
	
	-- We need to remove any links present in order to have a clean description
	local sanitized = input
		-- First remove Singly matched links "[]" otherwise double brackets will turn into single brackets
		:gsub("%[[^%[%]% ]+% ([^%[%]]+)%]", "%1")
		-- Replace inner links with the text contents
		:gsub("%[%[[^%[%]]+%|([^%[%]]+)%]%]", "%1")
	
	frame:callParserFunction('#description2', { sanitized })
	
	return input
end

return p