Module:CopyEmbeddedStories: Difference between revisions
From Seven Sages of Rome
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- | -- Function to fetch and format EmbeddedStory templates from a given page | ||
function p.fetchEmbeddedStories(frame) | |||
local pageTitle = frame.args["sourcePage"] | |||
local | if not pageTitle then | ||
return "Error: No source page specified." | |||
end | end | ||
-- | -- Get the wikitext content of the source page | ||
local content = mw.title.new(pageTitle):getContent() | |||
if not content then | |||
return "Error: Source page not found or empty." | |||
end | |||
local | |||
end | |||
-- | -- Find all EmbeddedStory templates | ||
local templates = {} | |||
local | for embeddedStory in content:gmatch("{{EmbeddedStory.-}}") do | ||
table.insert(templates, embeddedStory) | |||
end | end | ||
-- | -- Return the extracted templates | ||
if #templates == 0 then | |||
return "No EmbeddedStory templates found on the source page." | |||
return " | |||
end | end | ||
return | return table.concat(templates, "\n") | ||
end | end | ||
return p | return p |
Revision as of 20:12, 13 November 2024
Documentation for this module may be created at Module:CopyEmbeddedStories/doc
local p = {}
-- Function to fetch and format EmbeddedStory templates from a given page
function p.fetchEmbeddedStories(frame)
local pageTitle = frame.args["sourcePage"]
if not pageTitle then
return "Error: No source page specified."
end
-- Get the wikitext content of the source page
local content = mw.title.new(pageTitle):getContent()
if not content then
return "Error: Source page not found or empty."
end
-- Find all EmbeddedStory templates
local templates = {}
for embeddedStory in content:gmatch("{{EmbeddedStory.-}}") do
table.insert(templates, embeddedStory)
end
-- Return the extracted templates
if #templates == 0 then
return "No EmbeddedStory templates found on the source page."
end
return table.concat(templates, "\n")
end
return p