Module:Glossary: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 3:
 
function p.generate(frame)
local maxEntries = tonumber(frame.args[1]) or 30
local current = mw.title.getCurrentTitle()
local content = current:getContent() or ""
Line 8 ⟶ 9:
local seen = {}
local entries = {}
local count = 0
for link in content:gmatch("%[%[([^%]|]+)") do
if count >= maxEntries then
break
))end
local title = link:match("^(.-)#") or link
title = mw.text.trim(title)
Line 16 ⟶ 22:
seen[title] = true
-- only prepend if not already in Definition: namespace
local defTitle
if title:match("^Definition:") then
Line 23 ⟶ 28:
defTitle = "Definition:" .. title
end
-- clean display name (strip namespace prefix)
local displayName = title:gsub("^Definition:", "")
local page = mw.title.new(defTitle)
if page then
if page and page.exists thenlocal text = page:getContent()
localif text = page:getContent() or ""then
text = text:gsub("%b{}", "")
text = text:gsub("^%s+", "")
local sentence = text:match("^(.-%.)")
if sentence then
table.insert(entries, {
title = displayNametitle:gsub("^Definition:", ""),
summary = sentence
})
count = count + 1
end
end
end
Line 50 ⟶ 54:
local out = {}
for _, e in ipairs(entries) do
table.insert(out, stringe.format(summary)
"'''%s''': %s", e.title, e.summary
))
end