Module:SiteList: Difference between revisions
Jump to navigation
Jump to search
PeaceDeadC (talk | contribs) (Undo revision 2512 by PeaceDeadC (talk)) Tag: Undo |
PeaceDeadC (talk | contribs) No edit summary |
||
Line 6: | Line 6: | ||
updatesUrl = 'https://website1.com/updates/', |
updatesUrl = 'https://website1.com/updates/', |
||
modelsUrl = 'https://website1.com/models/', |
modelsUrl = 'https://website1.com/models/', |
||
category = ' |
category = 'Website 1 models', |
||
network = 'Network1 Network', |
|||
label = 'Website 1', |
label = 'Website 1', |
||
aliases = {'website1', 'website1.com', 'website1com'}, |
aliases = {'website1', 'website1.com', 'website1com'}, |
||
Line 14: | Line 15: | ||
updatesUrl = 'https://website2.com/scene/', |
updatesUrl = 'https://website2.com/scene/', |
||
modelsUrl = 'https://website2.com/people/', |
modelsUrl = 'https://website2.com/people/', |
||
category = ' |
category = 'Website 2 models', |
||
network = 'Network2 Network', |
|||
label = 'Website 2', |
label = 'Website 2', |
||
aliases = {'website2', 'website2.com', 'website2com'}, |
aliases = {'website2', 'website2.com', 'website2com'}, |
||
Line 22: | Line 24: | ||
updatesUrl = 'https://website3.com/videos/', |
updatesUrl = 'https://website3.com/videos/', |
||
modelsUrl = 'https://website3.com/performers/', |
modelsUrl = 'https://website3.com/performers/', |
||
category = ' |
category = 'Website 3 models', |
||
network = 'Network3 Network', |
|||
label = 'Website 3', |
label = 'Website 3', |
||
aliases = {'website3', 'website3.com', 'website3com'}, |
aliases = {'website3', 'website3.com', 'website3com'}, |
||
Line 42: | Line 45: | ||
local alias = args.alias or mw.title.getCurrentTitle().text |
local alias = args.alias or mw.title.getCurrentTitle().text |
||
local notes = args.notes and '<div style="font-size: 0.875em;">' .. args.notes .. '</div>' or '<div style="font-size: 0.875em;">N/A</div>' |
local notes = args.notes and '<div style="font-size: 0.875em;">' .. args.notes .. '</div>' or '<div style="font-size: 0.875em;">N/A</div>' |
||
local categoryLink = site.network and string.format(' <small>([[:Category:%s|%s]])</small>', site.category, site.category) or '' |
|||
local style |
local style |
||
Line 51: | Line 56: | ||
local result = string.format( |
local result = string.format( |
||
'|-\n| style="%s" | %s\n| style="text-align:center;vertical-align:middle;" | %s\n| style="text-align:center;vertical-align:middle;" | %s\n| style="text-align:center;vertical-align:middle;" | %s\n', |
'|-\n| style="%s" | %s\n| style="text-align:center;vertical-align:middle;" | %s%s\n| style="text-align:center;vertical-align:middle;" | %s\n| style="text-align:center;vertical-align:middle;" | %s\n', |
||
style, |
style, |
||
args[1] == 'Studio' and 'Studio' or 'Website', |
args[1] == 'Studio' and 'Studio' or 'Website', |
||
string.format('[%s %s] |
string.format('[%s %s]', url, site.label), |
||
categoryLink, |
|||
alias, |
alias, |
||
notes |
notes |
||
Line 61: | Line 67: | ||
local ns = mw.title.getCurrentTitle().namespace |
local ns = mw.title.getCurrentTitle().namespace |
||
if ns == 0 then |
if ns == 0 then |
||
result = result .. '[[Category:' .. site.category .. ']]' |
|||
result = result .. '[[Category:Articles in the mainspace using Template:SiteList]]' |
result = result .. '[[Category:Articles in the mainspace using Template:SiteList]]' |
||
elseif ns == 2 then |
elseif ns == 2 then |
Revision as of 14:28, 22 July 2023
Documentation for this module may be created at Module:SiteList/doc
local p = {} local sites = { website1 = { url = 'https://website1.com/', updatesUrl = 'https://website1.com/updates/', modelsUrl = 'https://website1.com/models/', category = 'Website 1 models', network = 'Network1 Network', label = 'Website 1', aliases = {'website1', 'website1.com', 'website1com'}, }, website2 = { url = 'https://website2.com/', updatesUrl = 'https://website2.com/scene/', modelsUrl = 'https://website2.com/people/', category = 'Website 2 models', network = 'Network2 Network', label = 'Website 2', aliases = {'website2', 'website2.com', 'website2com'}, }, website3 = { url = 'https://website3.com/', updatesUrl = 'https://website3.com/videos/', modelsUrl = 'https://website3.com/performers/', category = 'Website 3 models', network = 'Network3 Network', label = 'Website 3', aliases = {'website3', 'website3.com', 'website3com'}, }, } function p.site(frame) local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:SiteList'}) local site = getSite(args.site) if site then local url = site.url if args.sceneid then url = site.updatesUrl .. args.sceneid .. '.html' elseif args.id then url = site.modelsUrl .. args.id .. '.html' end local alias = args.alias or mw.title.getCurrentTitle().text local notes = args.notes and '<div style="font-size: 0.875em;">' .. args.notes .. '</div>' or '<div style="font-size: 0.875em;">N/A</div>' local categoryLink = site.network and string.format(' <small>([[:Category:%s|%s]])</small>', site.category, site.category) or '' local style if args[1] == 'Studio' then style = 'background-color:#DADADA;text-align:center;color:black' else style = 'background-color:#E7E7E7;text-align:center;color:black' end local result = string.format( '|-\n| style="%s" | %s\n| style="text-align:center;vertical-align:middle;" | %s%s\n| style="text-align:center;vertical-align:middle;" | %s\n| style="text-align:center;vertical-align:middle;" | %s\n', style, args[1] == 'Studio' and 'Studio' or 'Website', string.format('[%s %s]', url, site.label), categoryLink, alias, notes ) local ns = mw.title.getCurrentTitle().namespace if ns == 0 then result = result .. '[[Category:' .. site.category .. ']]' result = result .. '[[Category:Articles in the mainspace using Template:SiteList]]' elseif ns == 2 then result = result .. '[[Category:Articles in the userspace using Template:SiteList]]' elseif ns == 118 then result = result .. '[[Category:Drafts using Template:SiteList]]' end return result else return mw.text.nowiki('{{SiteList}}') .. ' Error: invalid site parameter' end end function table.contains(table, element) for _, value in pairs(table) do if value == element then return true end end return false end function getSite(name) for _, site in pairs(sites) do if site.label:lower() == name:lower() or table.contains(site.aliases, name:lower()) then return site end end return nil end return p