Module:Official website: Difference between revisions
From Research Realm
No edit summary |
removing wikidata |
||
| Line 9: | Line 9: | ||
return result | return result | ||
end | end | ||
end | end | ||
-- Render the URL link, plus other visible output. | -- Render the URL link, plus other visible output. | ||
local function renderUrl(options) | local function renderUrl(options) | ||
local ret = {} | local ret = {} | ||
ret[#ret + 1] = string.format( | ret[#ret + 1] = string.format( | ||
'<span class="official-website">%s</span>', | '<span class="official-website">%s</span>', | ||
makeUrl(options.url | makeUrl(options.url, options.display) | ||
) | ) | ||
return table.concat(ret, ' ') | return table.concat(ret, ' ') | ||
end | end | ||
-- Render the tracking category. | |||
local function renderTrackingCategory(url) | |||
if mw.title.getCurrentTitle().namespace ~= 0 then | |||
return '' | |||
end | |||
local category | |||
if not url then | |||
category = 'Official website missing URL' | |||
end | |||
return category and string.format('[[Category:%s]]', category) or '' | |||
end | |||
function p._main(args) | function p._main(args) | ||
local url = args[1] or args.URL or args.url | local url = args[1] or args.URL or args.url | ||
local formattedUrl = renderUrl{ | local formattedUrl = renderUrl{ | ||
url = url, | url = url, | ||
display = args[2] or args.name or 'Official website' | display = args[2] or args.name or 'Official website' | ||
} | } | ||
Latest revision as of 05:11, 12 January 2026
Documentation for this module may be created at Module:Official website/doc
local makeUrl = require('Module:URL')._url
local p = {}
-- Wrapper for pcall which returns nil on failure.
local function quickPcall(func)
local success, result = pcall(func)
if success then
return result
end
end
-- Render the URL link, plus other visible output.
local function renderUrl(options)
local ret = {}
ret[#ret + 1] = string.format(
'<span class="official-website">%s</span>',
makeUrl(options.url, options.display)
)
return table.concat(ret, ' ')
end
-- Render the tracking category.
local function renderTrackingCategory(url)
if mw.title.getCurrentTitle().namespace ~= 0 then
return ''
end
local category
if not url then
category = 'Official website missing URL'
end
return category and string.format('[[Category:%s]]', category) or ''
end
function p._main(args)
local url = args[1] or args.URL or args.url
local formattedUrl = renderUrl{
url = url,
display = args[2] or args.name or 'Official website'
}
return formattedUrl .. renderTrackingCategory(url, wikidataurl)
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Official website'
})
return p._main(args)
end
return p