Module: Blog post

(Created page with "local p = {} -- -- -- Format a list of authors from the author and author parameters. -- Testing: -- =p.authorList({args={author='Foo'}}) -- =p.authorList({args={authors='Foo; Bar', format='plain'}}) p.authorList = function( frame ) -- Gather authors from 'author' or 'authors' arguments. local authors = {} if frame.args.author ~= nil then authors[#authors+1] = frame.args.author elseif frame.args.authors ~= nil then authors = mw.text.split( frame.args.authors...")
 
No edit summary
Line 2: Line 2:


-- --
-- --
-- Format a list of authors from the author and author parameters.
-- Format a list of authors from the author or author parameters.
-- Testing:
-- Testing:
--  =p.authorList({args={author='Foo'}})
--  =p.authorList({args={author='Foo'}})
--  =p.authorList({args={authors='Foo; Bar', format='plain'}})
--  =p.authorList({args={authors='Foo; Bar', format='plain'}})
p.authorList = function( frame )
p.authorList = function( frame )
-- Gather authors from 'author' or 'authors' arguments.
-- Gather and normalise authors.
local authors = {}
local authors = {}
if frame.args.author ~= nil then
if frame.args.author ~= nil then
Line 22: Line 22:
return table.concat( authors, ' / ' )
return table.concat( authors, ' / ' )
else
else
return '[[' .. table.concat( authors, ']] / [[' ) .. ']]'
return ', <strong>[[' .. table.concat( authors, ']] / [[' ) .. ']]</strong>'
end
end
end
end


return p
return p

Revision as of 08:24, 28 June 2023

Documentation for this module may be created at Module:Blog post/doc

local p = {}

-- --
-- Format a list of authors from the author or author parameters.
-- Testing:
--   =p.authorList({args={author='Foo'}})
--   =p.authorList({args={authors='Foo; Bar', format='plain'}})
p.authorList = function( frame )
	-- Gather and normalise authors.
	local authors = {}
	if frame.args.author ~= nil then
		authors[#authors+1] = frame.args.author
	elseif frame.args.authors ~= nil then
		authors = mw.text.split( frame.args.authors, ';', true )
	end
	for i, a in pairs( authors ) do
		authors[i] = mw.text.trim( a )
	end

	-- Format output.	
	if frame.args.format == 'plain' then
		return table.concat( authors, ' / ' )
	else
		return ', <strong>[[' .. table.concat( authors, ']] / [[' ) .. ']]</strong>'
	end
end

return p
Discuss this page