More actions
Content deleted Content added
Created page with "local p = {} -- Function to retrieve and transclude pages in a given category function p.transcludeCategory(frame) -- Get the category name from the arguments local args = frame:getParent().args local categoryName = args[1] if not categoryName or categoryName == "" then return "Error: No category specified." end -- Initialize a buffer to hold the transcluded content local contentBuffer = {} -- Iterate through pages in the categ..." |
No edit summary |
||
Line 4: | Line 4: | ||
function p.transcludeCategory(frame) |
function p.transcludeCategory(frame) |
||
-- Get the category name from the arguments |
-- Get the category name from the arguments |
||
local args = frame |
local args = frame.args |
||
local categoryName = args[1] |
local categoryName = args[1] |
||
Revision as of 11:20, 14 January 2025
Documentation for this module may be created at Module:CategoryTranscluder/doc
local p = {}
-- Function to retrieve and transclude pages in a given category
function p.transcludeCategory(frame)
-- Get the category name from the arguments
local args = frame.args
local categoryName = args[1]
if not categoryName or categoryName == "" then
return "Error: No category specified."
end
-- Initialize a buffer to hold the transcluded content
local contentBuffer = {}
-- Iterate through pages in the category
local category = mw.site.getCategory(categoryName)
if not category then
return "Error: Category not found."
end
local count = 0
for _, page in ipairs(category:members()) do
count = count + 1
-- Only transclude articles, not files or subcategories
if page.ns == 0 then
table.insert(contentBuffer, string.format("<includeonly>{{:%s}}</includeonly>", page.text))
end
-- Optional: Stop after a set limit to prevent excessive processing
if count > 100 then
table.insert(contentBuffer, "<!-- Output truncated to the first 100 items. -->")
break
end
end
-- Combine the transcluded content and return it
return table.concat(contentBuffer, "\n")
end
return p