Module:Link: Difference between revisions
MusikAnimal (talk | contribs) No edit summary |
MusikAnimal (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local function | local function person_link( content, title, linkType, linkSubtype ) | ||
for _i, subject in ipairs({ 'Billy Corgan', 'James Iha', "D'arcy Wretzky", 'Jimmy Chamberlin', 'Butch Vig', 'Flood', 'Alan Moulder', 'Kerry Brown', 'Bjorn Thorsrud', 'Nellee Hooper', 'Terry Date', 'Jeff Schroeder', 'Howard Willing', 'Rick Rubin', 'Roy Thomas Baker', 'Brad Wood', 'Dale Griffin', 'Ted de Bono' }) do | for _i, subject in ipairs({ 'Billy Corgan', 'James Iha', "D'arcy Wretzky", 'Jimmy Chamberlin', 'Butch Vig', 'Flood', 'Alan Moulder', 'Kerry Brown', 'Bjorn Thorsrud', 'Nellee Hooper', 'Terry Date', 'Jeff Schroeder', 'Howard Willing', 'Rick Rubin', 'Roy Thomas Baker', 'Brad Wood', 'Dale Griffin', 'Ted de Bono' }) do | ||
local cat_str = 'Category:' .. linkType .. 's ' .. linkSubtype .. ' by ' .. subject .. '|' | local cat_str = 'Category:' .. linkType .. 's ' .. linkSubtype .. ' by ' .. subject .. '|' | ||
Line 18: | Line 18: | ||
elseif kind == 'song' then | elseif kind == 'song' then | ||
s = '"[[' .. s .. ']]"' | s = '"[[' .. s .. ']]"' | ||
else | |||
s = '[[' .. s .. ']]' | |||
end | end | ||
table.insert(t, s) | table.insert(t, s) | ||
Line 28: | Line 30: | ||
return mw.text.trim(ret, ', ') | return mw.text.trim(ret, ', ') | ||
end | |||
function p.main( frame ) | |||
local content = frame.args[1] | |||
if content == '' then | |||
return content | |||
end | |||
return p._link(content) | |||
end | end | ||
Line 46: | Line 56: | ||
end | end | ||
return | return person_link(content, title, linkType, 'produced') | ||
end | end | ||
Line 57: | Line 67: | ||
end | end | ||
return | return person_link(content, title, linkType, 'written') | ||
end | end | ||
return p | return p |
Revision as of 15:59, 17 June 2020
Documentation for this module may be created at Module:Link/doc
local p = {}
local function person_link( content, title, linkType, linkSubtype )
for _i, subject in ipairs({ 'Billy Corgan', 'James Iha', "D'arcy Wretzky", 'Jimmy Chamberlin', 'Butch Vig', 'Flood', 'Alan Moulder', 'Kerry Brown', 'Bjorn Thorsrud', 'Nellee Hooper', 'Terry Date', 'Jeff Schroeder', 'Howard Willing', 'Rick Rubin', 'Roy Thomas Baker', 'Brad Wood', 'Dale Griffin', 'Ted de Bono' }) do
local cat_str = 'Category:' .. linkType .. 's ' .. linkSubtype .. ' by ' .. subject .. '|'
content = mw.ustring.gsub( content, subject, '[[:' .. cat_str .. subject .. ']][[' .. cat_str .. title .. ']]' )
end
return content
end
function p._link(content, kind)
local t = {}
for s in string.gmatch(content, "([^,]+)") do
s = mw.text.trim(s)
if kind == 'album' then
s = "''[[" .. s .. "]]''"
elseif kind == 'song' then
s = '"[[' .. s .. ']]"'
else
s = '[[' .. s .. ']]'
end
table.insert(t, s)
end
local ret = ''
for _i, s in pairs(t) do
ret = ret .. ', ' .. s
end
return mw.text.trim(ret, ', ')
end
function p.main( frame )
local content = frame.args[1]
if content == '' then
return content
end
return p._link(content)
end
function p.album( frame )
local content = frame.args[1]
if content == '' then
return content
end
return p._link(content, 'album')
end
function p.producer( frame )
local content = frame.args[1]
local title = frame.args[2]
local linkType = frame.args[3]
if content == '' then
return content
end
return person_link(content, title, linkType, 'produced')
end
function p.writer( frame )
local content = frame.args[1]
local title = frame.args[2]
local linkType = frame.args[3]
if content == '' then
return content
end
return person_link(content, title, linkType, 'written')
end
return p