Modul: ChapterTabs: Unterschied zwischen den Versionen

Aus Zweidat
Wechseln zu: Navigation, Suche
(Die Seite wurde neu angelegt: „-- Module for creating TabberNeue structure from SMW query local p = {} -- Helper function to split string by delimiter local function split(str, delimiter) local result = {} for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do table.insert(result, match) end return result end -- Main function to generate tabs function p.generateTabs(frame) local tabberStart = '<tabber>\n' local tabberEnd = '</tabber>' local…“)
 
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
-- Module for creating TabberNeue structure from SMW query
-- Module for creating TabberNeue structure from SMW query
local p = {}
local p = {}
-- Helper function to split string by delimiter
local function split(str, delimiter)
    local result = {}
    for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do
        table.insert(result, match)
    end
    return result
end


-- Main function to generate tabs
-- Main function to generate tabs
Zeile 18: Zeile 9:
      
      
     -- Get the SMW query results for books
     -- Get the SMW query results for books
     local query = mw.smw.ask({
     local query = mw.smw.ask('[[Category:Buch]]|?BuchSortierung')
        '[[Category:Buch]]',
        '?BuchSortierung'
    })
      
      
     if not query then
     if not query then
         return "No results found"
         return "No results found"
     end
     end
   
    -- Sort the results by BuchSortierung if available
    table.sort(query, function(a, b)
        local sortA = a.printouts.BuchSortierung and a.printouts.BuchSortierung[1] or a.fulltext
        local sortB = b.printouts.BuchSortierung and b.printouts.BuchSortierung[1] or b.fulltext
        return sortA < sortB
    end)
      
      
     -- Generate tabs for each book
     -- Generate tabs for each book
     for _, result in ipairs(query) do
     for _, result in ipairs(query) do
         local pageName = result.fulltext
        -- Get the page name from the first element
         local pageName = result[1]
         -- Escape any equal signs in the page name
         -- Escape any equal signs in the page name
         local safePageName = string.gsub(pageName, "=", "&#61;")
         local safePageName = string.gsub(pageName, "=", "&#61;")

Version vom 25. Oktober 2024, 12:53 Uhr

Die Dokumentation für dieses Modul kann unter Modul:ChapterTabs/Doku erstellt werden

-- Module for creating TabberNeue structure from SMW query
local p = {}

-- Main function to generate tabs
function p.generateTabs(frame)
    local tabberStart = '<tabber>\n'
    local tabberEnd = '</tabber>'
    local tabs = ''
    
    -- Get the SMW query results for books
    local query = mw.smw.ask('[[Category:Buch]]|?BuchSortierung')
    
    if not query then
        return "No results found"
    end
    
    -- Generate tabs for each book
    for _, result in ipairs(query) do
        -- Get the page name from the first element
        local pageName = result[1]
        -- Escape any equal signs in the page name
        local safePageName = string.gsub(pageName, "=", "&#61;")
        
        -- Simply use the page name as content
        tabs = tabs .. safePageName .. '=' .. pageName .. '\n|-|\n'
    end
    
    -- Remove the last tab separator
    tabs = string.gsub(tabs, '\n|-|\n$', '')
    
    return tabberStart .. tabs .. tabberEnd
end

return p