Hopp til innhold

Modul:AutoDefaultsort

Fra Wikipedia, den frie encyklopedi
Moduldokumentasjon
local p = {}

function p.autoDefaultSort(frame)
    -- Get the current page title
    local title = mw.title.getCurrentTitle().text

    -- Remove parenthetical disambiguation, e.g., "John Smith (actor)" → "John Smith"
    title = mw.ustring.gsub(title, " %b()", ""):gsub("%s+$", "")

    -- Split into words
    local words = mw.text.split(title, " ")

    -- Build the DEFAULTSORT key
    if #words > 1 then
        local lastname = words[#words]
        local firstname = table.concat(words, " ", 1, #words - 1)
        return "{{STANDARDSORTERING:" .. lastname .. ", " .. firstname .. "}}"
    else
        return "{{STANDARDSORTERING:" .. title .. "}}"
    end
end

return p