Module:SiteList: Difference between revisions
Content deleted Content added
PeaceDeadC (talk | contribs) No edit summary |
PeaceDeadC (talk | contribs) No edit summary |
||
| (13 intermediate revisions by the same user not shown) | |||
Line 1:
local p = {}
function p.site(frame)
local args = require('Module:Arguments').getArgs(frame, {wrappers = 'Template:SiteList'})
local site, error = getSite(args.site)
if
return string.format('|-\n| colspan="4" style="text-align:center;vertical-align:middle;color:red;font-weight:bold;" | %s \n| style="width: 0px; padding: 0px; border: none;" |\n', error)
elseif site then
local url = site.url
local isArchived = site.archived and (site.archived == 'yes' or site.archived == 'y')
local archiveNotice = isArchived and " <small>(''Website archived'')</small>" or ''
if isArchived and
elseif isArchived then
url = ''
else
if url ~= '' then
if args.sceneid and site.sceneUrl ~= '' then
url = site.sceneUrl .. args.sceneid .. site.suffix
elseif args.id and site.modelUrl ~= '' then
url = site.modelUrl .. args.id .. site.suffix
end
end
end
local alias = args.alias or '<div style="font-size: 1em;">' .. mw.title.getCurrentTitle().text .. '</div>'
local notes = args.notes and '<div style="font-size: 1em;">' .. args.notes .. '</div>' or '<div style="font-size: 1em;">N/A</div>'
local categoryLink = site.network and site.network ~= '' and string.format(" <small>([[:Category:%s|'''%s''']])</small>", site.network, site.network) or ''
local siteType = site.sitetype or args[1]
local style
if siteType == nil or siteType == '' then
siteType = 'Invalid type'
Line 136 ⟶ 43:
local linkOrLabel
if url ~= '' then
if site.idtonum and (site.idtonum == 'yes' or site.idtonum == 'y') and args.id then
linkOrLabel = string.format('[%s %s #%s]%s', url, site.label, args.id, archiveNotice)
else
linkOrLabel = string.format('[%s %s]%s', url, site.label, archiveNotice)
end
else
linkOrLabel = site.label .. archiveNotice
end
if site.list and site.list ~= '' then
linkOrLabel = linkOrLabel .. string.format(' ([[%s|LIST]])', site.list)
Line 200 ⟶ 100:
function getSite(name)
local firstLetter = name:sub(1, 1):upper()
local success, siteDictModule = pcall(require, 'Module:SiteDict/' .. firstLetter)
if success then
local matchedSites = {}
for _, site in pairs(siteDictModule.sites) do
if site.label:lower() == name:lower() or table.contains(site.aliases, name:lower()) then
table.insert(matchedSites, site)
end
end
if #matchedSites > 1 then
return nil, 'Error: Duplicate sites found in module. Please check the module for errors.'
elseif #matchedSites == 1 then
return matchedSites[1]
end
else
mw.log('Could not load module: ' .. 'Module:SiteDict/' .. firstLetter)
end
return nil
end
| |||