Jump to content

Module:Sandbox/1ctinus

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by 1ctinus (talk | contribs) at 17:00, 2 June 2024 (use a different parsing method). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local p = {}
local plain = require('Module:Plain text')._main
local getArgs = require('Module:Arguments').getArgs
function p.shortdesc(text, frame)
	return frame:expandTemplate{title = 'Short description', args = {text, 'noreplace'}}
end
function p.main(frame)
	local args = getArgs (frame, {parentOnly = true})
	local short_description = plain(args.short_description)
	local output = ""
	local published = plain(args.pub_date or args.release_date or args.published)
	if not(string.find(published, "–")) and string.len(published) < 40 then
		if string.match(published, "%d%d%d%d") then
		  output = string.match(published, "%d%d%d%d")
		end
	end
	local content = mw.title.getCurrentTitle():getContent()
	local offset = string.find(content, "==", 1 , true)
	if offset then
		local intro = string.sub(content, 1, offset-1):gsub('{{[^{}]*}}|', '')
		local firststop = string.find(intro, ".", 1 , true)
		if firststop then
		  local lead = string.sub(intro,1,firststop)
		  output = output .. plain(lead)
		end
	end
	local author = plain(args.author)
	if author and string.len(author) < 40 then
		output = output .. " by " .. author
	end
	return output
end

return p