Module: Blog post
No edit summary |
No edit summary |
||
Line 9: | Line 9: | ||
-- Gather and normalise authors. | -- Gather and normalise authors. | ||
local authors = {} | local authors = {} | ||
if frame.args.author ~= nil then | if frame.args.author ~= nil and frame.args.author ~= '' then | ||
authors[ | authors[1] = frame.args.author | ||
elseif frame.args.authors ~= nil then | elseif frame.args.authors ~= nil and frame.args.authors ~= '' then | ||
authors = mw.text.split( frame.args.authors, ';', true ) | authors = mw.text.split( frame.args.authors, ';', true ) | ||
end | end |
Revision as of 08:58, 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 and frame.args.author ~= '' then
authors[1] = frame.args.author
elseif frame.args.authors ~= nil and frame.args.authors ~= '' then
authors = mw.text.split( frame.args.authors, ';', true )
end
if #authors == 0 then
return '<span class="error">Unable to parse authors: ' .. frame.args.authors .. '</span>'
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