Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 1: | Zeile 1: | ||
local buch = {} | local buch = {} | ||
-- Funktion | -- Funktion, um die Anzahl der Bände aus der Serienseite zu holen | ||
function | local function getTotalVolumes(seriesTitle) | ||
if not seriesTitle or seriesTitle == "" then | |||
local query = "[[" .. | return nil | ||
end | |||
local query = "[[Hat Titel::" .. seriesTitle .. "]]|?Complete volumes|limit=1" | |||
local result = mw.smw.getQueryResult(query) | local result = mw.smw.getQueryResult(query) | ||
if result and result.results and next(result.results) then | if result and result.results and next(result.results) then | ||
for _, data in pairs(result.results) do | |||
return data.properties["Complete volumes"] and data.properties["Complete volumes"][1] or nil | |||
end | end | ||
end | end | ||
return nil | return nil | ||
end | end | ||
Zeile 24: | Zeile 20: | ||
function buch.render(args, main) | function buch.render(args, main) | ||
local output = '<table class="publikation buch">' | local output = '<table class="publikation buch">' | ||
-- Titel | -- Titel | ||
output = output .. '<tr><td><strong>Titel</strong></td><td>[[Hat Titel::' .. | local title = args["Titel"] or "Unbekannt" | ||
output = output .. '<tr><td><strong>Titel</strong></td><td>[[Hat Titel::' .. title .. ']]</td></tr>' | |||
-- | -- Autor(en) | ||
if args["Autor"] then | if args["Autor"] then | ||
output = output .. '<tr><td><strong>Autor(en)</strong></td><td>' | output = output .. '<tr><td><strong>Autor(en)</strong></td><td>' | ||
for author in mw.text.gsplit(args["Autor"], ",") do | for author in mw.text.gsplit(args["Autor"], ",") do | ||
output = output .. '[[Hat Autor::' .. author .. ']], ' | output = output .. '[[Hat Autor::' .. mw.text.trim(author) .. ']], ' | ||
end | end | ||
output = output:sub(1, -3) .. '</td></tr>' -- Entfernt das letzte Komma | output = output:sub(1, -3) .. '</td></tr>' -- Entfernt das letzte Komma | ||
end | end | ||
-- | -- Band | ||
if args["Band"] then | |||
local seriesTitle = args["Hat Serie"] or "" | |||
local totalVolumes = getTotalVolumes(seriesTitle) | |||
output = output .. '<tr><td><strong>Band</strong></td><td>' | |||
output = output .. args["Band"] | |||
if totalVolumes then | |||
output = output .. ' von ' .. totalVolumes | |||
end | |||
if seriesTitle ~= "" then | |||
output = output .. ' ([[ ' .. seriesTitle .. ' | Serie ]])' | |||
output = output .. ' | |||
end | end | ||
output = output .. '</td></tr>' | |||
output = output | |||
end | end | ||
-- Weitere Felder hinzufügen... | |||
output = output .. '</table>' | output = output .. '</table>' | ||
return output | return output | ||
end | end | ||
return buch | return buch |
Version vom 20. November 2024, 00:22 Uhr
Die Dokumentation für dieses Modul kann unter Modul:Publikation/Buch/Doku erstellt werden
local buch = {}
-- Funktion, um die Anzahl der Bände aus der Serienseite zu holen
local function getTotalVolumes(seriesTitle)
if not seriesTitle or seriesTitle == "" then
return nil
end
local query = "[[Hat Titel::" .. seriesTitle .. "]]|?Complete volumes|limit=1"
local result = mw.smw.getQueryResult(query)
if result and result.results and next(result.results) then
for _, data in pairs(result.results) do
return data.properties["Complete volumes"] and data.properties["Complete volumes"][1] or nil
end
end
return nil
end
function buch.render(args, main)
local output = '<table class="publikation buch">'
-- Titel
local title = args["Titel"] or "Unbekannt"
output = output .. '<tr><td><strong>Titel</strong></td><td>[[Hat Titel::' .. title .. ']]</td></tr>'
-- Autor(en)
if args["Autor"] then
output = output .. '<tr><td><strong>Autor(en)</strong></td><td>'
for author in mw.text.gsplit(args["Autor"], ",") do
output = output .. '[[Hat Autor::' .. mw.text.trim(author) .. ']], '
end
output = output:sub(1, -3) .. '</td></tr>' -- Entfernt das letzte Komma
end
-- Band
if args["Band"] then
local seriesTitle = args["Hat Serie"] or ""
local totalVolumes = getTotalVolumes(seriesTitle)
output = output .. '<tr><td><strong>Band</strong></td><td>'
output = output .. args["Band"]
if totalVolumes then
output = output .. ' von ' .. totalVolumes
end
if seriesTitle ~= "" then
output = output .. ' ([[ ' .. seriesTitle .. ' | Serie ]])'
end
output = output .. '</td></tr>'
end
-- Weitere Felder hinzufügen...
output = output .. '</table>'
return output
end
return buch