Module:Glossary: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(3 intermediate revisions 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 ""
-- find all [[internal links]]
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 17 ⟶ 22:
seen[title] = true
--local look up the Definition: namespace versiondefTitle
local defTitle =if title:match("^Definition:") .. titlethen
local page defTitle = mw.title.new(defTitle)
else
defTitle = "Definition:" .. title
end
iflocal page and= pagemw.exists thentitle.new(defTitle)
local text =if page:getContent() or ""then
--local striptext templates,= get first sentencepage:getContent()
text =if text:gsub("%b{}", "")then
text = text:gsub("^%s+b{}", "")
local sentence text = text:matchgsub("^(.-%.)s+", "")
if local sentence then= text:match("^(.-%.)")
table.insert(entries,if {sentence then
titletable.insert(entries, = title,{
summary title = sentencetitle:gsub("^Definition:", ""),
}) summary = sentence
})
count = count + 1
end
end
end
Line 37 ⟶ 48:
end
-- sort alphabetically
table.sort(entries, function(a, b)
return a.title < b.title
end)
-- render
local out = {}
for _, e in ipairs(entries) do
table.insert(out, stringe.format(summary)
"'''%s''': %s", e.title, e.summary
))
end