More actions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
function p.fromPage(frame) | function p.fromPage(frame) | ||
local input = frame.args[1] or "" | |||
-- Extract and clean up the title from [[Page]] or [[Page|Display]] | |||
local raw = mw.ustring.match(input, "%[%[(.-)%]%]") or input | |||
local titleText = mw.text.split(raw, "|")[1] | |||
-- Resolve title object | |||
local title = mw.title.new(titleText) | |||
if not title then | |||
return "Invalid page title: " .. titleText | |||
end | |||
-- Get content and return preview if it exists | |||
if title.exists then | |||
local content = title:getContent() | |||
if content then | |||
local preview = mw.ustring.sub(content, 1, 150) | |||
return preview .. "..." | |||
else | |||
return "No content on: " .. title.fullText | |||
end | |||
else | |||
return "Page does not exist: " .. titleText | |||
end | |||
end | end | ||
return p | return p |
Revision as of 01:05, 25 May 2025
Documentation for this module may be created at Module:SummarySnippet/doc
local p = {}
function p.fromPage(frame)
local input = frame.args[1] or ""
-- Extract and clean up the title from [[Page]] or [[Page|Display]]
local raw = mw.ustring.match(input, "%[%[(.-)%]%]") or input
local titleText = mw.text.split(raw, "|")[1]
-- Resolve title object
local title = mw.title.new(titleText)
if not title then
return "Invalid page title: " .. titleText
end
-- Get content and return preview if it exists
if title.exists then
local content = title:getContent()
if content then
local preview = mw.ustring.sub(content, 1, 150)
return preview .. "..."
else
return "No content on: " .. title.fullText
end
else
return "Page does not exist: " .. titleText
end
end
return p