Module:Vital article

This is an old revision of this page, as edited by Kammerer55 (talk | contribs) at 00:11, 30 November 2023 (I do not think we need to do anything with categories in this module, since this would be an inline template used many times, sometimes maybe randomly). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

local getLink = function(page)
	local subpage = mw.ustring.upper(mw.ustring.sub(page, 1, 1)) -- get first letter of article name
	local codepoint = mw.ustring.codepoint(page, 1, 1)
	if codepoint<65 or codepoint>90 then --first letter is not between A-Z
		subpage = 'others'
	end
	local data_page = 'Wikipedia:Vital articles/data/' .. subpage .. '.json'
	local data = mw.loadJsonData(data_page)[page]
	if data then
		local level = tostring(data.level)
		if level then
			local link = 'Wikipedia:Vital articles/Level/' .. level
			if (level=='4' or level=='5') and data.topic then
				link = link .. '/' .. data.topic
			end
			if data.sublist then
				link = link .. '/' .. data.sublist
			end
			--if data.section then -- not used until we have stable section anchors to link to
			--	link = link .. '#' .. data.section
			--end
			return link, level
		end
	end
end

p.link = function(frame)
	local page = frame.args.page~='' and frame.args.page or mw.title.getCurrentTitle().subjectPageTitle.text
	local link, level = getLink(page)
	return '[[' .. page .. ']]' .. (link and '&nbsp;[[File:Círculos Concéntricos.svg|11px|link=|alt=]]&nbsp;[[' .. link .. '|' .. level .. ']]' or '')
end

return p