Module:Indicator datasets table: Difference between revisions

From Visual Data Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 6: Line 6:
         return "Error: articleids not provided"
         return "Error: articleids not provided"
     end
     end
   
    -- Entferne alle Kommas und Leerzeichen am Ende von articleids
    articleids = mw.ustring.gsub(articleids, '[,%s]*$', '')
      
      
     local ids = mw.text.split(articleids, ",")
     local ids = mw.text.split(articleids, ",")

Revision as of 14:31, 2 May 2024

Documentation for this module may be created at Module:Indicator datasets table/doc

local p = {}

function p.getDatasets(frame)
    local articleids = frame.args.articleids
    if not articleids then
        return "Error: articleids not provided"
    end
    
    -- Entferne alle Kommas und Leerzeichen am Ende von articleids
    articleids = mw.ustring.gsub(articleids, '[,%s]*$', '')
    
    local ids = mw.text.split(articleids, ",")
    local pagecontent = {}
    local titleobject
    
    for _, id in ipairs(ids) do
        titleobject = mw.title.new(tonumber(id))
        local existspage = titleobject.exists
        
        if existspage then
            local content = titleobject:getContent()
            -- Speichere den Inhalt der Seite
            table.insert(pagecontent, content)
        else
            table.insert(pagecontent, "Error: Page not found for ID " .. id)
        end
    end
    
    -- Erstelle für jeden Inhalt ein <div>-Element
    local result = {}
    for _, content in ipairs(pagecontent) do
        table.insert(result, '<div>' .. content .. '</div>')
    end
    
    -- Gib alle <div>-Elemente als zusammengefügten String zurück
    return table.concat(result, "\n")
end

return p