Module:Sandbox/LVL: Difference between revisions

LVL (talk | contribs)
No edit summary
LVL (talk | contribs)
No edit summary
Line 7: Line 7:
-- Load icon data and language codes
-- Load icon data and language codes
local iconData = require("Module:Icon/data")
local iconData = require("Module:Icon/data")
local nameToNum = {}
do
    local raw = mw.title.getCurrentTitle():getContent() or ''
    for num, name in raw:gmatch('<span class="abi%-num" data%-num="(%d)"></span>([^<]+)') do
        nameToNum[name:gsub('^%s*',''):gsub('%s*$',''):lower()] = tonumber(num)
    end
end
local lang_codes = mw.loadJsonData("Data:LangCodes.json")
local lang_codes = mw.loadJsonData("Data:LangCodes.json")


Line 81: Line 88:
      
      
     -- build hero-page fragment automatically
     -- build hero-page fragment automatically
    local num  = nameToNum[displayName:lower()]
    local frag = num and ("("..num..")_"..toAnchor(displayName))
                    or toAnchor(displayName)
     local link
     local link
     if baseLink ~= "" and not baseLink:find("#", 1, true) then   -- only hero pages, no manual #
     if baseLink ~= "" and not baseLink:find("#", 1, true) then
         link = baseLink .. "#" .. toAnchor(displayName)
         link = baseLink .. "#" .. frag
     else
     else
         link = baseLink
         link = baseLink