Module:SiteList: Difference between revisions
Jump to navigation
Jump to search
PeaceDeadC (talk | contribs) No edit summary |
PeaceDeadC (talk | contribs) No edit summary |
||
Line 33: | Line 33: | ||
function p.site(frame) |
function p.site(frame) |
||
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:SiteList'}) |
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:SiteList'}) |
||
local site = args.site and sites[args.site:lower()] |
local site = findSite(args.site) and sites[args.site:lower()] |
||
if site then |
if site then |
||
Line 77: | Line 77: | ||
return mw.text.nowiki('{{SiteList}}') .. ' Error: invalid site parameter' |
return mw.text.nowiki('{{SiteList}}') .. ' Error: invalid site parameter' |
||
end |
end |
||
end |
|||
function findSite(argsSite) |
|||
for _, site in pairs(sites) do |
|||
for _, alias in pairs(site.aliases) do |
|||
if alias == argsSite then |
|||
return site |
|||
end |
|||
end |
|||
end |
|||
return nil |
|||
end |
end |
||
Revision as of 00:00, 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 = 'Network1', label = 'Website 1', aliases = {'website1', 'website1.com', 'website1com'}, }, website2 = { url = 'https://website2.com/', updatesUrl = 'https://website2.com/scene/', modelsUrl = 'https://website2.com/people/', category = 'Network2', label = 'Website 2', aliases = {'website2', 'website2.com', 'website2com'}, }, website3 = { url = 'https://website3.com/', updatesUrl = 'https://website3.com/videos/', modelsUrl = 'https://website3.com/performers/', category = 'Network3', label = 'Website 3', aliases = {'website3', 'website3.com', 'website3com'}, }, -- Добавьте больше сайтов здесь по необходимости } -- Функция для обработки каждого сайта function p.site(frame) local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:SiteList'}) local site = findSite(args.site) and sites[args.site:lower()] 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 or 'N/A' -- Выбираем CSS стиль в зависимости от типа сайта 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\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] <small>([[:Category:%s|%s]])</small>', url, site.label, site.category, site.category), alias, notes ) -- Добавление в категории в зависимости от пространства имен local ns = mw.title.getCurrentTitle().namespace if ns == 0 then 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 findSite(argsSite) for _, site in pairs(sites) do for _, alias in pairs(site.aliases) do if alias == argsSite then return site end end end return nil end return p