Modul: ChapterTabs: Unterschied zwischen den Versionen
Aus Zweidat
Zpd (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
Zpd (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
Zeile 8: | Zeile 8: | ||
'[[Category:Buch]]', | '[[Category:Buch]]', | ||
'?=#', | '?=#', | ||
'?', | |||
'?BuchSortierung', | '?BuchSortierung', | ||
'sort=BuchSortierung' | |||
}) | }) | ||
Zeile 22: | Zeile 24: | ||
-- Get the page name from the first element | -- Get the page name from the first element | ||
local pageName = result[1] | local pageName = result[1] | ||
local pageLink = result[1] | |||
-- Escape any equal signs in the page name | -- Escape any equal signs in the page name | ||
local safePageName = string.gsub(pageName, "=", "=") | local safePageName = string.gsub(pageName, "=", "=") | ||
local safePageLink = string.gsub(pageLink, "=", "=") | |||
-- Add tab content | -- Add tab content | ||
tabContent = tabContent .. safePageName .. '=' .. | tabContent = tabContent .. safePageName .. '=' .. safePageLink .. '\n|-|\n' | ||
end | end | ||
Version vom 25. Oktober 2024, 13:36 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) -- Get the SMW query results for books with no links local query = mw.smw.ask({ '[[Category:Buch]]', '?=#', '?', '?BuchSortierung', 'sort=BuchSortierung' }) if not query then return "No results found" end -- Generate tabs content local tabContent = '' -- Generate tabs for each book for _, result in ipairs(query) do -- Get the page name from the first element local pageName = result[1] local pageLink = result[1] -- Escape any equal signs in the page name local safePageName = string.gsub(pageName, "=", "=") local safePageLink = string.gsub(pageLink, "=", "=") -- Add tab content tabContent = tabContent .. safePageName .. '=' .. safePageLink .. '\n|-|\n' end -- Remove the last separator tabContent = string.gsub(tabContent, '\n|-|\n$', '') -- Use frame:extensionTag to properly trigger the extension return frame:extensionTag('tabber', tabContent) end return p